|
|
@ -450,6 +450,10 @@ class Dataset {
|
|
|
|
this._byKeys = {};
|
|
|
|
this._byKeys = {};
|
|
|
|
this._current = null;
|
|
|
|
this._current = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = this._getDataItems(obj);
|
|
|
|
|
|
|
|
this._items = data.items;
|
|
|
|
|
|
|
|
this._byKeys = data.byKeys;
|
|
|
|
|
|
|
|
/*
|
|
|
|
obj = obj || {};
|
|
|
|
obj = obj || {};
|
|
|
|
let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || [];
|
|
|
|
let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || [];
|
|
|
|
if (!Array.isArray(array))
|
|
|
|
if (!Array.isArray(array))
|
|
|
@ -460,12 +464,62 @@ class Dataset {
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
this._byKeys[key] = item;
|
|
|
|
this._byKeys[key] = item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.onDatasetChange(obj);
|
|
|
|
|
|
|
|
this.setState(!Array.isArray(obj) ? obj.state : state);
|
|
|
|
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_getDataItems(obj) {
|
|
|
|
|
|
|
|
obj = obj || {};
|
|
|
|
|
|
|
|
let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || [];
|
|
|
|
|
|
|
|
if (!Array.isArray(array))
|
|
|
|
|
|
|
|
throw new Error("The data must be an array");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let _items = array.map(e => new DataItem(e, this._formats)),
|
|
|
|
|
|
|
|
_byKeys = {};
|
|
|
|
|
|
|
|
_items.forEach(item => {
|
|
|
|
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
|
|
|
|
_byKeys[key] = item;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
items: _items,
|
|
|
|
|
|
|
|
byKeys: _byKeys
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**Adds user data to the Dataset.
|
|
|
|
|
|
|
|
* To get user data from an object, the dataGetter configured is called.
|
|
|
|
|
|
|
|
* After user data is set, the methods
|
|
|
|
|
|
|
|
* <ul> <li>{@link Dataset#onDatasetChange}</li>
|
|
|
|
|
|
|
|
* <li>{@link Dataset#onCurrentChange}</li>
|
|
|
|
|
|
|
|
* <li>{@link Dataset#onSelectionChange}</li>
|
|
|
|
|
|
|
|
* <li>{@link Dataset#onDirtiesChange}</li>
|
|
|
|
|
|
|
|
* </ul>
|
|
|
|
|
|
|
|
* are called back.
|
|
|
|
|
|
|
|
* @param {array|object} obj user data or an object that has user data
|
|
|
|
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
addData(obj) {
|
|
|
|
|
|
|
|
if (this.empty)
|
|
|
|
|
|
|
|
return this.setData(obj);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = this._getDataItems(obj);
|
|
|
|
|
|
|
|
this._items = this._items.concat(data.items);
|
|
|
|
|
|
|
|
this._byKeys = {
|
|
|
|
|
|
|
|
...this._byKeys,
|
|
|
|
|
|
|
|
...data.byKeys
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.onDatasetChange(obj);
|
|
|
|
this.onDatasetChange(obj);
|
|
|
|
this.setState(!Array.isArray(obj) ? obj.state : state);
|
|
|
|
this.setState(!Array.isArray(obj) ? obj.state : state);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**Clears the Dataset's user data.
|
|
|
|
/**Clears the Dataset's user data.
|
|
|
@ -1140,6 +1194,7 @@ class DatasetControl {
|
|
|
|
this.prefix = conf.prefix;
|
|
|
|
this.prefix = conf.prefix;
|
|
|
|
this.prefixName = conf.prefixName;
|
|
|
|
this.prefixName = conf.prefixName;
|
|
|
|
this.infoSize = conf.infoSize;
|
|
|
|
this.infoSize = conf.infoSize;
|
|
|
|
|
|
|
|
this.appendData = conf.appendData;
|
|
|
|
|
|
|
|
|
|
|
|
this.query = {};
|
|
|
|
this.query = {};
|
|
|
|
|
|
|
|
|
|
|
@ -1184,13 +1239,23 @@ class DatasetControl {
|
|
|
|
ajax.get({
|
|
|
|
ajax.get({
|
|
|
|
url:this.urls.load,
|
|
|
|
url:this.urls.load,
|
|
|
|
data:this.query,
|
|
|
|
data:this.query,
|
|
|
|
success:resp => this.setData(resp)
|
|
|
|
success:resp => {
|
|
|
|
|
|
|
|
if (!this.appendData || this.query.pageNum == 1)
|
|
|
|
|
|
|
|
this.setData(resp);
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
this.addData(resp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setData(obj) {
|
|
|
|
setData(obj) {
|
|
|
|
this.dataset.setData(obj);
|
|
|
|
this.dataset.setData(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addData(obj) {
|
|
|
|
|
|
|
|
this.dataset.addData(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onDatasetChange(obj) {
|
|
|
|
onDatasetChange(obj) {
|
|
|
|
debug("onDatasetChange", obj);
|
|
|
|
debug("onDatasetChange", obj);
|
|
|
|