|
@ -129,7 +129,7 @@ util.extend = function (a, b) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast an object to another type |
|
|
|
|
|
|
|
|
* Convert an object to another type |
|
|
* @param {Boolean | Number | String | Date | Moment | Null | undefined} object |
|
|
* @param {Boolean | Number | String | Date | Moment | Null | undefined} object |
|
|
* @param {String | undefined} type Name of the type. Available types: |
|
|
* @param {String | undefined} type Name of the type. Available types: |
|
|
* 'Boolean', 'Number', 'String', |
|
|
* 'Boolean', 'Number', 'String', |
|
@ -137,7 +137,7 @@ util.extend = function (a, b) { |
|
|
* @return {*} object |
|
|
* @return {*} object |
|
|
* @throws Error |
|
|
* @throws Error |
|
|
*/ |
|
|
*/ |
|
|
util.cast = function cast(object, type) { |
|
|
|
|
|
|
|
|
util.convert = function convert(object, type) { |
|
|
var match; |
|
|
var match; |
|
|
|
|
|
|
|
|
if (object === undefined) { |
|
|
if (object === undefined) { |
|
@ -190,7 +190,7 @@ util.cast = function cast(object, type) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
throw new Error( |
|
|
throw new Error( |
|
|
'Cannot cast object of type ' + util.getType(object) + |
|
|
|
|
|
|
|
|
'Cannot convert object of type ' + util.getType(object) + |
|
|
' to type Date'); |
|
|
' to type Date'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -216,7 +216,7 @@ util.cast = function cast(object, type) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
throw new Error( |
|
|
throw new Error( |
|
|
'Cannot cast object of type ' + util.getType(object) + |
|
|
|
|
|
|
|
|
'Cannot convert object of type ' + util.getType(object) + |
|
|
' to type Date'); |
|
|
' to type Date'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -242,7 +242,7 @@ util.cast = function cast(object, type) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
throw new Error( |
|
|
throw new Error( |
|
|
'Cannot cast object of type ' + util.getType(object) + |
|
|
|
|
|
|
|
|
'Cannot convert object of type ' + util.getType(object) + |
|
|
' to type ISODate'); |
|
|
' to type ISODate'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -267,12 +267,12 @@ util.cast = function cast(object, type) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
throw new Error( |
|
|
throw new Error( |
|
|
'Cannot cast object of type ' + util.getType(object) + |
|
|
|
|
|
|
|
|
'Cannot convert object of type ' + util.getType(object) + |
|
|
' to type ASPDate'); |
|
|
' to type ASPDate'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
throw new Error('Cannot cast object of type ' + util.getType(object) + |
|
|
|
|
|
|
|
|
throw new Error('Cannot convert object of type ' + util.getType(object) + |
|
|
' to type "' + type + '"'); |
|
|
' to type "' + type + '"'); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -599,7 +599,7 @@ util.preventDefault = function preventDefault (event) { |
|
|
util.option = {}; |
|
|
util.option = {}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast a value as boolean |
|
|
|
|
|
|
|
|
* Convert a value into a boolean |
|
|
* @param {Boolean | function | undefined} value |
|
|
* @param {Boolean | function | undefined} value |
|
|
* @param {Boolean} [defaultValue] |
|
|
* @param {Boolean} [defaultValue] |
|
|
* @returns {Boolean} bool |
|
|
* @returns {Boolean} bool |
|
@ -617,7 +617,7 @@ util.option.asBoolean = function (value, defaultValue) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast a value as number |
|
|
|
|
|
|
|
|
* Convert a value into a number |
|
|
* @param {Boolean | function | undefined} value |
|
|
* @param {Boolean | function | undefined} value |
|
|
* @param {Number} [defaultValue] |
|
|
* @param {Number} [defaultValue] |
|
|
* @returns {Number} number |
|
|
* @returns {Number} number |
|
@ -635,7 +635,7 @@ util.option.asNumber = function (value, defaultValue) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast a value as string |
|
|
|
|
|
|
|
|
* Convert a value into a string |
|
|
* @param {String | function | undefined} value |
|
|
* @param {String | function | undefined} value |
|
|
* @param {String} [defaultValue] |
|
|
* @param {String} [defaultValue] |
|
|
* @returns {String} str |
|
|
* @returns {String} str |
|
@ -653,7 +653,7 @@ util.option.asString = function (value, defaultValue) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast a size or location in pixels or a percentage |
|
|
|
|
|
|
|
|
* Convert a size or location into a string with pixels or a percentage |
|
|
* @param {String | Number | function | undefined} value |
|
|
* @param {String | Number | function | undefined} value |
|
|
* @param {String} [defaultValue] |
|
|
* @param {String} [defaultValue] |
|
|
* @returns {String} size |
|
|
* @returns {String} size |
|
@ -675,7 +675,7 @@ util.option.asSize = function (value, defaultValue) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Cast a value as DOM element |
|
|
|
|
|
|
|
|
* Convert a value into a DOM element |
|
|
* @param {HTMLElement | function | undefined} value |
|
|
* @param {HTMLElement | function | undefined} value |
|
|
* @param {HTMLElement} [defaultValue] |
|
|
* @param {HTMLElement} [defaultValue] |
|
|
* @returns {HTMLElement | null} dom |
|
|
* @returns {HTMLElement | null} dom |
|
@ -1157,7 +1157,7 @@ EventBus.prototype.emit = function (event, data, source) { |
|
|
* Usage: |
|
|
* Usage: |
|
|
* var dataSet = new DataSet({ |
|
|
* var dataSet = new DataSet({ |
|
|
* fieldId: '_id', |
|
|
* fieldId: '_id', |
|
|
* fieldTypes: { |
|
|
|
|
|
|
|
|
* convert: { |
|
|
* // ...
|
|
|
* // ...
|
|
|
* } |
|
|
* } |
|
|
* }); |
|
|
* }); |
|
@ -1182,7 +1182,7 @@ EventBus.prototype.emit = function (event, data, source) { |
|
|
* @param {Object} [options] Available options: |
|
|
* @param {Object} [options] Available options: |
|
|
* {String} fieldId Field name of the id in the |
|
|
* {String} fieldId Field name of the id in the |
|
|
* items, 'id' by default. |
|
|
* items, 'id' by default. |
|
|
* {Object.<String, String} fieldTypes |
|
|
|
|
|
|
|
|
* {Object.<String, String} convert |
|
|
* A map with field names as key, |
|
|
* A map with field names as key, |
|
|
* and the field type as value. |
|
|
* and the field type as value. |
|
|
* @constructor DataSet |
|
|
* @constructor DataSet |
|
@ -1194,17 +1194,17 @@ function DataSet (options) { |
|
|
this.options = options || {}; |
|
|
this.options = options || {}; |
|
|
this.data = {}; // map with data indexed by id
|
|
|
this.data = {}; // map with data indexed by id
|
|
|
this.fieldId = this.options.fieldId || 'id'; // name of the field containing id
|
|
|
this.fieldId = this.options.fieldId || 'id'; // name of the field containing id
|
|
|
this.fieldTypes = {}; // field types by field name
|
|
|
|
|
|
|
|
|
this.convert = {}; // field types by field name
|
|
|
|
|
|
|
|
|
if (this.options.fieldTypes) { |
|
|
|
|
|
for (var field in this.options.fieldTypes) { |
|
|
|
|
|
if (this.options.fieldTypes.hasOwnProperty(field)) { |
|
|
|
|
|
var value = this.options.fieldTypes[field]; |
|
|
|
|
|
|
|
|
if (this.options.convert) { |
|
|
|
|
|
for (var field in this.options.convert) { |
|
|
|
|
|
if (this.options.convert.hasOwnProperty(field)) { |
|
|
|
|
|
var value = this.options.convert[field]; |
|
|
if (value == 'Date' || value == 'ISODate' || value == 'ASPDate') { |
|
|
if (value == 'Date' || value == 'ISODate' || value == 'ASPDate') { |
|
|
this.fieldTypes[field] = 'Date'; |
|
|
|
|
|
|
|
|
this.convert[field] = 'Date'; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
this.fieldTypes[field] = value; |
|
|
|
|
|
|
|
|
this.convert[field] = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1415,7 +1415,7 @@ DataSet.prototype.update = function (data, senderId) { |
|
|
* {Object} options An Object with options. Available options: |
|
|
* {Object} options An Object with options. Available options: |
|
|
* {String} [type] Type of data to be returned. Can |
|
|
* {String} [type] Type of data to be returned. Can |
|
|
* be 'DataTable' or 'Array' (default) |
|
|
* be 'DataTable' or 'Array' (default) |
|
|
* {Object.<String, String>} [fieldTypes] |
|
|
|
|
|
|
|
|
* {Object.<String, String>} [convert] |
|
|
* {String[]} [fields] field names to be returned |
|
|
* {String[]} [fields] field names to be returned |
|
|
* {function} [filter] filter items |
|
|
* {function} [filter] filter items |
|
|
* {String | function} [order] Order the items by |
|
|
* {String | function} [order] Order the items by |
|
@ -1472,14 +1472,14 @@ DataSet.prototype.get = function (args) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// build options
|
|
|
// build options
|
|
|
var fieldTypes = options && options.fieldTypes || this.options.fieldTypes; |
|
|
|
|
|
|
|
|
var convert = options && options.convert || this.options.convert; |
|
|
var filter = options && options.filter; |
|
|
var filter = options && options.filter; |
|
|
var items = [], item, itemId, i, len; |
|
|
var items = [], item, itemId, i, len; |
|
|
|
|
|
|
|
|
// cast items
|
|
|
|
|
|
|
|
|
// convert items
|
|
|
if (id != undefined) { |
|
|
if (id != undefined) { |
|
|
// return a single item
|
|
|
// return a single item
|
|
|
item = me._getItem(id, fieldTypes); |
|
|
|
|
|
|
|
|
item = me._getItem(id, convert); |
|
|
if (filter && !filter(item)) { |
|
|
if (filter && !filter(item)) { |
|
|
item = null; |
|
|
item = null; |
|
|
} |
|
|
} |
|
@ -1487,7 +1487,7 @@ DataSet.prototype.get = function (args) { |
|
|
else if (ids != undefined) { |
|
|
else if (ids != undefined) { |
|
|
// return a subset of items
|
|
|
// return a subset of items
|
|
|
for (i = 0, len = ids.length; i < len; i++) { |
|
|
for (i = 0, len = ids.length; i < len; i++) { |
|
|
item = me._getItem(ids[i], fieldTypes); |
|
|
|
|
|
|
|
|
item = me._getItem(ids[i], convert); |
|
|
if (!filter || filter(item)) { |
|
|
if (!filter || filter(item)) { |
|
|
items.push(item); |
|
|
items.push(item); |
|
|
} |
|
|
} |
|
@ -1497,7 +1497,7 @@ DataSet.prototype.get = function (args) { |
|
|
// return all items
|
|
|
// return all items
|
|
|
for (itemId in this.data) { |
|
|
for (itemId in this.data) { |
|
|
if (this.data.hasOwnProperty(itemId)) { |
|
|
if (this.data.hasOwnProperty(itemId)) { |
|
|
item = me._getItem(itemId, fieldTypes); |
|
|
|
|
|
|
|
|
item = me._getItem(itemId, convert); |
|
|
if (!filter || filter(item)) { |
|
|
if (!filter || filter(item)) { |
|
|
items.push(item); |
|
|
items.push(item); |
|
|
} |
|
|
} |
|
@ -1573,7 +1573,7 @@ DataSet.prototype.getIds = function (options) { |
|
|
var data = this.data, |
|
|
var data = this.data, |
|
|
filter = options && options.filter, |
|
|
filter = options && options.filter, |
|
|
order = options && options.order, |
|
|
order = options && options.order, |
|
|
fieldTypes = options && options.fieldTypes || this.options.fieldTypes, |
|
|
|
|
|
|
|
|
convert = options && options.convert || this.options.convert, |
|
|
i, |
|
|
i, |
|
|
len, |
|
|
len, |
|
|
id, |
|
|
id, |
|
@ -1588,7 +1588,7 @@ DataSet.prototype.getIds = function (options) { |
|
|
items = []; |
|
|
items = []; |
|
|
for (id in data) { |
|
|
for (id in data) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
item = this._getItem(id, fieldTypes); |
|
|
|
|
|
|
|
|
item = this._getItem(id, convert); |
|
|
if (filter(item)) { |
|
|
if (filter(item)) { |
|
|
items.push(item); |
|
|
items.push(item); |
|
|
} |
|
|
} |
|
@ -1605,7 +1605,7 @@ DataSet.prototype.getIds = function (options) { |
|
|
// create unordered list
|
|
|
// create unordered list
|
|
|
for (id in data) { |
|
|
for (id in data) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
item = this._getItem(id, fieldTypes); |
|
|
|
|
|
|
|
|
item = this._getItem(id, convert); |
|
|
if (filter(item)) { |
|
|
if (filter(item)) { |
|
|
ids.push(item[this.fieldId]); |
|
|
ids.push(item[this.fieldId]); |
|
|
} |
|
|
} |
|
@ -1649,7 +1649,7 @@ DataSet.prototype.getIds = function (options) { |
|
|
* The order of the items is not determined. |
|
|
* The order of the items is not determined. |
|
|
* @param {function} callback |
|
|
* @param {function} callback |
|
|
* @param {Object} [options] Available options: |
|
|
* @param {Object} [options] Available options: |
|
|
* {Object.<String, String>} [fieldTypes] |
|
|
|
|
|
|
|
|
* {Object.<String, String>} [convert] |
|
|
* {String[]} [fields] filter fields |
|
|
* {String[]} [fields] filter fields |
|
|
* {function} [filter] filter items |
|
|
* {function} [filter] filter items |
|
|
* {String | function} [order] Order the items by |
|
|
* {String | function} [order] Order the items by |
|
@ -1657,7 +1657,7 @@ DataSet.prototype.getIds = function (options) { |
|
|
*/ |
|
|
*/ |
|
|
DataSet.prototype.forEach = function (callback, options) { |
|
|
DataSet.prototype.forEach = function (callback, options) { |
|
|
var filter = options && options.filter, |
|
|
var filter = options && options.filter, |
|
|
fieldTypes = options && options.fieldTypes || this.options.fieldTypes, |
|
|
|
|
|
|
|
|
convert = options && options.convert || this.options.convert, |
|
|
data = this.data, |
|
|
data = this.data, |
|
|
item, |
|
|
item, |
|
|
id; |
|
|
id; |
|
@ -1676,7 +1676,7 @@ DataSet.prototype.forEach = function (callback, options) { |
|
|
// unordered
|
|
|
// unordered
|
|
|
for (id in data) { |
|
|
for (id in data) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
item = this._getItem(id, fieldTypes); |
|
|
|
|
|
|
|
|
item = this._getItem(id, convert); |
|
|
if (!filter || filter(item)) { |
|
|
if (!filter || filter(item)) { |
|
|
callback(item, id); |
|
|
callback(item, id); |
|
|
} |
|
|
} |
|
@ -1689,7 +1689,7 @@ DataSet.prototype.forEach = function (callback, options) { |
|
|
* Map every item in the dataset. |
|
|
* Map every item in the dataset. |
|
|
* @param {function} callback |
|
|
* @param {function} callback |
|
|
* @param {Object} [options] Available options: |
|
|
* @param {Object} [options] Available options: |
|
|
* {Object.<String, String>} [fieldTypes] |
|
|
|
|
|
|
|
|
* {Object.<String, String>} [convert] |
|
|
* {String[]} [fields] filter fields |
|
|
* {String[]} [fields] filter fields |
|
|
* {function} [filter] filter items |
|
|
* {function} [filter] filter items |
|
|
* {String | function} [order] Order the items by |
|
|
* {String | function} [order] Order the items by |
|
@ -1698,15 +1698,15 @@ DataSet.prototype.forEach = function (callback, options) { |
|
|
*/ |
|
|
*/ |
|
|
DataSet.prototype.map = function (callback, options) { |
|
|
DataSet.prototype.map = function (callback, options) { |
|
|
var filter = options && options.filter, |
|
|
var filter = options && options.filter, |
|
|
fieldTypes = options && options.fieldTypes || this.options.fieldTypes, |
|
|
|
|
|
|
|
|
convert = options && options.convert || this.options.convert, |
|
|
mappedItems = [], |
|
|
mappedItems = [], |
|
|
data = this.data, |
|
|
data = this.data, |
|
|
item; |
|
|
item; |
|
|
|
|
|
|
|
|
// cast and filter items
|
|
|
|
|
|
|
|
|
// convert and filter items
|
|
|
for (var id in data) { |
|
|
for (var id in data) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
if (data.hasOwnProperty(id)) { |
|
|
item = this._getItem(id, fieldTypes); |
|
|
|
|
|
|
|
|
item = this._getItem(id, convert); |
|
|
if (!filter || filter(item)) { |
|
|
if (!filter || filter(item)) { |
|
|
mappedItems.push(callback(item, id)); |
|
|
mappedItems.push(callback(item, id)); |
|
|
} |
|
|
} |
|
@ -1900,13 +1900,13 @@ DataSet.prototype.min = function (field) { |
|
|
DataSet.prototype.distinct = function (field) { |
|
|
DataSet.prototype.distinct = function (field) { |
|
|
var data = this.data, |
|
|
var data = this.data, |
|
|
values = [], |
|
|
values = [], |
|
|
fieldType = this.options.fieldTypes[field], |
|
|
|
|
|
|
|
|
fieldType = this.options.convert[field], |
|
|
count = 0; |
|
|
count = 0; |
|
|
|
|
|
|
|
|
for (var prop in data) { |
|
|
for (var prop in data) { |
|
|
if (data.hasOwnProperty(prop)) { |
|
|
if (data.hasOwnProperty(prop)) { |
|
|
var item = data[prop]; |
|
|
var item = data[prop]; |
|
|
var value = util.cast(item[field], fieldType); |
|
|
|
|
|
|
|
|
var value = util.convert(item[field], fieldType); |
|
|
var exists = false; |
|
|
var exists = false; |
|
|
for (var i = 0; i < count; i++) { |
|
|
for (var i = 0; i < count; i++) { |
|
|
if (values[i] == value) { |
|
|
if (values[i] == value) { |
|
@ -1950,8 +1950,8 @@ DataSet.prototype._addItem = function (item) { |
|
|
var d = {}; |
|
|
var d = {}; |
|
|
for (var field in item) { |
|
|
for (var field in item) { |
|
|
if (item.hasOwnProperty(field)) { |
|
|
if (item.hasOwnProperty(field)) { |
|
|
var type = this.fieldTypes[field]; // type may be undefined
|
|
|
|
|
|
d[field] = util.cast(item[field], type); |
|
|
|
|
|
|
|
|
var fieldType = this.convert[field]; // type may be undefined
|
|
|
|
|
|
d[field] = util.convert(item[field], fieldType); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
this.data[id] = d; |
|
|
this.data[id] = d; |
|
@ -1960,13 +1960,13 @@ DataSet.prototype._addItem = function (item) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Get an item. Fields can be casted to a specific type |
|
|
|
|
|
|
|
|
* Get an item. Fields can be converted to a specific type |
|
|
* @param {String} id |
|
|
* @param {String} id |
|
|
* @param {Object.<String, String>} [fieldTypes] Cast field types |
|
|
|
|
|
|
|
|
* @param {Object.<String, String>} [convert] field types to convert |
|
|
* @return {Object | null} item |
|
|
* @return {Object | null} item |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
DataSet.prototype._getItem = function (id, fieldTypes) { |
|
|
|
|
|
|
|
|
DataSet.prototype._getItem = function (id, convert) { |
|
|
var field, value; |
|
|
var field, value; |
|
|
|
|
|
|
|
|
// get the item from the dataset
|
|
|
// get the item from the dataset
|
|
@ -1975,35 +1975,35 @@ DataSet.prototype._getItem = function (id, fieldTypes) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// cast the items field types
|
|
|
|
|
|
var casted = {}, |
|
|
|
|
|
|
|
|
// convert the items field types
|
|
|
|
|
|
var converted = {}, |
|
|
fieldId = this.fieldId, |
|
|
fieldId = this.fieldId, |
|
|
internalIds = this.internalIds; |
|
|
internalIds = this.internalIds; |
|
|
if (fieldTypes) { |
|
|
|
|
|
|
|
|
if (convert) { |
|
|
for (field in raw) { |
|
|
for (field in raw) { |
|
|
if (raw.hasOwnProperty(field)) { |
|
|
if (raw.hasOwnProperty(field)) { |
|
|
value = raw[field]; |
|
|
value = raw[field]; |
|
|
// output all fields, except internal ids
|
|
|
// output all fields, except internal ids
|
|
|
if ((field != fieldId) || !(value in internalIds)) { |
|
|
if ((field != fieldId) || !(value in internalIds)) { |
|
|
casted[field] = util.cast(value, fieldTypes[field]); |
|
|
|
|
|
|
|
|
converted[field] = util.convert(value, convert[field]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// no field types specified, no casting needed
|
|
|
|
|
|
|
|
|
// no field types specified, no converting needed
|
|
|
for (field in raw) { |
|
|
for (field in raw) { |
|
|
if (raw.hasOwnProperty(field)) { |
|
|
if (raw.hasOwnProperty(field)) { |
|
|
value = raw[field]; |
|
|
value = raw[field]; |
|
|
// output all fields, except internal ids
|
|
|
// output all fields, except internal ids
|
|
|
if ((field != fieldId) || !(value in internalIds)) { |
|
|
if ((field != fieldId) || !(value in internalIds)) { |
|
|
casted[field] = value; |
|
|
|
|
|
|
|
|
converted[field] = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return casted; |
|
|
|
|
|
|
|
|
return converted; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -2028,8 +2028,8 @@ DataSet.prototype._updateItem = function (item) { |
|
|
// merge with current item
|
|
|
// merge with current item
|
|
|
for (var field in item) { |
|
|
for (var field in item) { |
|
|
if (item.hasOwnProperty(field)) { |
|
|
if (item.hasOwnProperty(field)) { |
|
|
var type = this.fieldTypes[field]; // type may be undefined
|
|
|
|
|
|
d[field] = util.cast(item[field], type); |
|
|
|
|
|
|
|
|
var fieldType = this.convert[field]; // type may be undefined
|
|
|
|
|
|
d[field] = util.convert(item[field], fieldType); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -2164,7 +2164,7 @@ DataView.prototype.setData = function (data) { |
|
|
* {Object} options An Object with options. Available options: |
|
|
* {Object} options An Object with options. Available options: |
|
|
* {String} [type] Type of data to be returned. Can |
|
|
* {String} [type] Type of data to be returned. Can |
|
|
* be 'DataTable' or 'Array' (default) |
|
|
* be 'DataTable' or 'Array' (default) |
|
|
* {Object.<String, String>} [fieldTypes] |
|
|
|
|
|
|
|
|
* {Object.<String, String>} [convert] |
|
|
* {String[]} [fields] field names to be returned |
|
|
* {String[]} [fields] field names to be returned |
|
|
* {function} [filter] filter items |
|
|
* {function} [filter] filter items |
|
|
* {String | function} [order] Order the items by |
|
|
* {String | function} [order] Order the items by |
|
@ -3130,8 +3130,8 @@ Range.prototype.setRange = function(start, end) { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
Range.prototype._applyRange = function(start, end) { |
|
|
Range.prototype._applyRange = function(start, end) { |
|
|
var newStart = (start != null) ? util.cast(start, 'Number') : this.start; |
|
|
|
|
|
var newEnd = (end != null) ? util.cast(end, 'Number') : this.end; |
|
|
|
|
|
|
|
|
var newStart = (start != null) ? util.convert(start, 'Number') : this.start; |
|
|
|
|
|
var newEnd = (end != null) ? util.convert(end, 'Number') : this.end; |
|
|
var diff; |
|
|
var diff; |
|
|
|
|
|
|
|
|
// check for valid number
|
|
|
// check for valid number
|
|
@ -4648,8 +4648,8 @@ TimeAxis.prototype.reflow = function () { |
|
|
// calculate range and step
|
|
|
// calculate range and step
|
|
|
this._updateConversion(); |
|
|
this._updateConversion(); |
|
|
|
|
|
|
|
|
var start = util.cast(range.start, 'Date'), |
|
|
|
|
|
end = util.cast(range.end, 'Date'), |
|
|
|
|
|
|
|
|
var start = util.convert(range.start, 'Date'), |
|
|
|
|
|
end = util.convert(range.end, 'Date'), |
|
|
minimumStep = this.toTime((props.minorCharWidth || 10) * 5) - this.toTime(0); |
|
|
minimumStep = this.toTime((props.minorCharWidth || 10) * 5) - this.toTime(0); |
|
|
this.step = new TimeStep(start, end, minimumStep); |
|
|
this.step = new TimeStep(start, end, minimumStep); |
|
|
changed += update(props.range, 'start', start.valueOf()); |
|
|
changed += update(props.range, 'start', start.valueOf()); |
|
@ -6354,7 +6354,7 @@ GroupSet.prototype.setGroups = function setGroups(groups) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
this.groupsData = new DataSet({ |
|
|
this.groupsData = new DataSet({ |
|
|
fieldTypes: { |
|
|
|
|
|
|
|
|
convert: { |
|
|
start: 'Date', |
|
|
start: 'Date', |
|
|
end: 'Date' |
|
|
end: 'Date' |
|
|
} |
|
|
} |
|
@ -6871,7 +6871,7 @@ Timeline.prototype.setItems = function(items) { |
|
|
} |
|
|
} |
|
|
if (!(items instanceof DataSet)) { |
|
|
if (!(items instanceof DataSet)) { |
|
|
newItemSet = new DataSet({ |
|
|
newItemSet = new DataSet({ |
|
|
fieldTypes: { |
|
|
|
|
|
|
|
|
convert: { |
|
|
start: 'Date', |
|
|
start: 'Date', |
|
|
end: 'Date' |
|
|
end: 'Date' |
|
|
} |
|
|
} |
|
@ -7352,13 +7352,13 @@ Timeline.prototype.getItemRange = function getItemRange() { |
|
|
next(); |
|
|
next(); |
|
|
} |
|
|
} |
|
|
if (token == 'false') { |
|
|
if (token == 'false') { |
|
|
token = false; // cast to boolean
|
|
|
|
|
|
|
|
|
token = false; // convert to boolean
|
|
|
} |
|
|
} |
|
|
else if (token == 'true') { |
|
|
else if (token == 'true') { |
|
|
token = true; // cast to boolean
|
|
|
|
|
|
|
|
|
token = true; // convert to boolean
|
|
|
} |
|
|
} |
|
|
else if (!isNaN(Number(token))) { |
|
|
else if (!isNaN(Number(token))) { |
|
|
token = Number(token); // cast to number
|
|
|
|
|
|
|
|
|
token = Number(token); // convert to number
|
|
|
} |
|
|
} |
|
|
tokenType = TOKENTYPE.IDENTIFIER; |
|
|
tokenType = TOKENTYPE.IDENTIFIER; |
|
|
return; |
|
|
return; |
|
|