new model()
- Copyright:
- (c) Copyright 2013 - 2016 AV Digital Media Ltd. All Rights Reserved. No unauthorized copying, distribution or modification to this code in whole or in part is permitted without the express permission of AV Digital Media Ltd (UK).
This is the main model object for the MVC frameworl
Methods
(private, static) _arrayIndexValue(instanceName, name, index, value)
Updates an array index with a completely new value, Returns the value of a modal array index
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name to update the data for |
index |
Number | The index id for the array |
value |
* | The new data for the property |
Returns:
This will return the value at the specified index if any
(private, static) _castTo(type, value)
Cast a value to a specific object type
Parameters:
Name | Type | Description |
---|---|---|
type |
Number | The type, either, 1,2,3,4 |
value |
* | The value to format |
(private, static) _cleanDuplicates(instanceName, or, property, overwrite)
Clean - removes duplicates from a given array
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
or |
Array | {String} reference - The array of items to sort or the name reference of the internal model data |
property |
String | The property name to sort the array by |
overwrite |
Boolean | Determines whether the model stored should be overwritten |
(private, static) _clear(instanceName, name, property)
Clear a property from the model object, this will effectively delete all references to a specific property name in either an Array or Object literal model type
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The name of the model |
property |
String | The property name of the model |
(private, static) _destroy(instanceName)
Destroy the model reference objects
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
(private, static) _each(instanceName, or)
Executes a callback on each model item for either an array or object literal
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
or |
Array | {String} reference - An array or the internal reference name |
(private, static) _getArrayValueAs(instanceName, name, property, whereProperty, whereValue, valueAs)
Get a specific values from the model
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
valueAs |
Number | The type of response value, Number, String, Boolean |
Returns:
The matched result
(private, static) _getModel(instanceName, name, readOnly)
Get from the model, specify whether data is ready only
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name |
readOnly |
boolean | The readOnly option which will convert the model item using JSON |
Returns:
The model object
(private, static) _getValueAs(instanceName, name, property, whereProperty, whereValue, type)
Get Value As as specific Cast i.e. Number, String, Boolean
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
type |
Number | The type of response value, Number, String, Boolean |
(private, static) _indexOf(instanceName, name, value)
Get the index of a specific value in the Array
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name reference |
value |
* | The value to set at the index |
(private, static) _insertIntoArray(instanceName, data)
Insert data into the required model array, this method only works for array models and not the object literal version which only have a property list, the values of which can be updated with the property method
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
data |
Arguments | List of objects to insert into the array, the first argument should be the model name |
(private, static) _isObject(instanceName, name)
Get the type of model object stored, it's either going to be an array of items or an object literal with properties
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The name of the object to check |
Returns:
Boolean is object result
(private, static) _length(instanceName, name)
Get the selected models length, will only work for an array
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name |
Returns:
The model length
(private, static) _list()
List all the stored models by NAME, TYPE, the model data is not returned in an editable fashion
(private, static) _objProperties(instanceName, name, properties)
Add new properties to the object model or update existing properties, values will be overridden, this method is only if the model stored is an object literal
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The name of the model object |
properties |
Object | The properties to add to the model object |
Returns:
This will return the object property list
(private, static) _objProperty(instanceName, name, prop, value)
Update or return the property of a model object
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The name of the model |
prop |
String | The property name of the model |
value |
* | The value of the property |
Returns:
The matched result
(private, static) _readData(instanceName, name)
Returns the readonly data for the specified model object
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name to return the object for |
(private, static) _remove(instanceName, name, whereProperty, whereValue)
Remove a property from the model, if this is an array it will be the entire index, if an object then the same as clear it removes the property
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model to search |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
(private, static) _search(instanceName, name, values, strict, readOnly)
Search for items in a specific array model
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model to search |
values |
String | The key value pairs to search against |
strict |
String | Boolean to define whether the search is strict or a Regex match |
readOnly |
Object | The identifier value to compare against |
Returns:
The matched results
(private, static) _setData(instanceName, name, {Array})
Set the required data as a direct object set
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The key reference for the model |
{Array} |
Object | data - The data for the model, either and object or and array |
(private, static) _setModel(instanceName, asObject, name)
Create a new model instance
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
asObject |
boolean | Define whether the model is an array or an object literal |
name |
String | The key reference for the model will default to this.NAME if no value is supplied |
Returns:
This will return a boolean to signify if the model was created
(private, static) _sort(instanceName, or, type, property)
Sort an array of items
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
or |
Array | {String} reference - The array of items to sort or the name reference of the internal model data |
type |
String | The sort direction either ASC or DESC |
property |
String | The property name to sort the array by |
Returns:
The sorted array
(private, static) _sortComplex(type, property)
Order the elements
Parameters:
Name | Type | Description |
---|---|---|
type |
String | The sort direction either ASC or DESC |
property |
String | The property name to order the array by |
(private, static) _sortSimple(array, type)
Order the elements
Parameters:
Name | Type | Description |
---|---|---|
array |
String | The property name to order the array by |
type |
String | The sort direction either ASC or DESC |
(private, static) _splice(instanceName, name, index)
Remove a property from the model, if this is an array it will be the entire index, if an object then the same as clear it removes the property
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model to search |
index |
String | The index to remove from the array |
(private, static) _updateArrayIndexProperty(instanceName, name, property, value, whereProperty, whereValue)
Updates an row in the array with the new property values
Parameters:
Name | Type | Description |
---|---|---|
instanceName |
String | The name of the aim.model instance reference |
name |
String | The model name to update the data for |
property |
String | The field type to change the value of |
value |
* | The new data for the property |
whereProperty |
String | The where property clause field name |
whereValue |
* | The value for the where clause property |
(static) asBoolean(name, property, whereProperty, whereValue, type)
Get Value as Boolean
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
type |
Number | The type of response value, Number, String, Boolean |
Returns:
This will return the request value if it exists as a boolean value
(static) asNumber(name, property, whereProperty, whereValue, type)
Get Value as Number
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
type |
Number | The type of response value, Number, String, Boolean |
Returns:
This will return the request value if it exists as a number value
(static) asString(name, property, whereProperty, whereValue, type)
Get Value as String
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
type |
Number | The type of response value, Number, String, Boolean |
Returns:
This will return the request value if it exists as a string value
(static) clean(or, property, overwrite)
Clean - removes duplicates from a given array
Parameters:
Name | Type | Description |
---|---|---|
or |
Array | {String} reference - The array of items to sort or the name reference of the internal model data |
property |
String | The property name to sort the array by |
overwrite |
Boolean | Determines whether the model stored should be overwritten |
Returns:
Returns the cleaned array with no duplicate values
(static) clear(name, property)
Clear a property from the model object, this will effectively delete all references to a specific property name in either an Array or Object literal model type
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the model |
property |
String | The property name of the model |
(static) construct()
Override the construct method
(static) create(asObject, name)
Create a new model instance
Parameters:
Name | Type | Description |
---|---|---|
asObject |
boolean | Define whether the model is an array or an object literal |
name |
String | The key reference for the model will default to this.NAME if no value is supplied |
Returns:
This will return a boolean to signify if the model was created
(static) destroy()
Destroys the model instance, clears all data an destroys the object
(static) each(or)
Executes a callback on each model item for either an array or object literal
Parameters:
Name | Type | Description |
---|---|---|
or |
Array | {String} reference - An array or the internal reference name |
(static) index(name, index, value)
Updates an array index with a completely new value, Returns the value of a modal array index
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model name to update the data for |
index |
Number | The index id for the array |
value |
* | The new data for the property |
Returns:
This will return the value at the specified index if any
(static) indexOf(name, value)
Get the index of a specific value in the Array
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model name reference |
value |
* | The value to set at the index |
Returns:
This will return the index of the value specified
(static) insert(data)
Insert data into the required model array, this method only works for array models and not the object literal version which only have a property list, the values of which can be updated with the property method
Parameters:
Name | Type | Description |
---|---|---|
data |
Arguments | List of objects to insert into the array, the first argument should be the model name |
(static) length(name)
Get the selected models length, will only work for an array
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model name |
Returns:
The model length
(static) list()
List all the stored models by NAME, TYPE, the model data is not returned in an editable fashion
Returns:
Returns an array of model names with the related type Object or Array
(static) properties(name, properties)
Add new properties to the object model or update existing properties, values will be overridden, this method is only if the model stored is an object literal
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the model object |
properties |
Object | The properties to add to the model object |
Returns:
This will return the object property list
(static) property(name, prop, value)
Update or return the property of a model object
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the model |
prop |
String | The property name of the model |
value |
* | The value of the property |
Returns:
This will return the matched result
(static) readData(name)
Returns the readonly data for the specified model object
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model name to return the object for |
Returns:
This will return the model data in a readOnly state
(static) remove(name, whereProperty, whereValue)
Remove a property from the model, if this is an array it will be the entire index, if an object then the same as clear it removes the property
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
(static) search(name, values, strict, readOnly)
Search for items in a specific array model
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
values |
String | The key value pairs to search against |
strict |
String | Boolean to define whether the search is strict or a Regex match |
readOnly |
Object | The identifier value to compare against |
Returns:
This will return the matched results
(static) setData(name, {Array})
Set the required data as a direct object set
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The key reference for the model |
{Array} |
Object | data - The data for the model, either and object or and array |
(static) sort(or, type, property)
Sort an array of items
Parameters:
Name | Type | Description |
---|---|---|
or |
Array | {String} reference - The array of items to sort or the name reference of the internal model data |
type |
String | The sort direction either ASC or DESC |
property |
String | The property name to sort the array by |
Returns:
This will return the sorted array
(static) splice(name, index)
Remove a property from the model, if this is an array it will be the entire index, if an object then the same as clear it removes the property
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
index |
String | The index to remove from the array |
(static) update(name, property, value, whereProperty, whereValue)
Updates an row in the array with the new property values
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model name to update the data for |
property |
String | The field type to change the value of |
value |
* | The new data for the property |
whereProperty |
String | The where property clause field name |
whereValue |
* | The value for the where clause property |
(static) value(name, property, whereProperty, whereValue, type)
Get Value As as specific Cast i.e. Number, String, Boolean
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The model to search |
property |
String | The property value to retrieve |
whereProperty |
String | The identifier property to compare against |
whereValue |
Object | The identifier value to compare against |
type |
Number | The type of response value, Number, String, Boolean |
Returns:
This will return the request value if it exists