viewmodel.js | |
Functions | |
getViewModelById | Get ViewModel instance by its ID. |
ng_ViewModelFormatError | Formats ViewModel error object to one or more text messages. |
ngFieldDefException | This class implements ngFieldDef type exception. |
Properties | |
FieldDef | Related nfFieldDef object. |
Error | Exception error type flags. |
ErrorMessage | Exception error message (optional). |
ExtendedInfo | Exception extended error information (optional). |
ngFieldDef | This class implements ViewModel field type description object. |
Properties | |
Owner | Owner (usualy ngViewModel) of ngFieldDef. |
ID | Field identifier. |
Type | Basic field type. |
DataType | Field type identifier. |
PrivateField | Determines if field is private. |
Attrs | Field extended attributes. |
DisplayName | Textual description of field. |
Size | Field size. |
Precision | Field precision. |
Required | If TRUE, the value of field is required. |
NullIfEmpty | If TRUE, the empty value of field is considered as null. |
AutoTrim | Type of automatic string trim. |
ReadOnly | If TRUE, the value cannot be modified. |
MinValue | Minimal allowed value. |
MaxValue | Maximum allowed value. |
Enum | Enumeration of allowed values. |
DefaultValue | Default value of field. |
Value | Value of field. |
Methods | |
GetDisplayName | Gets field DisplayName. |
GetTypedValue | Gets field typed value. |
GetTypedDefaultValue | Gets field typed default value. |
GetAttribute | Gets field attribute. |
SetAttribute | Sets field attribute. |
TypedValue | Converts given value according to field type. |
TypedValueAs | Converts given value according to external field type. |
Clear | Sets field value to undefined. |
Validate | Validates if given value can be converted according to field type. |
FormatError | Formats ViewModel error object to one or more text messages. |
Serialize | Exports (and converts) given value from ViewModel. |
Deserialize | Imports (and converts) given value to ViewModel. |
FormatString | Converts given value to string according to field type. |
EditString | Converts given value to string suitable for editation according to field type. |
ParseString | Converts given string value to value according to field type. |
Events | |
OnFormatError | |
OnSerialize | |
OnDeserialize | |
OnTypedValue | |
OnFormatString | |
OnEditString | |
OnParseString | |
ngViewModel | This class implements ViewModel object. |
Properties | |
Namespace | ViewModel namespace. |
ViewModel | ViewModel properties. |
DefaultValues | Holds default values for non-ngFieldDef properties. |
ServerURL | ViewModel’s server script URL. |
ActiveCommand | Current running server-side command. |
Methods | |
Assign | Assigns settings and values from another ViewModel. |
SetNamespace | Sets ViewModel namespace. |
SetViewModel | Sets ViewModel modification. |
SetValues | Sets values to ViewModel. |
GetValues | Gets values from ViewModel. |
ScanValues | Scans all ViewModel values. |
GetFieldByID | Gets field in ViewModel based on property ID. |
GetFieldValueByID | Gets ViewModel value based on property ID. |
SetFieldValueByID | Sets ViewModel value based on property ID. |
Reset | Resets ViewModel to initial state. |
IsValid | Tests if all (or selected) ViewModel’s properties are valid. |
Errors | Gets textual description of ViewModel’s errors. |
ShowErrors | Displays ViewModel errors. |
Command | Sends command to the server. |
CancelCommand | Cancels running command. |
GetCommandValueNames | Gets value names for specified command. |
GetCommandValueNamesByFieldAttrs | Gets value names for specified command based on field attribute ‘Command’. |
GetRPC | Gets current ngRPC for ViewModel requests. |
Events | |
OnSetValues | |
OnSetValue | |
OnGetValues | |
OnGetValue | |
OnCommand | |
OnGetCommandValueNames | |
OnDoCommand | |
OnCommandRequest | |
OnCommandResults | |
OnCommandFinished | |
OnCommandCancel | |
OnCommandData | |
OnSetViewModel | |
OnViewModelChanged | |
OnResults | |
OnErrors | |
OnShowErrors | |
OnAssign | |
ngDataSetFieldDef | ngViewModel DataSet field (based on ngFieldDef ARRAY). |
Properties | |
DataSetNeedUpdate | Indicates if fresh data is requested from server on data update. |
Methods | |
InvalidateDataSet | Indicated that fresh data is requested from server on data update. |
ngLookupFieldDef | ngViewModel Lookup field (based on ngFieldDef ARRAY). |
Properties | |
DataSetNeedUpdate | Indicates if fresh data is requested from server on data update. |
Methods | |
InvalidateDataSet | Indicated that fresh data is requested from server on data update. |
Knockout extensions | This extends Knockout functions for viewmodel definition. |
Functions | |
ko. | Marks viewmodel property as non-serializable. |
ko. | Marks viewmodel property as serializable. |
ko. | Creates computed viewmodel property which value is gathered from another model. |
ko. | Creates computed viewmodel property which translates boolean to other viewmodel property value (or values). |
ko. | Creates computed viewmodel property which formats string (PHP like sprintf function) based on values of other viewmodel properties. |
ko. | Creates computed viewmodel property which detects value changes of enumerated properties. |
ko. | Creates computed viewmodel property, similar to ko.ng_changed, which detects value changes of enumerated properties and increases it’s value every time the change occurs. |
ko. | Creates computed viewmodel property which is set to TRUE if all enumerated properties equals to specified values. |
ko. | Creates computed viewmodel property which is set to TRUE if at least one of enumerated properties equal to specified value. |
ko. | Creates computed viewmodel property which is repeatedly updated on specified interval. |
ko. | Creates computed viewmodel property which transforms value of given property to value in lookup table. |
ko. | Encapsulates ngFieldDef into viewmodel. |
function ng_ViewModelFormatError( err )
Formats ViewModel error object to one or more text messages.
Syntax: array ng_ViewModelFormatError (object error)
error | ViewModel error object (ngFieldDefException or array of ngFieldDefExceptions) |
Array of formated string messages.
This class implements ngFieldDef type exception.
Properties | |
FieldDef | Related nfFieldDef object. |
Error | Exception error type flags. |
ErrorMessage | Exception error message (optional). |
ExtendedInfo | Exception extended error information (optional). |
this.Error
Exception error type flags. Type: object
FIELDDEF_ERR | unspecified error |
FIELDDEF_ERR_TYPE | type conversion exception |
FIELDDEF_ERR_EMPTY | field is empty |
FIELDDEF_ERR_MIN | value is lower than minimal allowed |
FIELDDEF_ERR_MAX | value is lower than maximum allowed |
FIELDDEF_ERR_ENUM | value is not one of allowed |
FIELDDEF_ERR_LEN | length of value exceeds allowed |
This class implements ViewModel field type description object.
Properties | |
Owner | Owner (usualy ngViewModel) of ngFieldDef. |
ID | Field identifier. |
Type | Basic field type. |
DataType | Field type identifier. |
PrivateField | Determines if field is private. |
Attrs | Field extended attributes. |
DisplayName | Textual description of field. |
Size | Field size. |
Precision | Field precision. |
Required | If TRUE, the value of field is required. |
NullIfEmpty | If TRUE, the empty value of field is considered as null. |
AutoTrim | Type of automatic string trim. |
ReadOnly | If TRUE, the value cannot be modified. |
MinValue | Minimal allowed value. |
MaxValue | Maximum allowed value. |
Enum | Enumeration of allowed values. |
DefaultValue | Default value of field. |
Value | Value of field. |
Methods | |
GetDisplayName | Gets field DisplayName. |
GetTypedValue | Gets field typed value. |
GetTypedDefaultValue | Gets field typed default value. |
GetAttribute | Gets field attribute. |
SetAttribute | Sets field attribute. |
TypedValue | Converts given value according to field type. |
TypedValueAs | Converts given value according to external field type. |
Clear | Sets field value to undefined. |
Validate | Validates if given value can be converted according to field type. |
FormatError | Formats ViewModel error object to one or more text messages. |
Serialize | Exports (and converts) given value from ViewModel. |
Deserialize | Imports (and converts) given value to ViewModel. |
FormatString | Converts given value to string according to field type. |
EditString | Converts given value to string suitable for editation according to field type. |
ParseString | Converts given string value to value according to field type. |
Events | |
OnFormatError | |
OnSerialize | |
OnDeserialize | |
OnTypedValue | |
OnFormatString | |
OnEditString | |
OnParseString |
this.Owner
Owner (usualy ngViewModel) of ngFieldDef. Type: object
this.Type
Basic field type. Type: string
’BOOL’ | boolean type |
’INTEGER’ | integer type |
’FLOAT’ | float number type |
’SBYTE’ | signed byte (-127..127) |
’BYTE’ | unsigned byte (0..255) |
’SHORT’ | signed short (-32767..32767) |
’USHORT’ | unsigned short (0-65535) |
’LONG’ | signed long (-2147483647..2147483647) |
’ULONG’ | unsigned long (0..4294967295) |
’DECIMAL’ | number with fixed decimal |
’STRING’ | string type |
’NVARCHAR’ | string type with limited length |
’TIMESTAMP’ | date and time type |
’DATETIME’ | date and time type |
’DATE’ | date only type |
’TIME’ | time only type |
’UTCTIMESTAMP’ | date and time type (UTC) |
’UTCDATETIME’ | date and time type (UTC) |
’UTCDATE’ | date only type (UTC) |
’UTCTIME’ | time only type (UTC) |
’ARRAY’ | array type |
Converts given value according to field type.
mixed TypedValue (mixed value)
value | value to convert |
Converted value or throws ngFieldDefException if convert fails.
Converts given value according to external field type.
mixed TypedValueAs (mixed value, ngFieldDef field)
value | value to convert |
field | field to which type value should be converted |
Converted value or throws ngFieldDefException if convert fails. Thrown exception has reference to this field, not external.
Validates if given value can be converted according to field type.
mixed Validate (mixed value)
value | value to test |
TRUE if value can be converted or ngFieldDefException object with description of conversion failure.
Formats ViewModel error object to one or more text messages.
array FormatError (object error)
error | ViewModel error object (ngFieldDefException or array of ngFieldDefExceptions) |
Array of formated string messages.
Exports (and converts) given value from ViewModel.
mixed Serialize (mixed value)
value | value to serialize |
Exported value or throws ngFieldDefException if convert fails.
Imports (and converts) given value to ViewModel.
mixed Deserialize (mixed value)
value | value to deserialize |
Imported value or throws ngFieldDefException if convert fails.
This class implements ViewModel object.
Properties | |
Namespace | ViewModel namespace. |
ViewModel | ViewModel properties. |
DefaultValues | Holds default values for non-ngFieldDef properties. |
ServerURL | ViewModel’s server script URL. |
ActiveCommand | Current running server-side command. |
Methods | |
Assign | Assigns settings and values from another ViewModel. |
SetNamespace | Sets ViewModel namespace. |
SetViewModel | Sets ViewModel modification. |
SetValues | Sets values to ViewModel. |
GetValues | Gets values from ViewModel. |
ScanValues | Scans all ViewModel values. |
GetFieldByID | Gets field in ViewModel based on property ID. |
GetFieldValueByID | Gets ViewModel value based on property ID. |
SetFieldValueByID | Sets ViewModel value based on property ID. |
Reset | Resets ViewModel to initial state. |
IsValid | Tests if all (or selected) ViewModel’s properties are valid. |
Errors | Gets textual description of ViewModel’s errors. |
ShowErrors | Displays ViewModel errors. |
Command | Sends command to the server. |
CancelCommand | Cancels running command. |
GetCommandValueNames | Gets value names for specified command. |
GetCommandValueNamesByFieldAttrs | Gets value names for specified command based on field attribute ‘Command’. |
GetRPC | Gets current ngRPC for ViewModel requests. |
Events | |
OnSetValues | |
OnSetValue | |
OnGetValues | |
OnGetValue | |
OnCommand | |
OnGetCommandValueNames | |
OnDoCommand | |
OnCommandRequest | |
OnCommandResults | |
OnCommandFinished | |
OnCommandCancel | |
OnCommandData | |
OnSetViewModel | |
OnViewModelChanged | |
OnResults | |
OnErrors | |
OnShowErrors | |
OnAssign |
this.DefaultValues
Holds default values for non-ngFieldDef properties. Type: object Default value: { }
Assigns settings and values from another ViewModel.
void Assign (ngViewModel vm)
vm | source viewmodel |
-
Gets values from ViewModel.
void GetValues ([bool writableonly=false, array valuenames=undefined, object errors={}, bool convtimestamps=false])
writableonly | if TRUE, return only values of non-read-only properties |
valuenames | optional list of property names, returned values are only from properties specified on this list |
errors | all errors which occured during serialization (including type conversion erros) are recorded into this object as name-value pairs “property path”:”exception” |
convtimestamps | if TRUE, values of type Date are returned as timestamps (integer) |
Object containing values.
Scans all ViewModel values.
void ScanValues (function callback)
callback | function which is called on each ViewModel value |
-
function callback (ngViewModel vm, mixed value, ngFieldDef instance, string propid)
vm | ViewModel on which is scan performed |
value | observable or value |
instance | ngFieldDef or same as value |
propid | property ID (including path) in ViewModel |
TRUE, if continue scan.
Resets ViewModel to initial state.
void Reset ([function callback])
callback | optional callback function which is called before value is reset |
-
function callback (ngViewModel vm, mixed value, ngFieldDef instance, string propid)
vm | ViewModel on which is scan performed |
value | observable or value |
instance | ngFieldDef or same as value |
propid | property ID (including path) in ViewModel |
If FALSE, reset of the property will be skipped
Tests if all (or selected) ViewModel’s properties are valid.
mixed IsValid ([bool writableonly=false, array valuenames=undefined])
writableonly | if TRUE, return only values of non-read-only properties |
valuenames | optional list of property names, returned values are only from properties specified on this list |
TRUE if ViewModel’s properties are valid or object with errors as name-value pairs “property path”:”exception”.
Gets textual description of ViewModel’s errors.
array Errors ([bool writableonly=false, array valuenames=undefined])
writableonly | if TRUE, return only values of non-read-only properties |
valuenames | optional list of property names, returned values are only from properties specified on this list |
Array of formated string messages.
Displays ViewModel errors.
void ShowErrors ([object errors])
errors | optional error object, if not specified the ngViewModel.IsValid is used for getting errors |
TRUE is one or more error present and displayed.
Sends command to the server.
void Command (string cmd[, object options])
cmd | command id |
options | command options |
TRUE if command was sent.
ValueNames | optional list of property names; values, which are send to server, are only from properties specified on this list |
Values | optional object with values which are send to server (ViewModel values are ignored) |
URL | optional server URL, default is ServerURL |
Params | optional request ngRPC parameters |
Gets value names for specified command.
mixed GetCommandValueNames (string cmd[, object options, bool exactmatch=false])
cmd | command id |
options | command options (see Command) |
exactmatch | return only value names which are exactly defined for specified command |
Array of value names to be passed together with command or undefined if no specific value names defined for command (all values are sent to server).
Gets value names for specified command based on field attribute ‘Command’.
mixed GetCommandValueNamesByFieldAttrs (string cmd [, bool exactmatch=false])
cmd | command id |
exactmatch | return only value names which are exactly defined for specified command |
Array of value names to be passed together with command or undefined if no specific value names defined for command (all values are sent to server).
ngViewModel DataSet field (based on ngFieldDef ARRAY).
new ngDataSetFieldDef (string id [, object attrs={}])
id | field id |
attrs | field attributes |
Properties | |
DataSetNeedUpdate | Indicates if fresh data is requested from server on data update. |
Methods | |
InvalidateDataSet | Indicated that fresh data is requested from server on data update. |
ngViewModel Lookup field (based on ngFieldDef ARRAY).
new ngLookupFieldDef (string id [, object attrs={}])
id | field id |
attrs | field attributes |
Properties | |
DataSetNeedUpdate | Indicates if fresh data is requested from server on data update. |
Methods | |
InvalidateDataSet | Indicated that fresh data is requested from server on data update. |
this.InvalidateDataSet = ngfd_InvalidateDataSet; this.DoSerialize = ngfd_DataSetFieldSerialize; this.DoDeserialize = ngfd_DataSetFieldDeserialize; } if( typeof ngUserControls = == 'undefined' ) ngUserControls = new Array(); ngUserControls['viewmodel'] =
Indicated that fresh data is requested from server on data update.
void InvalidateDataSet ()
-
This extends Knockout functions for viewmodel definition.
Functions | |
ko. | Marks viewmodel property as non-serializable. |
ko. | Marks viewmodel property as serializable. |
ko. | Creates computed viewmodel property which value is gathered from another model. |
ko. | Creates computed viewmodel property which translates boolean to other viewmodel property value (or values). |
ko. | Creates computed viewmodel property which formats string (PHP like sprintf function) based on values of other viewmodel properties. |
ko. | Creates computed viewmodel property which detects value changes of enumerated properties. |
ko. | Creates computed viewmodel property, similar to ko.ng_changed, which detects value changes of enumerated properties and increases it’s value every time the change occurs. |
ko. | Creates computed viewmodel property which is set to TRUE if all enumerated properties equals to specified values. |
ko. | Creates computed viewmodel property which is set to TRUE if at least one of enumerated properties equal to specified value. |
ko. | Creates computed viewmodel property which is repeatedly updated on specified interval. |
ko. | Creates computed viewmodel property which transforms value of given property to value in lookup table. |
ko. | Encapsulates ngFieldDef into viewmodel. |
ko.ng_delegate = function ( viewModel, propName, readonly )
Creates computed viewmodel property which value is gathered from another model.
function ko.ng_delegate (mixed viewmodel, string propname [, bool readonly])
viewmodel | string ID or instance of viewmodel |
propname | viewmodel property name in reference viewmodel |
readonly | if TRUE, the value in current viewmodel is read-only |
Computed viewmodel property.
ko.ng_bool2val = function ( viewModel, propName, trueValue, falseValue )
Creates computed viewmodel property which translates boolean to other viewmodel property value (or values).
function ko.ng_bool2val (mixed viewmodel, string propname, mixed trueValue [, mixed falseValue])
viewmodel | string ID or instance of viewmodel |
propname | viewmodel property name in reference viewmodel |
trueValue | value which is translated as TRUE |
falseValue | value which is translated as FALSE |
Computed viewmodel property.
ko.ng_sprintf = function ()
Creates computed viewmodel property which formats string (PHP like sprintf function) based on values of other viewmodel properties.
function ko.ng_sprintf (mixed viewmodel, string format [, string propname1, string propname2, ...])
viewmodel | string ID or instance of viewmodel |
format | text with format characters |
propname1..N | viewmodel property names, values of these properties are used as arguments for string formating |
If any of parameters is indexed array the array items are expanded inline as function parameters.
Computed viewmodel property.
ko.ng_changed = function ()
Creates computed viewmodel property which detects value changes of enumerated properties.
function ko.ng_changed (mixed viewmodel, [, string propname1, string propname2, ...])
viewmodel | string ID or instance of viewmodel |
propname1..N | viewmodel property names on which change state is maintained |
If any of parameters is indexed array the array items are expanded inline as function parameters.
Computed viewmodel property.
ko.ng_dataversion = function ()
Creates computed viewmodel property, similar to ko.ng_changed, which detects value changes of enumerated properties and increases it’s value every time the change occurs.
function ko.ng_dataversion (mixed viewmodel, [, string propname1, string propname2, ...])
viewmodel | string ID or instance of viewmodel |
propname1..N | viewmodel property names on which change state is maintained |
If any of parameters is indexed array the array items are expanded inline as function parameters.
Computed viewmodel property.
ko.ng_matches = function ()
Creates computed viewmodel property which is set to TRUE if all enumerated properties equals to specified values.
function ko.ng_matches (mixed viewmodel, string propname1, mixed val1 [, string propname2, mixed val2, ...])
viewmodel | string ID or instance of viewmodel |
propname1..N | viewmodel property names which values are compared |
val1..N | values for comparsion, $ can be used to reference other viewmodel property |
If any of parameters is indexed array the array items are expanded inline as function parameters.
Computed viewmodel property.
ko.ng_matches_one = function ()
Creates computed viewmodel property which is set to TRUE if at least one of enumerated properties equal to specified value.
function ko.ng_matches_one (mixed viewmodel, string propname1, mixed val1 [, string propname2, mixed val2, ...])
viewmodel | string ID or instance of viewmodel |
propname1..N | viewmodel property names which values are compared |
val1..N | values for comparsion, $ can be used to reference other viewmodel property |
If any of parameters is indexed array the array items are expanded inline as function parameters.
Computed viewmodel property.
ko.ng_timer = function ( interval )
Creates computed viewmodel property which is repeatedly updated on specified interval. The value of this property is date and time of last update.
function ko.ng_timer (int interval)
interval | update interval in milliseconds |
Computed viewmodel property.
ko.ng_lookup = function ( viewModel, propname, lookupviewmodel, lookuppropname, lookupkeyfield, lookupdatafield )
Creates computed viewmodel property which transforms value of given property to value in lookup table.
function ko.ng_lookup (mixed viewmodel, string propname, mixed lookupviewmodel, string lookuppropname, string lookupkeyfield=’Value’, lookupdatafield=’Text’)
viewmodel | string ID or instance of viewmodel |
propname | viewmodel property to be transformed |
lookupviewmodel | string ID or instance of lookup viewmodel |
lookuppropname | lookup viewmodel property where lookup table is stored |
lookupkeyfield | property name where key is stored in lookup table |
lookupdatafield | property name where transformed value is stored in lookup table, if null or undefined the transformed value is whole lookup table item |
Computed viewmodel property.
ko.ng_fielddef = function( vm, fd, value )
Encapsulates ngFieldDef into viewmodel.
ngFieldDef ko.ng_fielddef (mixed viewmodel, ngFieldDef fielddef [, mixed value])
viewmodel | instance of viewmodel |
fielddef | ngFieldDef which schould be part of the viewmodel |
value | optional initial value of ngFieldDef |
Encapsulated ngFieldDef as viewmodel property.
Get ViewModel instance by its ID.
function getViewModelById( id )
Formats ViewModel error object to one or more text messages.
function ng_ViewModelFormatError( err )
Related nfFieldDef object.
this.FieldDef
Exception error type flags.
this.Error
Exception error message (optional).
this.ErrorMessage
Exception extended error information (optional).
this.ExtendedInfo
Owner (usualy ngViewModel) of ngFieldDef.
this.Owner
Field identifier.
this.ID
Basic field type.
this.Type
Field type identifier.
this.DataType
Determines if field is private.
this.PrivateField
Field extended attributes.
this.Attrs
If TRUE, the value of field is required.
this.Required
If TRUE, the empty value of field is considered as null.
this.NullIfEmpty
Value of field.
this.Value
ViewModel namespace.
this.Namespace
ViewModel properties.
this.ViewModel
Holds default values for non-ngFieldDef properties.
this.DefaultValues
ViewModel’s server script URL.
this.ServerURL
Current running server-side command.
this.ActiveCommand
Indicates if fresh data is requested from server on data update.
this.DataSetNeedUpdate
Indicates if fresh data is requested from server on data update.
this.DataSetNeedUpdate
Indicated that fresh data is requested from server on data update.
this.InvalidateDataSet = ngfd_InvalidateDataSet; this.DoSerialize = ngfd_DataSetFieldSerialize; this.DoDeserialize = ngfd_DataSetFieldDeserialize; } if( typeof ngUserControls = == 'undefined' ) ngUserControls = new Array(); ngUserControls['viewmodel'] =
Marks viewmodel property as non-serializable.
ko.ng_noserialize = function ( v )
Marks viewmodel property as serializable.
ko.ng_serialize = function ( v )
Creates computed viewmodel property which value is gathered from another model.
ko.ng_delegate = function ( viewModel, propName, readonly )
Creates computed viewmodel property which translates boolean to other viewmodel property value (or values).
ko.ng_bool2val = function ( viewModel, propName, trueValue, falseValue )
Creates computed viewmodel property which formats string (PHP like sprintf function) based on values of other viewmodel properties.
ko.ng_sprintf = function ()
Creates computed viewmodel property which detects value changes of enumerated properties.
ko.ng_changed = function ()
Creates computed viewmodel property, similar to ko.ng_changed, which detects value changes of enumerated properties and increases it’s value every time the change occurs.
ko.ng_dataversion = function ()
Creates computed viewmodel property which is set to TRUE if all enumerated properties equals to specified values.
ko.ng_matches = function ()
Creates computed viewmodel property which is set to TRUE if at least one of enumerated properties equal to specified value.
ko.ng_matches_one = function ()
Creates computed viewmodel property which is repeatedly updated on specified interval.
ko.ng_timer = function ( interval )
Creates computed viewmodel property which transforms value of given property to value in lookup table.
ko.ng_lookup = function ( viewModel, propname, lookupviewmodel, lookuppropname, lookupkeyfield, lookupdatafield )
Encapsulates ngFieldDef into viewmodel.
ko.ng_fielddef = function( vm, fd, value )