Javascript Functions

From nuBuilderPro
Jump to: navigation, search

nuAddButtons(buttons)

This function adds buttons to a form in the order they are specified in the array

Parameters : buttons : Array of button objects to be created

nuAddRow(pSubformName)

This function adds a new row to a subform

Parameters : pSubformName : Subform Name

nuAjax(pCode [, pFunctionName])

This function runs the PHP Function in pCode and optionally runs a Javascript function using the set value of $nuParameters within the PHP Function as a parameter

If $nuError has a string length longer than 0, an alert box will appear displaying what is set inside it.

For this function, the current user will require access to the PHP Code defined in pCode

Parameters

pCode : The code of the PHP Code to run.

pFunctionName : Name of Javascript Function to run.


AJAX-demo.png

The AjaxStart button calls nuAjax('5','goAjax') when clicked.


The PHP Code contained within the PHP object with code 5 is:

$nuParameters = '#nu_text#';


The Javascript attached to this form under the Custom Code tab contains the goAjax function:


function goAjax(param) {
    if( param === '#nu_text#' ) {
        $('#refresh').val('No refresh');
    }
    else {
        prev = $('#nu_text_history').val();
        $('#refresh').val(param);
        $('#nu_text').val('');
        $('#nu_text_history').val(prev  + param + '\n');
   }
}

nuBrowseColumns()

Returns the number of Columns on a Browse Form.

nuBrowseColumnTotal(columnNumber)

Returns the Sum total for the column number passed.

The PHP function nuGetBrowseSum() must be run inside Before Browse for this to return a value other than 0.

This allows the developer to display the summed result of the filtered Browse Form somewhere on the Form (in this case in the status bar at the bottom of the Browse Form).

eg.



function nuLoadBrowse(){

   lb_sl_sum();

}

function lb_sl_sum(){

	var e = document.createElement('div');              //-- create a new paging object
	e.setAttribute('id', 'the_sum');
	$('#paging_nuStatusHolder').append(e);
	$('#' + e.id).css({
        'width'      : '370px',
        'height'     : '25px',
        'top'        : '10px',
        'text-align' : 'right',
    })

    $('#the_sum').html('Total Tonnes : ' + Number(nuBrowseColumnTotal(5)).toFixed(2));

}

NuBrowseColumnTotal.png

nuBrowseRows()

Returns the number of Rows on a Browse Form.

nuCloneForm(pThis, formID, recordID)

Creates a new Window, sets it with the Form ID and Record ID.

After a breadcrumb is removed and the window is created using nuBuildForm(), a new breadcrumb is added


Parameters :

pThis : This is the object being cloned as a base object

formID : A unique ID for the form to be create

recordID : An ID that this form relates to

nuCurrentRow()

Return current or last prefix of the row accessed.

eg. sf_item0001

nuEmail(pPDF ,pPHP [,pEmailTo] [,pSubject] [,pMessage] [,pFileName])

This function can be run anywhere you can place an onClick event.

It will load the Send Email Dialog which is used to email reports as PDF attachments.

This function is automatically added on all run report screens for emailng PDF reports.


Parameters :

pPDF : The code of the report you need to send (Empty string if using PHP)

pPHP : The code of the PHP generated report you wish to send. (Empty string if using PDF)

pEmailTo : Pre-load the email 'to' field . pSubject : Adds a subject to the e-mail

pMessage : The additional message within the e-mail

pFileName : The specified filename that the file will be sent with, PDF reports have default name of 'Report.pdf', PHP reports specify their own defaults


eg. nuEmailPDF('004', , 'admin@nubuilder.com') This will send the generated PDF report with code 004 to admin@nubuilder.com.

nuErrorMessage(e [, remove])

If not currently logged in, page is redirected to login page

If there are errors, alerts user of every error contained inside e, returns true

Otherwise, returns false


Parameters :

e : An array containing error messages

remove : If not defined, then error breadcrumb is removed

nuFieldTitle(field , list)

Returns field formatted to remove prefixes and underscores using list as a reference.

eg. cus_street_name becomes Street Name if the other strings in list start with cus


Parameters :

field : The field to format.

list : A list containing similar fields to check for a prefix.

nuDisable(object, value)

This function disables editing of an Edit Form Object

Parameters :

object : Object name

value : Set Objects value (optional)

nuEnable(object, value)

This function enables editing of an Edit Form Object

Parameters :

object : Object name

value : Set Objects value (optional)

nuFile(code)

Returns a src value that can be used to display a file uploaded to nuBuilder.


Parameters :

code : This is code of the file uploaded to nuBuilder

nuFormatAjaxErrorMessage(jqXHR [, exception])

This function returns a string containing the error message pertaining to the error response code

If the error code or exception type is not recognized, it will return a string with an uncaught error along with the response text of the error code


Parameters :

jqXHR : This is the error response code

exception : This is a specifically defined error

nuGetHash(name)

Returns the value of a hash variable

Parameters : name : The key of the hash variable to return

nuGetJSONSubform(pSubformName)

This creates a JSON string from data in a subform.

Along with the data from the row there have been 2 additional fields added to the information contained in each row.

  • nuIndex - The order number the row the data came from.
  • nuDelete - true or false, depending if Delete checkbox was checked.
  • nuPrimaryKey - Primary Key (if created) of SubformRow

Parameters :

pSubformName : Name of the Subform Object

This string can then be used like this..


function loopThroughRows(){

    var j = nuGetJSONSubform('sfname')
    var o = JSON.parse(j);

    for(var i = 0 ; i < o.length ; i++){

//-- insert code

    }

}

nuGoToForm([i] [,ask])

Function redirects form to the specified breadcrumb sequence number

If i is not defined, will go to previous form

If ask is not defined, a confirm box will appear asking to leave form


Parameters :

i : Is the order number of breadcrumb form to go to

ask : Option to show a confirm box or not

nuGridClass(row, column, class, remove)

Add or remove a CSS Class from a Grid square.


Parameters :

row : The row in a browse form for the grid square.

column : The column in a browse form for the grid square.

class : The name of the class to add or remove from the grid square.

remove : True removes the class from the grid square. False adds the class to the grid square.

nuGridValue(row, column [, value])

If no value is specified returns the current value of a Grid Square in a Browse Form. If a value is specified the Grid Square in a Browse Form has its value changed to the specified value.


Parameters :

row : The row in a browse form for the grid square.

column : The column in a browse form for the grid square.

value : The value to set the grid square to.

eg. nuGridValue(1,1)  : returns the value in a Browse Form at row 1, column 1.

nuGridValue(1,1,34) : sets the value in a Browse Form at row 1, column 1 to 34.

nuIsGA()

Returns true if the logged in user is Globeadmin, returns false otherwise. This can be used to check access levels in Javascript.

nuLoadBrowse()

Can be created in Javascript under the Custom Code Tab of a Form.

Can be used to manipulate that Browse Form as soon as it has loaded.

eg.


function nuLoadBrowse() {
    calculateTotal();     
    window.prevCustomer = $('#customer_id').val(); 
}

nuLoadBrowseGlobal()

Can be created in Javascript under the Custom Code Tab of any Form (the user's Home Edit Form by convention).

Can be used to manipulate all Browse Forms as soon as they have loaded.

nuLoadEdit()

Can be created in Javascript under the Custom Code Tab of a Form.

Can be used to manipulate that Edit Form as soon as it has loaded.

eg. Finding a cost and setting what a previous customer was


function nuLoadEdit() { 
    calculateTotal();     
    window.prevCustomer = $('#customer_id').val();
}

nuLoadEditGlobal()

Can be created in Javascript under the Custom Code Tab of any Form (usually the user's Home Edit Form).

Can be used to manipulate all Edit Forms as soon as they have loaded.

nuOnClone()

Can be created in Javascript under the Custom Code Tab of a Form.

This function can be used to validate whether the current Record can be Cloned.

Must return true (Clone record) or false (Do nothing).

eg.


function nuOnClone(){     


    if($('#inv_date').val() == ''){
        alert('Cannot Clone a record with no Invoice Date.');
        return false; 
    }else{
        return true; 
    }

}

nuOnSave()

Can be created in Javascript under the Custom Code Tab of a Form.

This function is used to validate the Edit Form before attempting to Save the current record.

Must return true (Save record) or false (Do nothing).

eg.


function nuOnSave(){     
    var data = $('#inv_date').val();     
    if(data != ""){ 
        return false;  
    }else{ 
        return true; 
    }
}

nuOpenForm(parentFormID, parentRecordID, formID, recordID, formTitle [, filter])

Opens the form specified by the parent form, record and the objects form and record.

If the record of the object is unspecified (empty string or null) a browse form is opened, else the edit form specified by the recordID is opened.


Parameters :

parentFormID : The ID of the parent form of the object.

parentRecordID : The record ID of the parent of the object.

formID : The form ID of the object.

recordID : The record ID of the object.

formTitle : The title of the form.

filter : A filter to be applied to the form.

nuOpenFormInFrame(formID, recordID, functionName)

Opens the form specified by the formID and recordID inside of an iFrame popup


Parameters:

formID : The ID of the form to be opened.

recordID : The ID of the record to display within the form.

functionName Name of function to run If defined.


Function must be defined on the same Form as nuOpenFormInFrame() is or globally.


nuOpenPHPForm(code)

Similar to nuRunPHP() but opens the criteria Form specified by the PHP Procedure before running.


Parameters:

code : The code of the PHP Procedure to be opened.

nuOpenReportForm(code)

Similar to nuPrintPDF() but opens the criteria Form specified by the PHP Procedure before running.


Parameters:

code : The code of the Report to be opened.

nuPrintPDF(pCode [, id])

This function can be run on an Edit Form by any User with the appropriate Access Level.

This will launch a PDF in a new Window only if passed the code parameter otherwise it will update what sits in an iFrame.


Parameters :

pCode : The code of the report to run.

id : Field Name of iFrame Form Object.


Eg. nuPrintPDF('cus_inv') : This will run the report defined by the code cus_inv, This was added to an extra action button, to print a pdf of an invoice.

nuReloadForm()

Reloads an Edit Form, undoing anything you have edited.

nuRemoveModal()

Closes the currently opened Modal Window which is an iFrame window popup

nuRowNumber(pThis)

Returns the row of a nuBuilder Object on a Subform.


Parameters :

pThis : The nuBuilder Object to get the row number of.

nuRowPrefix(pThis)

Returns the prefix of a nuBuilder Object (handy when dealing with Subforms).


Parameters :

pThis : The nuBuilder Object to get the prefix of.

nuRunPHP(pCode [, id])

This function can be run on an Edit Form by any User with the appropriate Access Level.

This function makes a call to the server with the PHP Code ID and executes it


Parameters :

pCode : The code of the PHP Code to run.

id : Field Name of iFrame Form Object.

nuRunPrintBrowse()

Prints the current browse view data to the printer

nuSaveForm([ sync = true ] [, operation = 0 ])

This function can be run on an Edit Form by any User with the appropriate Access Level.

Validation can be added by defining a nuOnSave() function which will return true when valid, else it will return false.

After validation is run, the record will be saved and the operation will be carried out.


Parameters :

sync : If other processes can run while saving record.

operation : 0 = Redisplay this record after Saving. 1 = Display a New Blank Record after Saving. 2 = Will return to the previous screen after saving the record.

nuSetHash(name, value)

Adds or sets a hash variable in the global hash variable array


Parameters :

name : The key of assigned to this hash variable

value : The value stored within this hash variable

nuSID()

Returns the current session ID.

nuSubformArray(subformname [, all = true])

Returns an array of all the prefixes used in this subform.

Allowing the developer to loop through an entire subform obtaining the Prefix keys.


Parameters :

subformname : The name of the subform.

all : True = Selects all rows in the subform. False = Ignores rows ticked for deletion.


eg. ["phpAccess0000", "phpAccess0001", "phpAccess0002", "phpAccess0003", "phpAccess0004", "phpAccess0005", "phpAccess0006", "phpAccess0007"]