|
|
@ -486,8 +486,10 @@ class Dataset {
|
|
|
|
let state = this.state;
|
|
|
|
let state = this.state;
|
|
|
|
this._byKeys = {};
|
|
|
|
this._byKeys = {};
|
|
|
|
this._current = null;
|
|
|
|
this._current = null;
|
|
|
|
|
|
|
|
|
|
|
|
let data = this._getDataItems(obj = obj || {});
|
|
|
|
obj = obj || {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = this._getDataItems(obj);
|
|
|
|
this._items = data.items;
|
|
|
|
this._items = data.items;
|
|
|
|
this._byKeys = data.byKeys;
|
|
|
|
this._byKeys = data.byKeys;
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -510,6 +512,7 @@ class Dataset {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_getDataItems(obj) {
|
|
|
|
_getDataItems(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))
|
|
|
|
throw new Error("The data must be an array");
|
|
|
|
throw new Error("The data must be an array");
|
|
|
@ -544,13 +547,15 @@ class Dataset {
|
|
|
|
return this.setData(obj);
|
|
|
|
return this.setData(obj);
|
|
|
|
|
|
|
|
|
|
|
|
let state = this.state;
|
|
|
|
let state = this.state;
|
|
|
|
let data = this._getDataItems(obj = obj || {});
|
|
|
|
let data = this._getDataItems(obj);
|
|
|
|
this._items = this._items.concat(data.items);
|
|
|
|
this._items = this._items.concat(data.items);
|
|
|
|
this._byKeys = {
|
|
|
|
this._byKeys = {
|
|
|
|
...this._byKeys,
|
|
|
|
...this._byKeys,
|
|
|
|
...data.byKeys
|
|
|
|
...data.byKeys
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj = obj || {}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
@ -1289,9 +1294,6 @@ class DatasetControl {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
download(type) {
|
|
|
|
download(type) {
|
|
|
|
if (!this.query.pageNum)
|
|
|
|
|
|
|
|
this.query.pageNum = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.query.download = type || "xls";
|
|
|
|
this.query.download = type || "xls";
|
|
|
|
let query = toQuery(this.query);
|
|
|
|
let query = toQuery(this.query);
|
|
|
|
this.query.download = null;
|
|
|
|
this.query.download = null;
|
|
|
@ -1415,4 +1417,39 @@ class DatasetControl {
|
|
|
|
if (resp.saved)
|
|
|
|
if (resp.saved)
|
|
|
|
this._load();
|
|
|
|
this._load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindInputs(obj, selector) {
|
|
|
|
|
|
|
|
let inputs = ["input", "select", "textarea"].map(tag => selector + " " + tag).join(","),
|
|
|
|
|
|
|
|
setChanged = evt => {
|
|
|
|
|
|
|
|
let input = evt.target,
|
|
|
|
|
|
|
|
name = input.getAttribute("data-map"),
|
|
|
|
|
|
|
|
val = input.value;
|
|
|
|
|
|
|
|
this.setValue(name, val);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelectorAll(inputs).forEach(input => {
|
|
|
|
|
|
|
|
let prop = input.getAttribute("data-map")
|
|
|
|
|
|
|
|
|| input.name
|
|
|
|
|
|
|
|
|| input.id;
|
|
|
|
|
|
|
|
if (!prop) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input.removeEventListener("change", setChanged);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dataItem = obj instanceof DataItem,
|
|
|
|
|
|
|
|
value = dataItem ? obj.getValue(prop) : obj[prop],
|
|
|
|
|
|
|
|
inputType = (input.type || input.tagName || "").toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
|
|
|
case "radio": input.checked = value && value == input.value; break;
|
|
|
|
|
|
|
|
case "checkbox": input.checked = value && value == input.value; break;
|
|
|
|
|
|
|
|
case "select":
|
|
|
|
|
|
|
|
for(let option of input.options) {
|
|
|
|
|
|
|
|
option.selected = option.value == value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: input.value = ifEmpty(value, ""); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
input.addEventListener("change", setChanged);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|