|
|
@ -485,9 +485,10 @@ class Dataset {
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* are called back.
|
|
|
|
* are called back.
|
|
|
|
* @param {array|object} obj user data or an object that has user data
|
|
|
|
* @param {array|object} obj user data or an object that has user data
|
|
|
|
|
|
|
|
* @param {object} obj optional information
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setData(obj) {
|
|
|
|
setData(obj, option) {
|
|
|
|
this._byKeys = {};
|
|
|
|
this._byKeys = {};
|
|
|
|
this._current = null;
|
|
|
|
this._current = null;
|
|
|
|
|
|
|
|
|
|
|
@ -508,7 +509,7 @@ class Dataset {
|
|
|
|
this._byKeys[key] = item;
|
|
|
|
this._byKeys[key] = item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
this.onDatasetChange(obj);
|
|
|
|
this.onDatasetChange(obj, option);
|
|
|
|
this.setState(obj.state);
|
|
|
|
this.setState(obj.state);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
|
|
|
|
|
|
|
@ -544,9 +545,10 @@ class Dataset {
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* are called back.
|
|
|
|
* are called back.
|
|
|
|
* @param {array|object} obj user data or an object that has user data
|
|
|
|
* @param {array|object} obj user data or an object that has user data
|
|
|
|
|
|
|
|
* @param {object} obj optional information
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
addData(obj) {
|
|
|
|
addData(obj, option) {
|
|
|
|
if (this.empty)
|
|
|
|
if (this.empty)
|
|
|
|
return this.setData(obj);
|
|
|
|
return this.setData(obj);
|
|
|
|
|
|
|
|
|
|
|
@ -560,7 +562,7 @@ class Dataset {
|
|
|
|
|
|
|
|
|
|
|
|
obj = obj || {}
|
|
|
|
obj = obj || {}
|
|
|
|
|
|
|
|
|
|
|
|
this.onDatasetChange(obj);
|
|
|
|
this.onDatasetChange(obj, option);
|
|
|
|
this.setState(!Array.isArray(obj) ? obj.state : state);
|
|
|
|
this.setState(!Array.isArray(obj) ? obj.state : state);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
this.onDirtiesChange(this.dirty);
|
|
|
|
|
|
|
|
|
|
|
@ -1203,8 +1205,9 @@ class Dataset {
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data are set.
|
|
|
|
/**Called back when user data are set.
|
|
|
|
* @param {object|array} obj object that has user data or an array of user data
|
|
|
|
* @param {object|array} obj object that has user data or an array of user data
|
|
|
|
|
|
|
|
* @param {object} obj optional information
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onDatasetChange(obj) {this.log("Dataset changed", obj);}
|
|
|
|
onDatasetChange(obj, option) {this.log("Dataset changed", obj, "option", option);}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when current user data is changed.
|
|
|
|
/**Called back when current user data is changed.
|
|
|
|
* @param {DataItem} currentItem current dataItem
|
|
|
|
* @param {DataItem} currentItem current dataItem
|
|
|
@ -1258,7 +1261,7 @@ class DatasetControl {
|
|
|
|
|
|
|
|
|
|
|
|
this.query = {};
|
|
|
|
this.query = {};
|
|
|
|
|
|
|
|
|
|
|
|
conf.onDatasetChange = obj => this.onDatasetChange(obj);
|
|
|
|
conf.onDatasetChange = (obj, option) => this.onDatasetChange(obj, option);
|
|
|
|
conf.onCurrentChange = item => this.onCurrentChange(item);
|
|
|
|
conf.onCurrentChange = item => this.onCurrentChange(item);
|
|
|
|
conf.onSelectionChange = selected => this.onSelectionChange(selected);
|
|
|
|
conf.onSelectionChange = selected => this.onSelectionChange(selected);
|
|
|
|
conf.onAppend = items => this.onAppend(items);
|
|
|
|
conf.onAppend = items => this.onAppend(items);
|
|
|
@ -1297,43 +1300,49 @@ class DatasetControl {
|
|
|
|
this._load();
|
|
|
|
this._load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_load(state, prev, callback) {
|
|
|
|
_load(option) {
|
|
|
|
|
|
|
|
option = option || {};
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.query.pageNum)
|
|
|
|
if (!this.query.pageNum)
|
|
|
|
this.query.pageNum = 1;
|
|
|
|
this.query.pageNum = 1;
|
|
|
|
if (prev)
|
|
|
|
if (option.prev)
|
|
|
|
this.query.pageNum = Math.max(1, this.query.pageNum - 1);
|
|
|
|
this.query.pageNum = Math.max(1, this.query.pageNum - 1);
|
|
|
|
|
|
|
|
|
|
|
|
ajax.get({
|
|
|
|
ajax.get({
|
|
|
|
url:this.urls.load,
|
|
|
|
url:this.urls.load,
|
|
|
|
data:this.query,
|
|
|
|
data:this.query,
|
|
|
|
success:resp => {
|
|
|
|
success:resp => {
|
|
|
|
if (!prev)
|
|
|
|
if (!option.prev)
|
|
|
|
resp.state = state;
|
|
|
|
resp.state = option.state;
|
|
|
|
if (!this.appendData || this.query.pageNum == 1)
|
|
|
|
if (!this.appendData || this.query.pageNum == 1)
|
|
|
|
this.setData(resp);
|
|
|
|
this.setData(resp, option);
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
this.addData(resp);
|
|
|
|
this.addData(resp, option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (callback)
|
|
|
|
if (option.callback)
|
|
|
|
callback();
|
|
|
|
option.callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reload(option) {
|
|
|
|
reload(option) {
|
|
|
|
let all = option ? option.all : false,
|
|
|
|
if (!option)
|
|
|
|
prev = option ? option.prev : false,
|
|
|
|
option = {};
|
|
|
|
|
|
|
|
option.reloaded = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let all = option.all,
|
|
|
|
|
|
|
|
prev = option.prev,
|
|
|
|
state = this.dataset.state;
|
|
|
|
state = this.dataset.state;
|
|
|
|
|
|
|
|
option.state = state;
|
|
|
|
|
|
|
|
|
|
|
|
if (!all) {
|
|
|
|
if (!all) {
|
|
|
|
this._load(state, prev);
|
|
|
|
this._load(option);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let query = Object.assign({}, this.query),
|
|
|
|
let query = Object.assign({}, this.query);
|
|
|
|
state = this.dataset.state;
|
|
|
|
|
|
|
|
this.query.fetchSize = this.dataset.length;
|
|
|
|
this.query.fetchSize = this.dataset.length;
|
|
|
|
this.query.pageNum = 1;
|
|
|
|
this.query.pageNum = 1;
|
|
|
|
this.dataset.clear();
|
|
|
|
option.callback = () => {this.query = query;};
|
|
|
|
this._load(state, prev, () => {this.query = query;});
|
|
|
|
this._load(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1344,16 +1353,16 @@ class DatasetControl {
|
|
|
|
document.location.href = this.urls.load + "?" + query;
|
|
|
|
document.location.href = this.urls.load + "?" + query;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setData(obj) {
|
|
|
|
setData(obj, option) {
|
|
|
|
this.dataset.setData(obj);
|
|
|
|
this.dataset.setData(obj, option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
addData(obj) {
|
|
|
|
addData(obj, option) {
|
|
|
|
this.dataset.addData(obj);
|
|
|
|
this.dataset.addData(obj, option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onDatasetChange(obj) {
|
|
|
|
onDatasetChange(obj, option) {
|
|
|
|
debug("onDatasetChange", obj);
|
|
|
|
debug("onDatasetChange", obj, option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getCurrent(option) {
|
|
|
|
getCurrent(option) {
|
|
|
|