Thursday, July 31, 2014

Javascript Date Functions

July 31st 2014.

Lot of people are afraid to deal with date objects in JavaScript. While it is not the easiest to deal with it is not certainly the most difficult to deal with.  With little time and experiments and lots of patience you can understand how it works.  Once learnt building something additional to it is lot easier in latter times.  Most of the functions I learnt in JavaScript is by studying W3Schools articles.
You can view all of their offering at www.w3schools.com

Today I am going to show you an example of date object manipulation.  This is in response to a discussion in the Alpha Message Board. In the following weeks I will post how the date object works as told by w3schools.

Think of a scenario where a vendor sends you a bill. The bill may be due in various dates according to the terms established by the vendor, for example it may be due on delivery, 10 days from delivery, certain day of the month or end of the month etc.,

So I have created a dialog in Alpha Five that will deal with three fields. Date of invoice, terms and due date.  Since this is only to show the date object functionality, I have designed that way.  In real world the terms will be at the vendor file and it will populate when you select the vendor and the due date will be calculated and assigned when you select the invoice date. You may be able to change the terms on the fly with the option of changing it permanently in the vendor table or just for this particular invoice.  I have not shown that since that is not planned.  The example deals with how the date object is manipulated, that is it.  You can use your imagination to build more complex component, if you wish.

In this example I have three fields. Date of Invoice, Terms and Due Date. The field terms is a drop-down with three options. The options are
(1) due 10th day of month returned value 1
(2) end of the month returned value 2
(3) 10 days from the bill returned value 3
The date of invoice is entered and in the onChange event of the field Terms I have written the inline JavaScript code that fires and calculates the due date according to the terms picked. It is important to notice that the dates are good even for leap years and leap centuries.

So here is the video:
http://screencast.com/t/mn0CtPesHq

the code that runs in the onChange event of the field Terms is here:
As I said earlier this is only for demonstration, you can assign the various values as you like and arrive at your desired result.

var invDate = {dialog.Object}.getValue('DATE_OF_INVOICE');
invDate = new Date(invDate);
var terms = {dialog.Object}.getValue('TERMS');
if (terms == 1) {
//alert('10th of the month');
var due_day = 10;
var d1 = invDate.getDate();
var m1 = invDate.getMonth()+1;
//
if (d1 <= due_day) {
var new_invDate = invDate.setDate(due_day);
}
else
{
new_invDate = invDate.setDate(due_day);
new_invDate = invDate.setMonth(m1);
}
invDate.setTime(new_invDate);
var mm = invDate.getMonth()+1;
if (mm < 10) {
mm = "0"+mm;
}
var dd = invDate.getDate();
var yyyy =invDate.getFullYear();
}
else if (terms == 2) {
//alert('end of the month');
var lastDayOfMonth = new Date(invDate.getFullYear(),invDate.getMonth()+1,0);
var mm = lastDayOfMonth.getMonth()+1;
var dd = lastDayOfMonth.getDate();
var yyyy = lastDayOfMonth.getFullYear();
}
else if (terms == 3) {
//alert('10 days from invoice');
invDate.setTime(invDate.getTime()+(10*24*60*60*1000));
var mm = invDate.getMonth()+1;
var dd = invDate.getDate();
var yyyy = invDate.getFullYear();
}
var due_date = mm + "/" + dd + "/" + yyyy;
{dialog.Object}.setValue('DUE_DATE',due_date );

Please let me know if there are any errors and any improvements I can make.

Saturday, February 22, 2014

Edit Web Security User

Edit Web Security User..

Okay, last week we saw how I created a dialog to add web security users, they are all added to a group called "New User". The new user group has very limited functionality and is restricted. However you can login and edit those credentials using a edit dialog.

In order to do that you will need two components.  One grid to show the currently enlisted users with a button select to edit the data and a dialog to edit the data to save.

As you remember we created a separate table to hold personal data with a common link to the web security table using the email as a link, since that is the sign in user name.

The grid will display the users and when you click the edit button the dialog will pop up with the data and you will edit all the information.  The secret is that alpha has helper functions that load and save the data back and forth from the security tables.  You don't have to write a separate code to do that.  You will be primarily concentrating on the table that you created for the user and rest alpha will take care of.  The ID from the grid is passed onto the dialog via a session variable so the dialog knows which record it should fetch to populate.  Once edited the record is saved to the private and as well as the security tables.

Since this involves security, it is better to have all these components require a login.

Here are the videos:
WebSecurity User Edit Video 1
http://screencast.com/t/fmhL1gFQI

WebSecurity User Edit Video 2
http://screencast.com/t/45J0wVl3bI

WebSecurity User Edit Video 3
http://screencast.com/t/amK07SCwC

Thursday, February 13, 2014

So you want to setup web security in AlphaFive...

So you want to setup web security in AlphaFive...

I was very busy during the holiday season, the business I am in demands that.  I skipped many weeks of posting.  Sorry about that.
So I thought now is the best time to talk about web security.
By default the web security is not enabled.  You have to enable it then create the necessary components to go with it.

To start with, go to web menu on the top and select the application server and then turn on the web security by clicking the checkbox enable security framework.  You may have to restart the server for this to take effect.

Then go to web control panel and click on the websecurity.  Then on the dialog that pops up click on the web configuration, the first choice. There turn on the web security and fill in all the necessary information.  You may want to create dummy login files and logout files if you need to.  Also select a random encryption key, I let alpha do it for me.

Once you have done that, it is time to setup security users and their permissions.
The following screencast shows how to setup the security. Take a look:
http://screencast.com/t/GuG5Qt97

Once you have set the security up, the first thing we need to do is add a new user or many users.
This can be easily done via the interface Alpha provides. But that has very limited use. If you want to add additional data regarding the user then it is better with a dialog that will add additional data to the security information.  Fortunately Alpha provides a template, that you can use and take advantage of it.
So when you want to build a dialog to add user with additional information select that template and first thing you do is remove all data binding.  You have an option of asking Alpha to create a table in your backend or you can create then bind to the fields.  When Alpha creates the table all the bindings are set to start with.
Since the dialog is template driven and was bound to other controls in the template, ou need to go back to each server side functions and edit them.  You may not need to correct any but you need to go through the steps so the xbasic commands are refreshed to reflect the changes.
Here is a video showing the dialog being built, take a look:
http://screencast.com/t/jW5W8WOqv

After configuring the dialog to add user, you need to go to each of the server side functions and edit them so that the xbasic will be re-written and the new values will take effect.
Here is that video, take a look:
http://screencast.com/t/8epwwLRH

Here is the final video where I am entering a new user to the security system.
http://screencast.com/t/OSfXwP8WEY
 

Friday, November 8, 2013

Basic Report

Today I will be showing you how to do a basic report.
In order to do this correct you need to set up the path alias properly. In one of the previous posts I have done that. Please follow that post and establish the path alias before constructing the report.

Since this is done with MySQL back end, the report will be based on SQL Data source.  Select the connection string and the table then design the report as usual.  Drag and drop the fields necessary. And once done preview the report and if all is satisfactory save the report with a name you can recall. That's it. You are done.

Now place the report in the tabbedui_main and publish you will be able to see via a browser interface.

take a look at the screencast:

http://screencast.com/t/caenE36BLM 

Wednesday, October 30, 2013

Today I will be showing various steps to show your web site over the Internet and sending email from the website.
In order to reach your website from somewhere using a browser you will need to few steps.
First go to the computer where you will hosting the server and cmd window and type the command: ipconfig and copy the ip address of the computer.
Then go to Google and find out the ip address of your site by typing what is my ip in the search box.
Then go to the base of you router, usually it is either 192.168.0.1 or 192.168.1.1 then login and go to the advanced tab and forward your alpha port to that local ip address.
if you need to adjust the firewall then allow the alphawas to be a permitted program.
Then test it you should be able to reach your website from outside.

Sending email from your website:

First setup the email in Project properties, then setup Email in the view, setting, email.  Test to see the test email shows success.  If succeeded then you can create a dialog and send the email from your web site.

Please see all of the following screencasts showing the above.

Port Forwarding:
http://screencast.com/t/cU5nUuuZc
Path Alias:
http://screencast.com/t/AuJnBUyeRi6
Reaching from outside:
http://screencast.com/t/13X1mOBgvh6
Sending Email Part1, setting up profile and account settings:
http://screencast.com/t/UC8TWAYFs
Dialog and sending the email:
http://screencast.com/t/ack8hhLbIc
Sending Email from website:
http://screencast.com/t/8rTrYeUTw0v

Friday, October 25, 2013

Few More Standard Grids With Search

Okay

Now I have built few more standard grids with search part and detail part which I have uploaded to the tabbedui_main page.
Since these are simple and similar I am gong to show only one and rest are all the same.

Here are the videos.

http://screencast.com/t/c3rogbBtNeZ

http://screencast.com/t/YglUf6ypB

Next week or so I will show how to create reports and send emails.

Tuesday, September 24, 2013

September 24th 2013:

Last time we saw how to do a tabbed ui interface.  Today I am going to add few features to it to make it look pretty and as well as add picture to the home tab.

Here are the videos:
http://screencast.com/t/mEZAYnoGGWP

http://screencast.com/t/XPIoFLxQpn

http://screencast.com/t/Ozw5cIfbNY

Next week I will be showing you how to create a component that has a search part with many fields to select from.  I have many other grids with simple search part as we did earlier, so I am just going to create them and add them to the tabbed ui interface.

see you next time.