Javascript

From nuBuilderForte
Revision as of 01:30, 27 January 2020 by Admin (talk | contribs) (→‎nuFilterRun)
Jump to navigation Jump to search


Each Form can contain custom Javascript code - except Subform Forms.

Any Javascript function run from a Subform's Object will use the custom Javascript code in its main Edit Form.

Each of the yellow diamonds containing JS is added before it's Form is displayed and can do 2 things.

  1. Run Javascript as the Form is loaded.
  2. Create functions that can be used once the Form is loaded.


Click to view larger


eg. <source lang="javascript">

if(nuFormType() == 'edit'){

   nuAddActionButton('nuRunPHPHidden', 'Run', 'nuRunPHP("UDSTK")');            //-- run as the Form is loaded

}


function copyToDelivery(){ //-- custom function that will be run on an Object Javascript event

   var s   = $('#inv_street_address').val();
   
   $('#inv_delivery_address').val(s);
   

}

</source>


nuAccessLevelCode

string = nuAccessLevelCode()

Parameters


Return Value

Returns the Access Level Code.

Description

Returns the Access Level's Code for the User currently logged in, but blank if logged in as globeadmin.

Example

console.log(nuAccessLevelCode());

console.log()

SUPERUSER

Also See : nuUserName

nuAddAction

nuAddAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will take the user to the Edit Form of a new record.

Example


console.log()


Also See : nuAddActionButton

nuAddRow

nuAddRow(string1)

Parameters

string 1  : Subform Object id

Return Value


Description

Adds a new row to a Subform and sets the focus to the first colmn in that row.

Example

nuAddRow('items_subform');

console.log()


Also See : nuSubformObject

nuAttachButtonImage

nuAttachButtonImage(string1, string2);

Parameters

string 1  : Object id
string 2  : File code

Return Value


Description

Adds a background image to a HTML button object, from nuBuilder Files.

Example

nuAttachButtonImage('run_file', 'FP');

console.log()


Also See :


nuAttachImage

nuAttachImage(string1, string2);

Parameters

string 1  : Object id
string 2  : File code

Return Value


Description

Adds an HTML img object to nuBuilder Forte's HTML Object, from nuBuilder Files.

Example

nuAttachImage('floor_plan', 'PLAN');

console.log()


Also See :


nuAddActionButton

nuAddActionButton(string1, string2, string3);

Parameters

string 1  : Action Button id
string 2  : title
string 3  : function to run.

Return Value


Description

Add an Action Button.

Example

nuAddActionButton('nuRunPHPHidden', 'Build Fast Form', 'nuRunPHPHidden("RUNFF")');

console.log()


Also See :


nuBeforeDelete

nuBeforeDelete()

Parameters


Return Value


Description

Before a record is deleted, nuBuilder checks for the existance of a function called nuBeforeDelete().

If this exists it will use its return value to decide whether to continue deleting the record.

Example


function nuBeforeDelete(){

   if(nuUserName() != $('#cus_name').val()){

      nuMessage(['You can only delete your own records']);
      return false;

   }
    
    return true;
    
}

console.log()


Also See :


nuBeforeSave

nuBeforeSave()

Parameters


Return Value


Description

Before a record is saved, nuBuilder checks for the existance of a function called nuBeforeSave().

If this exists it will use its return value to decide whether to continue saving the record.

Example


function nuBeforeSave(){

    if($("[data-nu-field='ff_browse']:checked").length == 0){
        
        nuMessage(['At least 1 Browse needs to be checked..']);
        
        return false;

    }

    if($('#fastform_table').val() == ''){
        
        nuMessage(['Table Name cannot be left blank..']);
        
        return false;

    }
    
    return true;
    
}

console.log()


Also See :


nuCached

boolean = nuCached(string1)

Parameters

string1  : Code of the file stored in nuBuilder (zzzzsys_file).

Return Value

boolean  : If already saved in the browser.

Description

If returning false, it will attempt to copy the file from the database to the browser.

Example

var alreadyHere = nuCached('Logo');

console.log()


Also See :



nuChart

nuChart(string1, string2, string3, string4, string5, string6, string7, boolean8)

Parameters

string1  : ID of the div the Chart will appear in.
string2  : Type of Chart (PieChart, ComboChart or BarChart).
string3  : Data for Chart
string4  : Chart title.
string5  : X Axis title
string6  : Y Axis title 
string7  : Series type (bars or lines)
boolean8 : Is a Stacked Chart (true or false)

Return Value


Description

Draws a Google Chart inside a DIV.

Example


var thedata = [
                ['Month', 'Shane', 'Dave', 'Adam', 'Paul', 'Chris'],
                ['2004', 100, 200, 300, 400, 500],
                ['2005', 165, 238, 322, 498, 550],
                ['2006', 165, 938, 522, 998, 450],
                ['2007', 135, 1120, 599, 1268, 288]
              ];

nuChart('chart_div', 'BarChart', 'thedata', 'Sales', '', '', 'bars', true);


console.log()


Also See :


nuCloneAction

nuCloneAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will make a copy of the current record ready to save.

Example


console.log()


Also See : nuAddActionButton


nuClosePopup

nuClosePopup()

Parameters


Return Value


Description

Closes a nuBuilder Popup window.

Example


console.log()


Also See : nuPopup

nuCurrentProperties

object = nuCurrentProperties()

Parameters


Return Value

object  : all properties for the current Form

Description

Returns all properties for the current Form as an object.

Example

var p = nuCurrentProperties();
console.log(p.record_id);

console.log()

-1

Also See : nuGetProperty, nuSetProperty


nuCurrentRow

number = nuCurrentRow()

Parameters


Return Value

number  : Subform Row number currently with focus.

Description

Returns Subform row number currently with focus.

Example

var r = nuCurrentRow();
console.log(r);

console.log()

7

Also See :


nuDeleteAction

nuDeleteAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will will delete the current record.

Example


console.log()


Also See : nuAddActionButton

nuDisable

nuDisable(string1)

Parameters

string1  : Object id.

Return Value


Description

This will disable all parts of a nuBuilder Forte Object.

Example

nuDisable('cus_phone2');

console.log()


Also See : nuEnable

nuEmailReportAction

nuEmailReportAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will send a report as an email.

Example


console.log()


Also See : nuAddActionButton

nuEmbedObject

nuEmbedObject(string1, string2)

Parameters

string1  : JSON string
string2  : DIV id

Return Value


Description

Converts a JSON string (generally created by an input:file Object) to an embedded HTML Object eg. to display an image.

Example


console.log()


Also See :


nuEnable

nuEnable(string1)

Parameters

string1  : Object id.

Return Value


Description

This will enable all parts of a nuBuilder Forte Object.

Example

nuEnable('cus_phone2');

console.log()


Also See : nuDisable


nuFilterRun

nuFilterRun(string1 string2)

Parameters

string1  : Run Object id.
string2  : Filter.

Return Value


Description

This will apply a different Filter to a Run::iFrame Object and recreate it Run Object.

Example

nuFilterRun('cus_run', '5000');

console.log()


Also See :


nuForm

nuForm(string1, string2, string3, string4, string5)

Parameters

string1  : Form id
string2  : record id of the Edit Form or an empty string to display a Browse Form.
string3  : Filter string
string4  : Search string
string5  : '0', '1' or '2'
  • 0 = Open Form in a new Breadcrumb.
  • 1 = Open Form in the current Breadcrumb.
  • 2 = Open Form in a new window.

Return Value


Description

Opens a Form.

Example

nuForm(nuGetProperty('form_id'), r, '', '', '1');

console.log()


Also See :


nuFormType

string = nuFormType()

Parameters


Return Value

string : 'edit or 'browse'

Description

Returns the current Form type.

Example

if(nuFormType() == 'edit'){
    nuAddActionButton('nuRunPHPHidden', 'Run', 'nuRunPHP("UDSTK")');
}

console.log()


Also See :


nuGetBreadcrumb

nuGetBreadcrumb(number1)

Parameters

number1  : breadcrumb number - this parameter is optional. (leaving it blank will simply refresh the current Form)

Return Value


Description

Go to a previous Breadcrumb.

Example

nuGetBreadcrumb(0);

console.log()


Also See :



nuGetLookupId

nuGetLookupId(string1, string2)

Parameters

string1 = Primary Key
string2 = Primary Key of Lookup Object to populate

Return Value


Description

Used to populate a Lookup Object with a Primary Key.

Example

nuGetLookupId('5afaa13eb523846', '5afaa13eb523832');

console.log()


Also See :


nuGetPHP

nuGetPHP(string1, string2)

Parameters

string1  : Form ID
string2  : Procedure ID

Return Value


Description

Opens a Form ready to run a Procedure.

Example

nuGetPHP('nublank', '5adc174ff19fec9')

console.log()


Also See : nuRunPHP

nuGetProperty

value = nuGetProperty(string1)

Parameters

string1  : Form property

Return Value

value    : value of Form property

Description

Get a Form's property.

Example

if(nuGetProperty('record_id') == ''){
    nuAddActionButton('nuRunPHP', 'Run', 'nuRunPHP("INV")')
}

console.log()


Also See : nuCurrentProperties, nuSetProperty

nuHasBeenEdited

nuHasBeenEdited()

Parameters


Return Value


Description

This will set the status of an Edit Form to Edited and do 2 things

  1. The Save Action Button will change to red.
  2. The web browser will alert the user if leaving the current record before it is saved.

Example


console.log()


Also See : nuHasNotBeenEdited

nuHasBeenSaved

nuHasBeenSaved()

Parameters


Return Value

number  : Number of times the current Edit Form  has been saved.

Description

Shows how many times (while on this Form) the current Edit Form has been saved and -1 if on a Browse Form.

Example


console.log()


Also See :


nuHasNotBeenEdited

nuHasNotBeenEdited();

Parameters


Return Value


Description

This will set the status of an Edit Form to not Edited and do 2 things

  1. The Save Action Button will return to its normal color.
  2. The web browser will not alert the user when leaving the current record.

Example


console.log()


Also See : nuHasBeenEdited

nuHide

nuHide(string1)

Parameters

string1  : Object id.

Return Value


Description

This will hide all parts of a nuBuilder Forte Object.

Example

nuHide('cus_phone2');

console.log()


Also See : nuShow

nuHideHolders

nuHideHolders(number1, number2, number3);

Parameters

numbers : any combination of 0,1 or 2.

Return Value


Description

Hides Holders From the top of a Form.

  • 0 Action Holder
  • 1 Breadcrumb Holder
  • 2 Tab Holder

Example

nuHideHolders(0,2);

console.log()


Also See :


nuID

nuID()

Parameters


Return Value


Description

Creates a string from...

  • c - Because it was created on the client.
  • 1502691915023 - time().
  • 1002 - An incrementing number looping between 1000 and 9999.

Example

nuID();

console.log()

"c15026919150231002"

Also See : nuID


nuIsClone

boolean = nuIsClone()

Parameters


Return Value

boolean  : If the current Form is being Cloned.

Description

Used to tell if the current Edit Form is being Cloned.

Example

nuIsClone();

console.log()

true

Also See : nuIsNewRecord

nuIsNewRecord

boolean = nuIsNewRecord()

Parameters


Return Value

boolean  : If the current Edit Form is new.

Description

Used to tell if the current Edit Form is a new, unsaved, record.

Example

nuIsNewRecord();

console.log()

false

Also See : nuIsClone,nuIsSaved

nuIsSaved

boolean = nuIsSaved()

Parameters


Return Value

boolean  : If the current Edit Form has been Saved.

Description

Used to tell if the current Edit Form has been edited but not Saved.

Example

nuIsSaved();

console.log()

false

Also See : nuIsClone,nuIsNewRecord

nuMessage

nuMessage(array1)

Parameters

array1  : an array of strings

Return Value


Description

Displays a message.

Example

nuMessage(['Hello','World']);

console.log()


Also See : nuDisplayError

nuOnClone

nuOnClone()

Parameters


Return Value


Description

If the nuOnClone() function exists, it will be run after the Clone Button is pressed on an Edit Form.

This needs to be created in the Javascript section of the Form because it will be removed when any Form first loads - A Form's Javascript is added after that.

Example

function nuOnClone(){
      nuEnable('inv_customer_id');
}

console.log()


Also See : nuEnable, nuDisable

nuOnLoad

nuOnLoad()

Parameters


Return Value


Description

If the nuOnLoad() function exists, it will be run after each Browse and Edit Form loads.

The best place to define this function is in the Header of Setup.

Example

function nuOnLoad(){

   var f = nuCurrentProperties();

   if(nuFormType() == 'edit'){
      console.log('Edit Form ID : ' + f.form_id, 'Record ID : ' + f.record_id);
   }else{
      console.log('Browse Form ID : ' + f.form_id);
   }

}

console.log()

Edit Form ID : nuhome Record ID : -1

Also See : nuFormType, nuCurrentProperties

nuOpenTab

nuOpenTab(number)

Parameters

number : tab index

Return Value


Description

Opens a certain Tab on an Edit Form.

Example

nuOpenTab(0);

console.log()


Also See : nuRemoveTab

nuPopup

nuPopup(string1, string2, string3)

Parameters

string1  : form id
string2  : record id
string3  : filter (only if there is no record id eg. a Browse Form)

Return Value


Description

Open a Form in an iFrame.

Example

nuPopup('nudebug', '', 'line 48');

console.log()


Also See :


nuPrintAction

nuPrintAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will create a HTML form containing the current list in the Browse Form.

Example


console.log()


Also See : nuAddActionButton

nuRemoveHolders

nuRemoveHolders(number1, number2, number3);

Parameters

numbers : any combination of 0,1 or 2.

Return Value


Description

Removes Holders From the top of a Form.

  • 0 Action Holder
  • 1 Breadcrumb Holder
  • 2 Tab Holder

Example

nuRemoveHolders(0,2);

console.log()


Also See :


nuRemoveTabs

nuRemoveTabs(number1, number2, ...)

Parameters

numbers : Tab numbers that will be removed

Return Value


Description

Removes Tabs on an Edit Form.

Example

nuRemoveTabs(0, 2, 3);

console.log()


Also See : nuOpenTab

nuRunPHP

nuRunPHP(string1, string2, string3)

Parameters

string1  : Procedure code
string2  : iFrame id or empty string eg.""
string3  : optional, if this 3rd parameter is passed, any nuBeforeSave() function will not be run.

Return Value


Description

If placed on an Object's click event, it will run a Procedure in a new window.

If string2 is a valid iFrame it will be refreshed with the Procedure from string1.

Example

nuRunPHP('INV', '', 1);

console.log()


Also See : nuBeforeSave, nuAddActionButton

nuRunPHPHidden

nuRunPHPHidden(string1, string2)

Parameters

string1  : Procedure code
string2  : optional, if a 2nd parameter is passed, any nuBeforeSave() function will not be run.

Return Value


Description

If placed on an Object's click event, it will run a Procedure on the server without anything visibly happening.

If you want some Javascript to run after the Procedure, you can add that within that Procedure with nuJavascriptCallback().


Do not run Procedures containing Print or Echo functions with nuRunPHPHidden() because it will stop the server returning a response.

Example

nuRunPHPHidden('INV', 1);

console.log()


Also See : nuBeforeSave, nuAddActionButton, nuJavascriptCallback

nuRunReport

nuRunReport(string1)

Parameters

string1  : a Report code

Return Value


Description

If placed on an Object's click event, it will run a Report in a new browser window.

Example


console.log()


Also See : nuAddActionButton

nuSaveAction

nuSaveAction()

Parameters


Return Value


Description

If placed on an Object's click event, it will save the current record.

Example


console.log()


Also See : nuAddActionButton

nuSelectBrowse

nuSelectBrowse(object1)

Parameters

object1  : browser event

Return Value


Description

This is a built in function that runs when any record on a Browse Form is selected.

It can be overwritten to do whatever you like. - it will reset to its default operation when loading another Form.

Below is an example of a version of this function that will open the Edit Form in a new window...

Example


function nuSelectBrowse(e){
    
    var r   = $('#' + e.target.id).attr('data-nu-primary-key');

    nuForm(nuGetProperty('form_id'), r, '', '', '2');

}

console.log()


Also See :


nuSelectTab

nuSelectTab(object1)

Parameters

object1  : HTML element

Return Value


Description

Displays a certain Tab on an Edit Form.

Example

var e = document.getElementById('nuTab1');

nuSelectTab(e);

console.log()


Also See :


nuSetProperty

nuSetProperty(string1, string2)

Parameters

string1  : Form property
string2  : new value

Return Value


Description

Sets the current Form's property.

This property can then be used as a Hash Cookie.

Example

nuSetProperty('afilter', 'nu%');

console.log()


Also See : nuCurrentProperties, nuGetProperty

nuSetNoSearchColumns

nuSetNoSearchColumns(array1)

Parameters

array1  : array of column numbers.

Return Value


Description

Excludes a list of columns from being searched on the current Browse Form.

Example

nuSetNoSearchColumns([1,3,4]);

console.log()


Also See :


nuSetVerticalTabs

nuSetVerticalTabs()

Parameters


Return Value


Description

Sets the Tabs of an Edit Form Vertically to the Left.

Example

nuSetVerticalTabs();

console.log()


Also See :


nuSetTitle

nuSetTitle(string1)

Parameters

string1  : phrase

Return Value


Description

Sets the current Edit Form's last breadcrumb to a certain value.

Example

nuSetTitle($('#cus_name').val());

console.log()


Also See :


nuShow

nuShow(string1)

Parameters

string1  : Object id.

Return Value


Description

This will display all parts of a nuBuilder Forte Object.

Example

nuShow('cus_phone2');

console.log()


Also See : nuHide


nuStopBrowserResize

nuStopBrowserResize()

Parameters


Return Value


Description

Sets a flag to stop Browse Forms automatically resizing when they are first opened

Example

nuStopBrowserResize();

console.log()


Also See :


nuSubformObject

object = nuSubformObject(string1)

Parameters

string1  : Subform Object id  **Passing an empty string will return the main Edit Form as a Subform object.

Return Value

object   : Subform object.

Description

Returns a Javscript object that can be looped through.


As well as having 2 arrays,

  1. .chartData
  2. .chartDataPivot

that can be used by Google Charts.


All values in this object will have any formatting removed. eg $ 1,234.50 will be 1234.5

Example

JSON.stringify(nuSubformObject('sf'));

console.log()


{
"id": "sf",
"foreign_key": "bbb_aaa_id",
"primary_key": "bbb_id",
"object_id": "5a3e518de1c9d39",
"table": "bbb",
"action": "save",
"rows": [["5a4031416e91ea4", "7", 7, 7, 0],
    ["5a4031417052b0f", "ww", 4, 4, 0],
    ["5a40314171ff813", "Jim", 44, 33, 0],
    ["5a40314173b8287", "Jan", -9, 1, 0],
    ["5a403141759ee71", "Billy", 3, 4, 0],
    ["-1", "", "", "", 1]],
"columns": [
    ["5a4031416e91ea4", "5a4031417052b0f", "5a40314171ff813", "5a40314173b8287", "5a403141759ee71"],
    ["7", "ww", "Jim", "Jan", "Billy"],
    [7, 4, 44, -9, 3],
    [7, 4, 33, 1, 4]
  ],
"chartData": [
    ["Name", "Sold", "Profit"],
    ["7", 7, 7],
    ["ww", 4, 4],
    ["Jim", 44, 33],
    ["Jan", -9, 1],
    ["Billy", 3, 4]
  ],
"chartDataPivot": [
    ["Name", "7", "ww", "Jim", "Jan", "Billy"],
    ["Sold", 7, 4, 44, -9, 3],
    ["Profit", 7, 4, 33, 1, 4]
  ],
"edited": [
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
  ],
"deleted": [0, 0, 0, 0, 0],
"fields": ["ID", "cname", "sold", "profit", "nuDelete"]
}


Also See : nuSubformObject


nuSubformRowId

string = nuSubformRowId(object1)

Parameters

object1  : HTML DOM object

Return Value

string   : ID of the record in the subform

Description

Returns the Primary Key of the record in the subform.

Example

console.log(nuSubformRowId(this))

console.log()

5a441af15bc6cf8

Also See : nuSubformObject


nuSubformRowValue

string = nuSubformValue(object1, string2)

Parameters

object1  : HTML DOM object
string2  : Column ID

Return Value

string   : Object Value.

Description

Returns the value of a column in the current Subform row.

Example

console.log(nuSubformValue(this, 'ite_total'))

console.log()

$ 500.00

Also See : nuSubformObject, nuSubformId

nuTotal

nuTotal(string1)

Parameters

string1  : Object id

Return Value


Description

Returns the nuformatted value of a number Object.

The parameter required is either..

  • Object id
  • Subform id + . + Object id

If a Subform id is included, the total will be of all Objects in that Subform.

Example

nuTotal('invoice_item.ite_total');

console.log()

54

Also See :


nuTranslate

nuTranslate(string1)

Parameters

string1  : phrase

Return Value


Description

Swaps a nuBuilder phrase with a phrase in Translations.

Example

nuTranslate('Home');

console.log()

Racine

Also See :



nuUserName

string = nuUserName()

Parameters


Return Value

User name or null (if globeadmin)

Description

User name of the person currently logged in.

Example

console.log(nuUserName());

console.log()

Robert Paulson

Also See : nuAccessLevelCode