rendering ...

Overview

The Table object defines the schema(s) used by an application. The records within a table are stored as JSON objects. Refer to Record Storage

The Table object is defined in the Appname.js File or an external file that defines the Table.

Note

Two instance types for the Table object are used internally.

  1. The first, the static object definition, refers to the static Javascript definition.

  2. The second, refers to a Javascript Table object which is a migrated copy of the static table definition. This instance allows the HTML code to directly access methods defined for the Table, Col and Filter objects.

During the first use of a Table in a scope context the dynamic version of the Table object is created. This is known as the Table migration process. Dynamic versions of the Col and Filter objects are also created by the process.

Definition Syntax

Below is the skeleton of a Table definition. The are coded into the Appname.js File or an external file that defines the Table

oApp.factory('tbl...',['servREG',..., function(servREG,...) {
  var oFuncs = {};              // The public functions table

  var ...                       // any variables needing static scope

  var oTabProp = {              // The `Table` properties
       recTitle: 'REPS'         // The title displayted for the User
      ,recName:  'repeat'       // Internal name as server key (3rd part)
      ,recType:  'repeat'       // Internal recType as server key (2nd part)
      ,lsName:   '-repeats'     // Key for localstorage cache
      ,tabServ:  oFuncs         // self pointer
      ,order:    {...}          // The optional order statement
      ,cols:    [               // The columns definition
                ]
      ,filters: [               // The optional fileters definition
                ]
      ,...                      // The optional exits reference
      ,...                      // The optional properties definitions
  };

  oFuncs.getTabProp = function() {return oTabProp;}    // Make oTabProp properties public
  oFuncs.getSupMap  = function() {return getSupMap();} // Make optional function public
  servREG.registerTable(oFuncs); // register the Table defintion
  return oFuncs;                 // return this definition to AngularJS

  // code local functions here
  function getSupMap() {
     ...
  }

  ...

}]);

where

Line 1:Standard factory statement to load required components and define this table. tbl... is the name of the table being defined.

Line 2:Coded as is to provide object in which to return public functions.

Line 3:Define optional private variables that must have static scope.

Line 6:The oTabProp definition is coded as is and provides an object in which to define the table properties.

Line 7:The recTitle statement defines the public visible name of the table and shows up, for example, in the menu displays. This is also the name used in the servREG.findTable method.

Line 8:The recName statement defines the internal name used as Part3 of the Key Structure when in REC Mode

When this value ends with a "%", the chunked mode operation is triggered.

For TBL Mode this parameter is not specified as Part3 of the Key Structure is determined by some computation.

Line 9:The recType statement defines the internal record type and is used as Part2 of Key Structure. Across all the tables used by an application this value must be unique.

For User Records the recType is not defined and triggers Admin access to the User Records.

Line 10:The lsName statement defines the application unique name under which local copies of records are cached. If this value is not specified (as for User Records) no caching occurs and access of the records always returns to the server.

Line 11:The tabServ definition is coded as is and provides a self pointer.

Line 12:The optional order property causes the table to be listed in a certain sequence by the List Controller.

If order is a literal string that names a field, the records are sorted by the specified field in ascending sequence. eg: order:'name'

If order is a function, each object is passed to the function as the first parameter. The function returns a string representing the object. The records are sorted in ascending sequence on the returned string. eg: order:getName

If order is a object, the col property of the object names a field to sort on. If the property seq equals 'reverse' the records are sorted in descending sequence. Otherwise they are sorted in ascending sequence. eg: order:{col:'name',seq:'reverse'}

Line 13:The cols definition provides the definition to the table columns. Refer to Cols Definition.

Line 15:The optional filters definition provides the definition to the table filters. Refer to Filters Definition.

Line 17:Optional exit functions references are defined at this point. Refer to Exit Functions

Line 18:Optional exit functions references are defined at this point. Refer to Optional Properties

Line 21:Coded as is to provide public access to the 'oTabProp' object.

Line 22:An example on how to provide public access to table functions that may be required in applications that access multiple tables simultaneously. See "Deps.js" as an example.

Line 23:Coded as is to register the table definition.

Line 24:Coded as is to return the public function definitions.

Line 26:Optional local functions referenced in the Exit Functions are coded here.

Line 33:Coded as is to end the Table definition.

Exit Functions

The exit definitions link an optional exit to the local implementation of that exit. At the appropriate time as indicated in this section the implementation will be called. The signature of the call is also indicated in this section.

The definitions can occur in any sequence but her listed here in alphabetical sequence. The link will jump to a detailed explanation. The convention is to name the function the same as the exit name.

cacheLoadExitProcess the cache when initally loaded
createExitModify new object before edit
dlgRenderExitModify Dialog Window before edit
fileKeyCompute Key Part 3
fileKeyRefDefine Key Field Reference
getEditRecordExitProcess a record when initally loaded for editing
menuWhenProvide dynamic list of menu items
primeEditPrime the edit before displaying
primeListPrime the list before displaying
saveRecordExitAdjust record before persisting
validateValidate object changes during edit

Exit cacheLoadExit

signature: cacheLoadExit(sFile,oRec)

This exit is taken when a new object or set of objects is loaded from the server. It can be used to adjust (such as adding computed values) or remove objects. The adjusted object or objects are returned and this returned set is loaded into the cache.

Here is a sample exit used in the "Deps.js" application

function cacheLoadExit(sFile,oRec) {
  var sParts = sFile.split(/[.]/);
  var oObj   = {name:sFile,src:sParts[1],currency:sParts[2],counter1:""+oRec.counter1,
               counter2:""+oRec.counter2,acct:"?",cashSum:oRec.cash,
               chequeSum:oRec.cheque,details:oRec};
  log("cacheLoadExit %s rec=%o obj=%o",sFile,oRec,oObj);
  return oObj;
}

Exit createExit

signature: createExit(oObj)

This exit is taken when a new object is being edited by the Edit Controller. It can be used to populate the oObj with default values or remove the tag property inserted by the servCRUD.makeRecord.

A return of true enables the edit to continue. A return of false quietly terminates the edit.

Here is a sample exit

function createExit(oObj) {
  oObj.date      = getNowYMD();
  oObj.number    = 1;
  oObj.enteredBy = getUserStr();
  return true;
}

Exit dlgRenderExit

signature: dlgRenderExit(oDlgEdit,oObj,sEditType)

This exit is taken when a the Dialog Editor Window resulting from a servCRUD.setDlgEdit call is opened by the Edit Controller. It can be used to adjust the Dialog window (such as add a Datepicker) or set up functions to call when the Dialog Window is closed.

The oDlgEdit parameter object contains an array called finals that can be used to add functions to be called when the Dialog Window closes.

The oObj parameter is the object being edited.

The sEditType determines the type of edit and contains Create (new object) or Edit (existing object)

Here is a sample exit from HelloUI App

function dlgRenderExit(oDlgEdit,oObj,sEditType) {
  var oDlg = oDlgEdit.oDlg;
  var sTitle = oObj.title || '** Create New Message **';
  if (sTitle.length > 50) sTitle = sTitle.substring(0,50)+"...";
  oDlg.dialog("option","title","EDIT:"+sTitle);
  $('div.pair#Date input',oDlg).each(function() {
    var oThis = this;
    $(this).attr('id','inp-Date');
    var sDate = oObj.date;
    var oDP = $(this).datepicker({
         dateFormat:'yymmdd'
        ,defaultDate:sDate
        ,onClose:function(sDateText,inst) {
                   oObj.date = sDateText;         // Update the object field
                   $rootScope.$digest();          // angularJS update
                 }
    });
    var oF = function() {$(oThis).datepicker('destroy');};
    oDlgEdit.finals.push(oF);  // we will need to close the Datepicker
  });
  if (oViewScope) {  //If editing from within the Dialog Viewer need to update its object cache
    oDlgEdit.finals.push(function() {oViewScope.doneEdit(oObj);});
  }
}

Exit fileKey

signature: fileKey()

This exit allows a table to dynamically set the Key Part3 based on a User Profile. It is often accompanied with the fileKeyRef.

Here is a sample exit used in the "Chqs.js" application

  function fileKey() {
    var oProf = servSess.getProfile();
    if (!oProf) return "no-prof";
    if (!oProf.chqfile) return "no-chq-file";
    return oProf.chqfile;
  }

Exit fileKeyRef

Strictly speaking this is not an exit in that it does not point to a function. Rather this property indicates to the underlying Triangular routines which User Profile contains the name of Key Part3.

Here is a sample definition used in the "Chqs.js" application

   ,fileKeyRef          : 'chqfile'

Exit getEditRecordExit

signature: getEditRecordExit(oaa)

This exit is taken when the Edit Controller wishes to load an object to be edited. Given oaa this function returns the record to be edited. In the example shown the actual record is within a substructure (details) of the record persisted to the server. The outer structure is used to store computed control information.

Here is a sample exit used in the "Deps.js" application

function getEditRecordExit(oaa) {
  var oObj = oTabProp.oObjs[oaa];
  return oObj.details;
}

Exit menuWhen

signature: menuWhen()

This exit is used to populate the left side menu with action item List ... Records. By default each loaded Table is added to the menu. This exit if it returns false causes the Action Item to not be added. Here is a sample exit taken from the "Deps.js" code.

  function testDoubleLogin() {
    var sUser1 = servSess.getUser();
    var sUser2 = servSess.getUser2();
    if (!sUser1) return false;
    if (!sUser2) return false;
    //log("testDoubleLogin "+sUser1+" "+sUser2);
    if (sUser1 != sUser2) return true;
    return false;
  }

referenced by

      ,menuWhen          : testDoubleLogin

Exit primeEdit

signature: primeEdit(scope,oTP,oObj)

This exit is taken before an object is displayed in the Edit Controller. It can be used to prepare the $scope of the Edit Controller (scope parameter). The oTP parameter is the table properties the oObj (the object being edited) is found in.

Here is a sample exit used in the "Deps.js" application

function primeEdit(scope,oTP,oObj) {
  log("primeEdit scope=%o oTP=%o obj=%o",scope,oTP,oObj);
  scope.setAddFocus    = setAddFocus;
  scope.sAutoName      = '';//force autotab to take
  return oObj;
}

Exit primeList

signature: primeList(scope,oTP)

This exit is taken before an object is displayed in the List Controller. It can be used to prepare the $scope of the List Controller (scope parameter) primarily the Filter work areas. The oTP parameter is the table properties.

Here is a sample exit used in the "Chqs.js" application

function primeList(scope,oTP) {
  log("primeList scope=%o oTP=%o",scope,oTP);
  if ((scope.oSel) && (!('_custPrt' in scope.oSel))) {
    scope.oSel._custprt = '0';
    scope.oSel._custvoid = '0';
    log("setCustPrt %o flag=%s",scope,scope.oSel._custprt);
  }
  nPrintChq = null;
}

Exit saveRecordExit

signature: saveRecordExit(oRec)

This exit is taken before an object is saved by the Edit Controller. It can be used to adjust the contents of a record such as deleting intermediate work fields that might have been created by support routines. The oRec parameter is the record being saved.

Here is a sample exit used in the "Chqs.js" application

function saveRecordExit(oRec) {
  log("saveRecordExit.1 %o",oRec);
  for(var i=0,iMax=oRec.lines.length; i<iMax; i+=1) {
    var oLine = oRec.lines[i];
    delete oLine.bShowCode;
    delete oLine.amtErr;
  }
  return oRec;
}

Exit validate

signature: validate(scope,oObj,oOrig,fValidateStd,fEditErr)

This is called after changes are made to object oObj. The scope references the $scope of the Edit Controller. oOrig is a copy of the object before editting began.

fValidateStd is a callback function that can be called to indicate validation passed but to continue with the standard validation. A return of true by the validate function will bypass the standard validation and indicate the validation passed.

fEditErr is a callback function to register an error and indicate the validation failed.

Here is a sample exit used to validate a User Record update.

  function validate(scope,oObj,oOrig,fValidateStd,fEditErr) { // custom validation
    if (!oObj.obj) return false;
    if (getUserID(oObj) != '.config') {
      if (!('password' in oObj.obj)) return fEditErr("'password' field required");
      if (oObj.obj.password != oOrig.obj.password) {
        if (oObj.obj.password.match(/[a-zA-Z]/) == null) {
          return fEditErr("'password' field must contain alphabetic");
        }
      }
    }
    return fValidateStd(oTabProp);
  }

Optional Properties

The optional properties add properties to the table definition that are used by Triangular processing routines.

The property definitions can occur in any sequence but her listed here in alphabetical sequence. The link will jump to a detailed explanation.

optActionsAdd additional actions to the List Controller header

Property optActions

This is used to add options to the List Controller header. The value of the optActions keyword is an array of objects each with the following properties.

click:A local function to call. The reference is automatically added to the List Controller scope.

title:A user hint string

label:The text shown in the action link

whatClass:a function called to determine if the link is enabled. The reference is automatically added to the List Controller scope.

Here is a sample exit used in the TableEnvelopes demo.

optActions : [{click:'printBatch()',
               title:"Print today's envelopes"
              ,label:'Print Batch'
              ,whatClass:'testBatch()'
             }]