JavaScript functions v1.0

From TempusServa wiki
Revision as of 12:51, 24 June 2021 by old>Admin (→‎Single dependency)
Jump to navigation Jump to search

 

Code placement

The following places can contain JS code

  • Entity header
  • Entity status
  • JavaScript field

Additionally HTML with inline script can be placed in

  • Wrapper
  • Template

Finally expressions can be evaluated using

  • Entity field dependency

 

Builtin functions

The following functions are only available for single item views (edit or show).

Get and set values

Display values are handled using standard getter and setters

  • getValue(fieldName)
  • setValue(fieldName,value)

Example

var a = getValue("NUMBER1");
var b = getValue("NUMBER2");
setValue( "RESULT", (a-b) );

For explicitly getting a value (or ID) use

  • getDecimal(fieldName)

Example

var recordId = getDecimal("SELECTRECORD");

Toggling fields (5478+)

Note: Hide functions are NOT intended for denying access to data -it will only be hidden in the frontend, but is still accessible to savvy users.

Fields can be shown or hidden calling the fieldname

  • hideField(fieldName)
  • showField(fieldName)

Examples

hideField("USER");
hideField("StatusID");

Dependent toggling

Hiding and showing fields can be made dependent on classes in the TempusServaPage

  • hideFieldForPageClass(fieldName,className)
  • showFieldForPageClass(fieldName,className)

Hiding and showing fields can be made dependent on items current status.

  • hideFieldForStatusId(fieldName,statusId)
  • showFieldForStatusId(fieldName,statusId)

Hiding and showing fields can be made dependent on classes in the TempusServaPage AND items current status.

  • hideFieldForPageClassAndStatusId(fieldName,className,statusId)
  • showFieldForPageClassAndStatusId(fieldName,className,statusId)

In case of advanced setup consider "hide for all first and show for some later". In this example NAME should only be displayed for a few status

hideField("NAME");   
showFieldForStatusId("NAME",1234);
showFieldForStatusId("NAME",1235);

Disclaimer

The functions are the equivilant of JQuery

$("#VB_DATA_"+fieldName).parent().parent().hide();
$("#VB_DATA_"+fieldName).parent().parent().hide();

This means that fields are expected to be wrapped in TWO layers of html tags for the functions to work  

Value dependencies

Using lookup select boxes you can set up complex dependencies between values. The target field will be filtered when the page loads and on all changes to the filter field(s).

Single dependency

  lookupValueFilterOnChange( fieldNameTarget, fieldNameSource, tripleArrayOfConditions );
var conditions = [
  ["Ding", "Foo"],
  ["Dong", "Foo"],
  ["Ding", "Bar"],
];
lookupValueFilterOnChange("LOOKUP", "FILTER", conditions );

In the above "Ding" and "Dong" will be available to select when FILTER = "Foo"

Double dependency

  lookupValueFilterDoubleOnChange( fieldNameTarget, fieldNameSource1, fieldNameSource2, tripleArrayOfConditions );
var conditions = [
  ["Ding", "Foo", "Cat"],
  ["Dong", "Foo", "Dog"],
  ["Ding", "Bar", "Cat"],
  ["Dong", "Bar", "Fish"],
];
lookupValueFilterDoubleOnChange("LOOKUP", "FILTERA", "FILTERB", conditions );

In the above "Ding" will be available to select when either :

  • FILTERA = "Foo" -AND- FilterB = "Cat"
  • FILTERA = "Bar" -AND- FilterB = "Cat"

Value triggers

Value triggers will make things happen when a field changes. Multiple triggers can be assigned to the same field.

  • setValueOnChange(sourceName,targetName,targetValue)
  • setValueOnSetValue(sourceName,sourceValue,targetName,targetValue)

Sets the value if another field is changed. Optionally only if a ceratain value is selected (sourceValue)

   setValueOnChange("CATEGORY","Silver","StatusID","Customer changed")
  • warningOnChange(sourceName,message)
  • warningOnSetValue(sourceName,sourceValue,message)

Display a warning to a user if another field is changed. Optionally only if a ceratain value is selected (sourceValue)  

Inspect command and users

The currect command can be examined using

  • isCommandNew()
  • isCommandEdit()
  • isCommandList()

Note that commands are allways added as a class to the #TempusServaPage element

   <div id="TempusServaPage" class="TempusServaPage listCommand da_DK">

User types can be determined using

  • isUserAdmin()
  • isUserExternal()
  • isUserNormal()

Note that special roles are allways added as a class to the #TempusServaPage element

   <div id="TempusServaPage" class="TempusServaPage IsAdministrator listCommand da_DK">

This allows for custom CSS for special roles

   .IsAdministrator h1 { color: red; }

Other functions

  • selectSingleOption(fildName)

Will set a value if only one option is avaiable in a select box.

 

Control variables

TS uses a number of special variables to control the behavior of the frontend. These variables can be changed anywhere.

Opening new windows

Window default sizes are controlled by the following variables

  • tsOpenWindowHeight = 680;
  • tsOpenWindowWidth = 820;

 

Dependency hiding fields

hideTableRowsForElements is by default true.

Set to false if template structure is only in a single level.

  • true: Hide two parent nodes when hiding fields
  • false: Hide single parent node when hiding fields

Example of 2 level template (default)

<tr>
  <td>
    <input ..

Example of 1 level template (special cases)

<div>
  <input ..

 

Other sources