Miscellaneous

From nuBuilderPro
Jump to: navigation, search

Navigation

As with any easy to use software it is important to have simple and consistent ways of navigating through an application.


Navigation within nuBuilder falls into one of 3 categories:

Navigating a Browse Form

To navigate the browse form, the aids are the Search and Sort functions.


Searching for a record is relatively simple. Type in all or part of the record name you wish to search for and it should filter out records not containing the search query.


Sorting adds easy sequential navigation. Sorting by alphabetical order, date or numerical value will put the list into ascending or descending order. This is done by clicking the title of the column.


Navigating an Edit Form

Difficulty in navigating the edit form is directly related to the complexity of the form input methods. The main navigation is through the use of tabs, if more than one exist.


Developer short-cuts.

Only admins and users of a certain group can directly modify forms and objects through double-clicking the titles.

States of an Edit Form

By using the display conditions on the various objects on an Edit Form, it is possible to change what is shown on the form over time depending on what events have occurred.


For example if you want to be able to print a copy of an invoice only when it is guaranteed that no changes are going to be made to the invoice. Over the course of this example we will be using the term posted if this guarantee holds. In this example an invoice will have 2 states: posted and not posted.


When the invoice is in the posted state the only operation that can be done to it is a copy of the invoice can be printed. When the invoice is in the not posted state the operations that can be carried out on the invoice are: saving changes, deleting the invoice, and posting the invoice.


To implement this functionality it is required to change the invoice table within the database to have an extra field, which we have called inv_posted. This will allow that posting the invoice is persistent over different sessions.


On the invoice form 2 Extra Action Buttons were added: one for printing the invoice and the other for posting the invoice. print and post buttons added


Forms-Extra-Action.png

Fig 1. Adding the Print Invoice and Post Invoice buttons.


The print invoice button had a display condition that will only show the button if the invoice has been posted.

SELECT IF(inv_posted = 1 AND COUNT(*) != 0, 1, 0) 
FROM invoice 
WHERE invoice_id = '#RECORD_ID#'


When the print invoice button is clicked the Javascript function nuRunPDF('cus_inv') is run to generate a copy of the invoice for printing.


The save, delete and post invoice buttons should only be visible when the invoice is not posted. To do this we use the same principals of hiding the buttons as the print invoice button, but with some modification, as the state these should be hidden in is different.

SELECT IF(inv_posted = 1 AND COUNT(*) != 0, 0, 1)
FROM invoice
WHERE invoice_id = '#RECORD_ID#'


Code for the post invoice button (explanation below)

//Post the invoice by setting posted to 1 and saving
function postInvoice() {
    $('#inv_posted').val(1);
    nuSaveForm();
}


The post invoice button works by:

  • It sets the value of an object that is always hidden to 1. This object is associated with the inv_posted field we added earlier.
  • The Javascript function nuSaveForm() is run so the invoice is posted immediately.


Once the item has been posted any edits made can not be saved, and the invoice can not be deleted.


Results

Invoice-Not-Posted.png

Fig 2. An invoice before posting.


Invoice-Posted.png

Fig 3. An invoice after posting

Uploading a file to a database table

Creating a way to upload a file to a database table can be done with an iFrame Object that uses nuBuilderPro's built in Procedure named FILE.

Iframeuplaodobject.PNG

Then placing the following PHP in the After Save section of Custom Code of the current Form.



IF("#FILES#" != '#FILES'.'#'){                                                  //has something been uploaded?

    $J        = json_decode("#FILES#");                                         //fetch the uploaded file information

    $name     = $J[0]->{'name'};
    $type     = $J[0]->{'type'};
    
    $contents = file_get_contents(sys_get_temp_dir().$name);                    //obtain the contents of the file
    $contents = addslashes($contents);
                                                                                //put the file information and contents into the database
    $s = "
        UPDATE zzz_person
        SET
            zper_file_blob = '$contents',
            zper_file_name = '$name',
            zper_file_type = '$type'
        WHERE zzz_person_id = '#RECORD_ID#'
    ";
    
    nuRunQuery($s);
    
    unlink(sys_get_temp_dir().$name);                                           //delete the temporary file.

}

Uploadiframe.PNG

Now with that done a Button Object can be created that will download that file, by creating an onclick Event that calls a Procedure with nuRunPHP() that contains the following that uses nuDownloadFile().



$s = "

SELECT 
zper_file_type AS file_type, 
zper_file_name AS file_name, 
zper_file_blob AS file_blob 
FROM zzz_person 
WHERE zzz_person_id = '#RECORD_ID#' 

";


nuDownloadFile('', $s);

Automatic Login

Automatically logging in.

This can simply be done by passing the username as u and password as p as part of the URL string

e.g. http://localhost/nubuilder/index.php?u=john&p=123123&k=53a26a6b58e2b3c

  • p=password
  • u=username
  • k=primary key (go straight to this record - left blank or missing, it will go to a new record)


CAUTION This technique should only be done in cases when security is not important.