|
|
@ -1,6 +1,6 @@
|
|
|
|
/* Copyright (c) 2020 Emjay Khan. All rights reserved. */
|
|
|
|
/* Copyright (c) 2020 Emjay Khan. All rights reserved. */
|
|
|
|
|
|
|
|
|
|
|
|
/**@file Classes and objects to help control user data in HTML pages
|
|
|
|
/**@file Classes and objects to help control user data in HTML pages
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function lpad(v) {
|
|
|
|
function lpad(v) {
|
|
|
@ -26,7 +26,7 @@ const numberFormat = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**Formats the value
|
|
|
|
/**Formats the value
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @returns {string} formatted value
|
|
|
|
* @returns {string} formatted value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -38,13 +38,13 @@ const numberFormat = {
|
|
|
|
|
|
|
|
|
|
|
|
/** value format for dates */
|
|
|
|
/** value format for dates */
|
|
|
|
const dateFormat = {
|
|
|
|
const dateFormat = {
|
|
|
|
/**Formats the value
|
|
|
|
/**Formats the value
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @returns {string} formatted value
|
|
|
|
* @returns {string} formatted value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
format(value) {
|
|
|
|
format(value) {
|
|
|
|
if (isEmpty(value)) return "";
|
|
|
|
if (isEmpty(value)) return "";
|
|
|
|
|
|
|
|
|
|
|
|
let _format = v => {
|
|
|
|
let _format = v => {
|
|
|
|
let date = "number" == typeof v ? new Date(v) : v;
|
|
|
|
let date = "number" == typeof v ? new Date(v) : v;
|
|
|
|
let year = date.getFullYear(),
|
|
|
|
let year = date.getFullYear(),
|
|
|
@ -52,7 +52,7 @@ const dateFormat = {
|
|
|
|
day = lpad(date.getDate());
|
|
|
|
day = lpad(date.getDate());
|
|
|
|
return year + "-" + month + "-" + day;
|
|
|
|
return year + "-" + month + "-" + day;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
switch (value instanceof Date ? "date" : typeof value) {
|
|
|
|
switch (value instanceof Date ? "date" : typeof value) {
|
|
|
|
case "number":
|
|
|
|
case "number":
|
|
|
|
case "date": return _format(value);
|
|
|
|
case "date": return _format(value);
|
|
|
@ -64,7 +64,7 @@ const dateFormat = {
|
|
|
|
|
|
|
|
|
|
|
|
/** value format for time */
|
|
|
|
/** value format for time */
|
|
|
|
const timeFormat = {
|
|
|
|
const timeFormat = {
|
|
|
|
/**Formats the value
|
|
|
|
/**Formats the value
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @returns {string} formatted value
|
|
|
|
* @returns {string} formatted value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -76,7 +76,7 @@ const timeFormat = {
|
|
|
|
seconds = lpad(date.getSeconds());
|
|
|
|
seconds = lpad(date.getSeconds());
|
|
|
|
return hours + ":" + minutes + ":" + seconds;
|
|
|
|
return hours + ":" + minutes + ":" + seconds;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
switch (value instanceof Date ? "date" : typeof value) {
|
|
|
|
switch (value instanceof Date ? "date" : typeof value) {
|
|
|
|
case "number":
|
|
|
|
case "number":
|
|
|
|
case "date": return _format(value);
|
|
|
|
case "date": return _format(value);
|
|
|
@ -90,7 +90,7 @@ const timeFormat = {
|
|
|
|
|
|
|
|
|
|
|
|
/** value format for datetimes */
|
|
|
|
/** value format for datetimes */
|
|
|
|
const datetimeFormat = {
|
|
|
|
const datetimeFormat = {
|
|
|
|
/**Formats the value
|
|
|
|
/**Formats the value
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @param {number} value value to format
|
|
|
|
* @returns {string} formatted value
|
|
|
|
* @returns {string} formatted value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -114,8 +114,8 @@ const datetimeFormat = {
|
|
|
|
* key0: numberFormat,
|
|
|
|
* key0: numberFormat,
|
|
|
|
* key1: dateFormat,
|
|
|
|
* key1: dateFormat,
|
|
|
|
* key2: {
|
|
|
|
* key2: {
|
|
|
|
* format(value) {...},
|
|
|
|
* format(value) {...},
|
|
|
|
* parse(value) {...}
|
|
|
|
* parse(value) {...}
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* })</code></pre>
|
|
|
|
* })</code></pre>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -137,24 +137,24 @@ class ValueFormat {
|
|
|
|
* <ul> <li>parser associated with the key</li>
|
|
|
|
* <ul> <li>parser associated with the key</li>
|
|
|
|
* <li>if not found for the key, default parser</li>
|
|
|
|
* <li>if not found for the key, default parser</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
parser(key) {
|
|
|
|
parser(key) {
|
|
|
|
let parser = this._formats[key];
|
|
|
|
let parser = this._formats[key];
|
|
|
|
return parser && parser.parse ? parser.parse : ValueFormat.Default.parse;
|
|
|
|
return parser && parser.parse ? parser.parse : ValueFormat.Default.parse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**Returns a formatter associated with the key.
|
|
|
|
/**Returns a formatter associated with the key.
|
|
|
|
* @param {string} key key associated with a value format
|
|
|
|
* @param {string} key key associated with a value format
|
|
|
|
* @returns {function}
|
|
|
|
* @returns {function}
|
|
|
|
* <ul> <li>formatter associated with the key</li>
|
|
|
|
* <ul> <li>formatter associated with the key</li>
|
|
|
|
* <li>if not found for the key, default formatter</li>
|
|
|
|
* <li>if not found for the key, default formatter</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
formatter(key) {
|
|
|
|
formatter(key) {
|
|
|
|
let formatter = this._formats[key];
|
|
|
|
let formatter = this._formats[key];
|
|
|
|
return formatter && formatter.format ? formatter.format : ValueFormat.Default.format;
|
|
|
|
return formatter && formatter.format ? formatter.format : ValueFormat.Default.format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
regexp(key) {
|
|
|
|
regexp(key) {
|
|
|
|
let expr = this._exprs[key];
|
|
|
|
let expr = this._exprs[key];
|
|
|
|
if (!expr)
|
|
|
|
if (!expr)
|
|
|
@ -172,7 +172,7 @@ ValueFormat.Default = {
|
|
|
|
/** Represents an invalid value. */
|
|
|
|
/** Represents an invalid value. */
|
|
|
|
ValueFormat.InvalidValue = "^invalid^value^";
|
|
|
|
ValueFormat.InvalidValue = "^invalid^value^";
|
|
|
|
|
|
|
|
|
|
|
|
/**Wraps a user data and traces the manipulation performed on it and consequent status.
|
|
|
|
/**Wraps a user data and traces the manipulation performed on it and consequent status.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class DataItem {
|
|
|
|
class DataItem {
|
|
|
|
/** user data */
|
|
|
|
/** user data */
|
|
|
@ -183,7 +183,7 @@ class DataItem {
|
|
|
|
selected;
|
|
|
|
selected;
|
|
|
|
/** state of the user data */
|
|
|
|
/** state of the user data */
|
|
|
|
state;
|
|
|
|
state;
|
|
|
|
|
|
|
|
|
|
|
|
/**Creates a new DataItem.
|
|
|
|
/**Creates a new DataItem.
|
|
|
|
* @param {any} data user data
|
|
|
|
* @param {any} data user data
|
|
|
|
* @param {object} formats value formatters of the user data's property
|
|
|
|
* @param {object} formats value formatters of the user data's property
|
|
|
@ -273,7 +273,7 @@ class DataItem {
|
|
|
|
/**Returns a string converted from the template using the property values of the user data.
|
|
|
|
/**Returns a string converted from the template using the property values of the user data.
|
|
|
|
* In the template, placeholder for the properties of the user data is specified like {property name}.
|
|
|
|
* In the template, placeholder for the properties of the user data is specified like {property name}.
|
|
|
|
* @param {string} template template string
|
|
|
|
* @param {string} template template string
|
|
|
|
* @param {function} formatter function to format a row string with custom property placeholders
|
|
|
|
* @param {function} formatter function to format a row string with custom property placeholders
|
|
|
|
* @returns {string} string converted from the template using the property values of the user data
|
|
|
|
* @returns {string} string converted from the template using the property values of the user data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
inString(template, formatter) {
|
|
|
|
inString(template, formatter) {
|
|
|
@ -291,7 +291,7 @@ class DataItem {
|
|
|
|
|
|
|
|
|
|
|
|
/**Manages user data wrapped in {@link DataItem}s, tracing the state after manipulation performed on them.
|
|
|
|
/**Manages user data wrapped in {@link DataItem}s, tracing the state after manipulation performed on them.
|
|
|
|
* <p>For a Dataset to work properly, it needs a keymapper to identify user data.
|
|
|
|
* <p>For a Dataset to work properly, it needs a keymapper to identify user data.
|
|
|
|
* And you specify it in a Dataset's configuration.
|
|
|
|
* And you specify it in a Dataset's configuration.
|
|
|
|
* <pre><code>let dataset = new Dataset({
|
|
|
|
* <pre><code>let dataset = new Dataset({
|
|
|
|
* keymapper: function(info) {return info.keyProperty;},
|
|
|
|
* keymapper: function(info) {return info.keyProperty;},
|
|
|
|
* ...
|
|
|
|
* ...
|
|
|
@ -338,12 +338,12 @@ class Dataset {
|
|
|
|
_items;
|
|
|
|
_items;
|
|
|
|
_byKeys;
|
|
|
|
_byKeys;
|
|
|
|
_current;
|
|
|
|
_current;
|
|
|
|
|
|
|
|
|
|
|
|
/**Dataset configuration
|
|
|
|
/**Dataset configuration
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
conf;
|
|
|
|
conf;
|
|
|
|
_formats;
|
|
|
|
_formats;
|
|
|
|
|
|
|
|
|
|
|
|
/**Creates a new Dataset with a configuration.
|
|
|
|
/**Creates a new Dataset with a configuration.
|
|
|
|
* The configuration is an object with which you specify
|
|
|
|
* The configuration is an object with which you specify
|
|
|
|
* <ul> <li>keymapper - function that returns a key of a user data. Used to identify user data in the Dataset. Mandatory.</li>
|
|
|
|
* <ul> <li>keymapper - function that returns a key of a user data. Used to identify user data in the Dataset. Mandatory.</li>
|
|
|
@ -359,21 +359,21 @@ class Dataset {
|
|
|
|
* <li>{@link Dataset#onRemove onRemove}</li>
|
|
|
|
* <li>{@link Dataset#onRemove onRemove}</li>
|
|
|
|
* <li>{@link Dataset#onErase onErase}</li>
|
|
|
|
* <li>{@link Dataset#onErase onErase}</li>
|
|
|
|
* <li>{@link Dataset#onDirtiesChange onDirtiesChange}</li>
|
|
|
|
* <li>{@link Dataset#onDirtiesChange onDirtiesChange}</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </li>
|
|
|
|
* <li>trace - true to enable message logging</li>
|
|
|
|
* <li>trace - true to enable message logging</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* @param conf {object} configuration
|
|
|
|
* @param conf {object} configuration
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
constructor(conf) {
|
|
|
|
constructor(conf) {
|
|
|
|
this._items = [];
|
|
|
|
this._items = [];
|
|
|
|
this._byKeys = {};
|
|
|
|
this._byKeys = {};
|
|
|
|
this._current = null;
|
|
|
|
this._current = null;
|
|
|
|
|
|
|
|
|
|
|
|
this.conf = notEmpty(conf, "conf is required but missing");
|
|
|
|
this.conf = notEmpty(conf, "conf is required but missing");
|
|
|
|
notEmpty(conf.keymapper, "keymapper is required but missing");
|
|
|
|
notEmpty(conf.keymapper, "keymapper is required but missing");
|
|
|
|
this._formats = new ValueFormat(conf.formats);
|
|
|
|
this._formats = new ValueFormat(conf.formats);
|
|
|
|
|
|
|
|
|
|
|
|
if (!conf.trace)
|
|
|
|
if (!conf.trace)
|
|
|
|
this.log = () => {};
|
|
|
|
this.log = () => {};
|
|
|
|
|
|
|
|
|
|
|
@ -428,12 +428,12 @@ class Dataset {
|
|
|
|
* let added = dirties.added;
|
|
|
|
* let added = dirties.added;
|
|
|
|
* let modified = dirties.modified;
|
|
|
|
* let modified = dirties.modified;
|
|
|
|
* let removed = dirties.removed;
|
|
|
|
* let removed = dirties.removed;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getKeys(status){
|
|
|
|
getKeys(status){
|
|
|
|
let dataset = this.getDataset(status);
|
|
|
|
let dataset = this.getDataset(status);
|
|
|
|
if ("dirty" != status)
|
|
|
|
if ("dirty" != status)
|
|
|
|
return dataset.map(e => this.getKey(e));
|
|
|
|
return dataset.map(e => this.getKey(e));
|
|
|
|
|
|
|
|
|
|
|
|
let result = {};
|
|
|
|
let result = {};
|
|
|
|
for (let prop in dataset) {
|
|
|
|
for (let prop in dataset) {
|
|
|
|
result[prop] = dataset[prop].map(e => this.getKey(e));
|
|
|
|
result[prop] = dataset[prop].map(e => this.getKey(e));
|
|
|
@ -474,7 +474,7 @@ 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 || {});
|
|
|
|
let data = this._getDataItems(obj = obj || {});
|
|
|
|
this._items = data.items;
|
|
|
|
this._items = data.items;
|
|
|
|
this._byKeys = data.byKeys;
|
|
|
|
this._byKeys = data.byKeys;
|
|
|
@ -483,7 +483,7 @@ class Dataset {
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
this._items = array.map(e => new DataItem(e, this._formats));
|
|
|
|
this._items = array.map(e => new DataItem(e, this._formats));
|
|
|
|
this._items.forEach(item => {
|
|
|
|
this._items.forEach(item => {
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
@ -493,28 +493,28 @@ class Dataset {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_getDataItems(obj) {
|
|
|
|
_getDataItems(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");
|
|
|
|
|
|
|
|
|
|
|
|
let _items = array.map(e => new DataItem(e, this._formats)),
|
|
|
|
let _items = array.map(e => new DataItem(e, this._formats)),
|
|
|
|
_byKeys = {};
|
|
|
|
_byKeys = {};
|
|
|
|
_items.forEach(item => {
|
|
|
|
_items.forEach(item => {
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
let key = "key-" + this.getKey(item.data);
|
|
|
|
_byKeys[key] = item;
|
|
|
|
_byKeys[key] = item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
items: _items,
|
|
|
|
items: _items,
|
|
|
|
byKeys: _byKeys
|
|
|
|
byKeys: _byKeys
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**Adds user data to the Dataset.
|
|
|
|
/**Adds user data to the Dataset.
|
|
|
|
* To get user data from an object, the dataGetter configured is called.
|
|
|
|
* To get user data from an object, the dataGetter configured is called.
|
|
|
|
* After user data is set, the methods
|
|
|
|
* After user data is set, the methods
|
|
|
@ -530,7 +530,7 @@ class Dataset {
|
|
|
|
addData(obj) {
|
|
|
|
addData(obj) {
|
|
|
|
if (this.empty)
|
|
|
|
if (this.empty)
|
|
|
|
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 = obj || {});
|
|
|
|
this._items = this._items.concat(data.items);
|
|
|
|
this._items = this._items.concat(data.items);
|
|
|
@ -538,17 +538,17 @@ class Dataset {
|
|
|
|
...this._byKeys,
|
|
|
|
...this._byKeys,
|
|
|
|
...data.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.
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
clear() {
|
|
|
|
clear() {
|
|
|
|
this.setData(null);
|
|
|
|
this.setData(null);
|
|
|
@ -588,7 +588,7 @@ class Dataset {
|
|
|
|
|
|
|
|
|
|
|
|
/**Sets the user data as current that is associated with the key.
|
|
|
|
/**Sets the user data as current that is associated with the key.
|
|
|
|
* @param {string} key key to a user data
|
|
|
|
* @param {string} key key to a user data
|
|
|
|
* After the data is set, the method
|
|
|
|
* After the data is set, the method
|
|
|
|
* <ul> <li>{@link Dataset#onCurrentChange}</li>
|
|
|
|
* <ul> <li>{@link Dataset#onCurrentChange}</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* is called back.
|
|
|
|
* is called back.
|
|
|
@ -621,7 +621,7 @@ class Dataset {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**Sets the state to the Dataset.
|
|
|
|
/**Sets the state to the Dataset.
|
|
|
|
* After the state is set, the methods
|
|
|
|
* After the state is set, the methods
|
|
|
|
* <ul> <li>{@link Dataset#onCurrentChange}</li>
|
|
|
|
* <ul> <li>{@link Dataset#onCurrentChange}</li>
|
|
|
|
* <li>{@link Dataset#onSelectionChange}</li>
|
|
|
|
* <li>{@link Dataset#onSelectionChange}</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
@ -719,7 +719,7 @@ class Dataset {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ("item" == option)
|
|
|
|
if ("item" == option)
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
let getData = item => item.data;
|
|
|
|
let getData = item => item.data;
|
|
|
|
if ("dirty" != status)
|
|
|
|
if ("dirty" != status)
|
|
|
|
return "item" == option ? result : result.map(e => getData(e));
|
|
|
|
return "item" == option ? result : result.map(e => getData(e));
|
|
|
@ -818,13 +818,13 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
append(data) {
|
|
|
|
append(data) {
|
|
|
|
if (!data) return this;
|
|
|
|
if (!data) return this;
|
|
|
|
|
|
|
|
|
|
|
|
let notDirty = !this.dirty,
|
|
|
|
let notDirty = !this.dirty,
|
|
|
|
array = Array.isArray(data) ? data : [data];
|
|
|
|
array = Array.isArray(data) ? data : [data];
|
|
|
|
array.forEach(e => {
|
|
|
|
array.forEach(e => {
|
|
|
|
let item = new DataItem(e, this._formats);
|
|
|
|
let item = new DataItem(e, this._formats);
|
|
|
|
this._items.push(item);
|
|
|
|
this._items.push(item);
|
|
|
|
|
|
|
|
|
|
|
|
let key = this.getKey(e);
|
|
|
|
let key = this.getKey(e);
|
|
|
|
this._byKeys["key-" + key] = item;
|
|
|
|
this._byKeys["key-" + key] = item;
|
|
|
|
item.state = "added";
|
|
|
|
item.state = "added";
|
|
|
@ -834,10 +834,10 @@ class Dataset {
|
|
|
|
this.onAppend(array);
|
|
|
|
this.onAppend(array);
|
|
|
|
state.currentKey = this.getKey(array[array.length - 1]);
|
|
|
|
state.currentKey = this.getKey(array[array.length - 1]);
|
|
|
|
this.setState(state);
|
|
|
|
this.setState(state);
|
|
|
|
|
|
|
|
|
|
|
|
if (notDirty)
|
|
|
|
if (notDirty)
|
|
|
|
this.onDirtiesChange(true);
|
|
|
|
this.onDirtiesChange(true);
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -865,11 +865,11 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
modify(key, modifier) {
|
|
|
|
modify(key, modifier) {
|
|
|
|
if (!modifier) return this;
|
|
|
|
if (!modifier) return this;
|
|
|
|
|
|
|
|
|
|
|
|
let item = this.getData(key, "item");
|
|
|
|
let item = this.getData(key, "item");
|
|
|
|
if (!item)
|
|
|
|
if (!item)
|
|
|
|
return log("Item not found with " + key);
|
|
|
|
return log("Item not found with " + key);
|
|
|
|
|
|
|
|
|
|
|
|
let notDirty = !this.dirty,
|
|
|
|
let notDirty = !this.dirty,
|
|
|
|
data = item.data,
|
|
|
|
data = item.data,
|
|
|
|
prev = Object.assign({}, data),
|
|
|
|
prev = Object.assign({}, data),
|
|
|
@ -883,11 +883,11 @@ class Dataset {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
return changed;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let current = data == this.getCurrent(),
|
|
|
|
let current = data == this.getCurrent(),
|
|
|
|
revert = modifier(item) == ValueFormat.InvalidValue,
|
|
|
|
revert = modifier(item) == ValueFormat.InvalidValue,
|
|
|
|
changed = modifiedProps(prev, data);
|
|
|
|
changed = modifiedProps(prev, data);
|
|
|
|
|
|
|
|
|
|
|
|
if (changed.length > 0) {
|
|
|
|
if (changed.length > 0) {
|
|
|
|
if (!item.state)
|
|
|
|
if (!item.state)
|
|
|
|
item.state = "modified";
|
|
|
|
item.state = "modified";
|
|
|
@ -931,30 +931,30 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
replace(replacement) {
|
|
|
|
replace(replacement) {
|
|
|
|
if (isEmpty(replacement)) return this;
|
|
|
|
if (isEmpty(replacement)) return this;
|
|
|
|
|
|
|
|
|
|
|
|
let before = this.dirty,
|
|
|
|
let before = this.dirty,
|
|
|
|
replacements = Array.isArray(replacement) ? replacement : [replacement],
|
|
|
|
replacements = Array.isArray(replacement) ? replacement : [replacement],
|
|
|
|
replacing = [];
|
|
|
|
replacing = [];
|
|
|
|
replacements.forEach(obj => {
|
|
|
|
replacements.forEach(obj => {
|
|
|
|
let data = obj.data;
|
|
|
|
let data = obj.data;
|
|
|
|
if (!data) return;
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
|
|
|
|
let key = obj.key || this.getKey(data);
|
|
|
|
let key = obj.key || this.getKey(data);
|
|
|
|
if (!key) return;
|
|
|
|
if (!key) return;
|
|
|
|
|
|
|
|
|
|
|
|
let oldItem = this.getData(key, "item"),
|
|
|
|
let oldItem = this.getData(key, "item"),
|
|
|
|
newItem = new DataItem(data, this._formats),
|
|
|
|
newItem = new DataItem(data, this._formats),
|
|
|
|
pos = oldItem ? this._items.indexOf(oldItem) : -1;
|
|
|
|
pos = oldItem ? this._items.indexOf(oldItem) : -1;
|
|
|
|
|
|
|
|
|
|
|
|
newItem.selected = oldItem && oldItem.selected;
|
|
|
|
newItem.selected = oldItem && oldItem.selected;
|
|
|
|
if (pos > -1)
|
|
|
|
if (pos > -1)
|
|
|
|
this._items[pos] = newItem;
|
|
|
|
this._items[pos] = newItem;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
this._items.push(newItem);
|
|
|
|
this._items.push(newItem);
|
|
|
|
|
|
|
|
|
|
|
|
delete this._byKeys["key-" + key];
|
|
|
|
delete this._byKeys["key-" + key];
|
|
|
|
this._byKeys["key-" + this.getKey(data)] = newItem;
|
|
|
|
this._byKeys["key-" + this.getKey(data)] = newItem;
|
|
|
|
|
|
|
|
|
|
|
|
if (this._current == oldItem)
|
|
|
|
if (this._current == oldItem)
|
|
|
|
this._current = newItem;
|
|
|
|
this._current = newItem;
|
|
|
|
|
|
|
|
|
|
|
@ -984,7 +984,7 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
remove(key) {
|
|
|
|
remove(key) {
|
|
|
|
if (!key || this.empty) return this;
|
|
|
|
if (!key || this.empty) return this;
|
|
|
|
|
|
|
|
|
|
|
|
let before = this.dirty,
|
|
|
|
let before = this.dirty,
|
|
|
|
keys = Array.isArray(key) ? key : [key],
|
|
|
|
keys = Array.isArray(key) ? key : [key],
|
|
|
|
removed = this._items.filter(item => {
|
|
|
|
removed = this._items.filter(item => {
|
|
|
@ -997,13 +997,13 @@ class Dataset {
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
currentPos = this._items.indexOf(this._current),
|
|
|
|
currentPos = this._items.indexOf(this._current),
|
|
|
|
state = this.state;
|
|
|
|
state = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPos > -1) {
|
|
|
|
if (currentPos > -1) {
|
|
|
|
let newKey = null;
|
|
|
|
let newKey = null;
|
|
|
|
for (let i = currentPos, length = this._items.length; i < length; ++i) {
|
|
|
|
for (let i = currentPos, length = this._items.length; i < length; ++i) {
|
|
|
|
let item = this._items[i];
|
|
|
|
let item = this._items[i];
|
|
|
|
if (item.unreachable) continue;
|
|
|
|
if (item.unreachable) continue;
|
|
|
|
|
|
|
|
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1011,7 +1011,7 @@ class Dataset {
|
|
|
|
for (let i = this._items.length - 1; i > 0; --i) {
|
|
|
|
for (let i = this._items.length - 1; i > 0; --i) {
|
|
|
|
let item = this._items[i];
|
|
|
|
let item = this._items[i];
|
|
|
|
if (item.unreachable) continue;
|
|
|
|
if (item.unreachable) continue;
|
|
|
|
|
|
|
|
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1022,7 +1022,7 @@ class Dataset {
|
|
|
|
let after = this.dirty;
|
|
|
|
let after = this.dirty;
|
|
|
|
if (before != after)
|
|
|
|
if (before != after)
|
|
|
|
this.onDirtiesChange(after);
|
|
|
|
this.onDirtiesChange(after);
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1035,7 +1035,7 @@ class Dataset {
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
|
* are called.
|
|
|
|
* are called.
|
|
|
|
* Note that unlike {@link Dataset#remove} this method deletes user data completely from the Dataset
|
|
|
|
* Note that unlike {@link Dataset#remove} this method deletes user data completely from the Dataset
|
|
|
|
* and the erased user data are not traced as dirty user data.
|
|
|
|
* and the erased user data are not traced as dirty user data.
|
|
|
|
* @param {string|array} key key or keys to user data
|
|
|
|
* @param {string|array} key key or keys to user data
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
* @returns {Dataset} the Dataset
|
|
|
|
* @example
|
|
|
|
* @example
|
|
|
@ -1044,7 +1044,7 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
erase(key) {
|
|
|
|
erase(key) {
|
|
|
|
if (!key || this.empty) return;
|
|
|
|
if (!key || this.empty) return;
|
|
|
|
|
|
|
|
|
|
|
|
let before = this.dirty,
|
|
|
|
let before = this.dirty,
|
|
|
|
keys = Array.isArray(key) ? key : [key],
|
|
|
|
keys = Array.isArray(key) ? key : [key],
|
|
|
|
erased = this._items.filter(item => {
|
|
|
|
erased = this._items.filter(item => {
|
|
|
@ -1055,16 +1055,16 @@ class Dataset {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return erase;
|
|
|
|
return erase;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let currentPos = erased.indexOf(this._current) > -1 ? this._items.indexOf(this._current) : -1,
|
|
|
|
let currentPos = erased.indexOf(this._current) > -1 ? this._items.indexOf(this._current) : -1,
|
|
|
|
state = this.state;
|
|
|
|
state = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPos > -1) {
|
|
|
|
if (currentPos > -1) {
|
|
|
|
let newKey = null;
|
|
|
|
let newKey = null;
|
|
|
|
for (let i = currentPos + 1, length = this._items.length; i < length; ++i) {
|
|
|
|
for (let i = currentPos + 1, length = this._items.length; i < length; ++i) {
|
|
|
|
let item = this._items[i];
|
|
|
|
let item = this._items[i];
|
|
|
|
if (item.unreachable || erased.includes(item)) continue;
|
|
|
|
if (item.unreachable || erased.includes(item)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1072,7 +1072,7 @@ class Dataset {
|
|
|
|
for (let i = this._items.length - 1; i > 0; --i) {
|
|
|
|
for (let i = this._items.length - 1; i > 0; --i) {
|
|
|
|
let item = this._items[i];
|
|
|
|
let item = this._items[i];
|
|
|
|
if (item.unreachable || erased.includes(item)) continue;
|
|
|
|
if (item.unreachable || erased.includes(item)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
newKey = this.getKey(item);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1090,7 +1090,7 @@ class Dataset {
|
|
|
|
/**Returns an array of strings converted from the template using the property values of the Dataset's user data.
|
|
|
|
/**Returns an array of strings converted from the template using the property values of the Dataset's user data.
|
|
|
|
* In the template, placeholder for the properties of the user data is specified like {property name}.
|
|
|
|
* In the template, placeholder for the properties of the user data is specified like {property name}.
|
|
|
|
* @param {string} template template string
|
|
|
|
* @param {string} template template string
|
|
|
|
* @param {function} formatter function to format a row string with custom property placeholders
|
|
|
|
* @param {function} formatter function to format a row string with custom property placeholders
|
|
|
|
* @returns {array} array of strings converted from the template using the property values of the user data
|
|
|
|
* @returns {array} array of strings converted from the template using the property values of the user data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
inStrings(template, formatter) {
|
|
|
|
inStrings(template, formatter) {
|
|
|
@ -1122,7 +1122,7 @@ class Dataset {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default: return null;
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let item = this.getData(key, "item");
|
|
|
|
let item = this.getData(key, "item");
|
|
|
|
return item ? item.getValue(property) : undefined;
|
|
|
|
return item ? item.getValue(property) : undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1143,7 +1143,7 @@ class Dataset {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setValue(...args) {
|
|
|
|
setValue(...args) {
|
|
|
|
let key = null,
|
|
|
|
let key = null,
|
|
|
|
property = null,
|
|
|
|
property = null,
|
|
|
|
value = null;
|
|
|
|
value = null;
|
|
|
|
switch (args.length) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
@ -1167,46 +1167,46 @@ class Dataset {
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onDatasetChange(obj) {this.log("Dataset changed", obj);}
|
|
|
|
onDatasetChange(obj) {this.log("Dataset changed", obj);}
|
|
|
|
|
|
|
|
|
|
|
|
/**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
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onCurrentChange(currentItem) {this.log("Current changed", currentItem);}
|
|
|
|
onCurrentChange(currentItem) {this.log("Current changed", currentItem);}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data selection changes.
|
|
|
|
/**Called back when user data selection changes.
|
|
|
|
* @param {array} selected array of selected user data
|
|
|
|
* @param {array} selected array of selected user data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onSelectionChange(selected) {this.log("Selection changed", selected);}
|
|
|
|
onSelectionChange(selected) {this.log("Selection changed", selected);}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data is appended.
|
|
|
|
/**Called back when user data is appended.
|
|
|
|
* @param {object|array} appended user data or array of user data
|
|
|
|
* @param {object|array} appended user data or array of user data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onAppend(appended) {this.log("Data appended", appended);}
|
|
|
|
onAppend(appended) {this.log("Data appended", appended);}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data is modified.
|
|
|
|
/**Called back when user data is modified.
|
|
|
|
* @param {array} props names of changed properties
|
|
|
|
* @param {array} props names of changed properties
|
|
|
|
* @param {DataItem} modified modified user dataItem
|
|
|
|
* @param {DataItem} modified modified user dataItem
|
|
|
|
* @param {boolean} current whether current user data is modified
|
|
|
|
* @param {boolean} current whether current user data is modified
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onModify(props, modified, current) {this.log("Data modified", props, modified, current ? "current" : "");}
|
|
|
|
onModify(props, modified, current) {this.log("Data modified", props, modified, current ? "current" : "");}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data are replaced.
|
|
|
|
/**Called back when user data are replaced.
|
|
|
|
* @param {array} replacing array of user dataItems replacing the old ones
|
|
|
|
* @param {array} replacing array of user dataItems replacing the old ones
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onReplace(replacing) {this.log("Data replaced", replacing);}
|
|
|
|
onReplace(replacing) {this.log("Data replaced", replacing);}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data are removed.
|
|
|
|
/**Called back when user data are removed.
|
|
|
|
* @param {array} removed array of removed dataItems
|
|
|
|
* @param {array} removed array of removed dataItems
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onRemove(removed) {this.log("Data removed", removed)}
|
|
|
|
onRemove(removed) {this.log("Data removed", removed)}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when user data are erased.
|
|
|
|
/**Called back when user data are erased.
|
|
|
|
* @param {array} erased array of erased dataItems
|
|
|
|
* @param {array} erased array of erased dataItems
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onErase(erased) {this.log("Data erased", erased)}
|
|
|
|
onErase(erased) {this.log("Data erased", erased)}
|
|
|
|
|
|
|
|
|
|
|
|
/**Called back when the Dataset gets dirty or not dirty.
|
|
|
|
/**Called back when the Dataset gets dirty or not dirty.
|
|
|
|
* @param {boolean} dirty
|
|
|
|
* @param {boolean} dirty
|
|
|
|
* <ul> <li>true if the Dataset is dirty</li>
|
|
|
|
* <ul> <li>true if the Dataset is dirty</li>
|
|
|
|
* <li>false otherwise</li>
|
|
|
|
* <li>false otherwise</li>
|
|
|
|
* </ul>
|
|
|
|
* </ul>
|
|
|
@ -1221,9 +1221,9 @@ class DatasetControl {
|
|
|
|
this.prefixName = conf.prefixName;
|
|
|
|
this.prefixName = conf.prefixName;
|
|
|
|
this.infoSize = conf.infoSize;
|
|
|
|
this.infoSize = conf.infoSize;
|
|
|
|
this.appendData = conf.appendData;
|
|
|
|
this.appendData = conf.appendData;
|
|
|
|
|
|
|
|
|
|
|
|
this.query = {};
|
|
|
|
this.query = {};
|
|
|
|
|
|
|
|
|
|
|
|
conf.onDatasetChange = obj => this.onDatasetChange(obj),
|
|
|
|
conf.onDatasetChange = obj => this.onDatasetChange(obj),
|
|
|
|
conf.onCurrentChange = item => this.onCurrentChange(item),
|
|
|
|
conf.onCurrentChange = item => this.onCurrentChange(item),
|
|
|
|
conf.onSelectionChange = selected => this.onSelectionChange(selected),
|
|
|
|
conf.onSelectionChange = selected => this.onSelectionChange(selected),
|
|
|
@ -1236,7 +1236,7 @@ class DatasetControl {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.dataset = new Dataset(conf);
|
|
|
|
this.dataset = new Dataset(conf);
|
|
|
|
|
|
|
|
|
|
|
|
this.urls = conf.urls || {
|
|
|
|
this.urls = conf.urls || {
|
|
|
|
load:this.url("/list.do"),
|
|
|
|
load:this.url("/list.do"),
|
|
|
|
getInfo:this.url("/info.do"),
|
|
|
|
getInfo:this.url("/info.do"),
|
|
|
@ -1245,11 +1245,11 @@ class DatasetControl {
|
|
|
|
remove:this.url("/remove.do")
|
|
|
|
remove:this.url("/remove.do")
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prefixed(str) {
|
|
|
|
prefixed(str) {
|
|
|
|
return (this.prefix || "") + str;
|
|
|
|
return (this.prefix || "") + str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
url(str) {
|
|
|
|
url(str) {
|
|
|
|
return wctx.url("/" + this.prefixed(str));
|
|
|
|
return wctx.url("/" + this.prefixed(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1278,7 +1278,7 @@ class DatasetControl {
|
|
|
|
setData(obj) {
|
|
|
|
setData(obj) {
|
|
|
|
this.dataset.setData(obj);
|
|
|
|
this.dataset.setData(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
addData(obj) {
|
|
|
|
addData(obj) {
|
|
|
|
this.dataset.addData(obj);
|
|
|
|
this.dataset.addData(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1286,7 +1286,7 @@ class DatasetControl {
|
|
|
|
onDatasetChange(obj) {
|
|
|
|
onDatasetChange(obj) {
|
|
|
|
debug("onDatasetChange", obj);
|
|
|
|
debug("onDatasetChange", obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getCurrent(option) {
|
|
|
|
getCurrent(option) {
|
|
|
|
return this.dataset.getCurrent(option);
|
|
|
|
return this.dataset.getCurrent(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1328,42 +1328,42 @@ class DatasetControl {
|
|
|
|
else
|
|
|
|
else
|
|
|
|
this.setInfo(info);
|
|
|
|
this.setInfo(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setInfo(info) {}
|
|
|
|
setInfo(info) {}
|
|
|
|
|
|
|
|
|
|
|
|
newInfo(obj) {
|
|
|
|
newInfo(obj) {
|
|
|
|
this.dataset.append(obj || {});
|
|
|
|
this.dataset.append(obj || {});
|
|
|
|
this.getInfo();
|
|
|
|
this.getInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getValue(name) {
|
|
|
|
getValue(name) {
|
|
|
|
return this.dataset.getValue(name);
|
|
|
|
return this.dataset.getValue(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setValue(name, value) {
|
|
|
|
setValue(name, value) {
|
|
|
|
this.dataset.setValue(name, value);
|
|
|
|
this.dataset.setValue(name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onAppend(items) {
|
|
|
|
onAppend(items) {
|
|
|
|
debug("on append", items);
|
|
|
|
debug("on append", items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onModify(props, modified, current) {
|
|
|
|
onModify(props, modified, current) {
|
|
|
|
debug("on modify", props, "modified", modified, "current", current);
|
|
|
|
debug("on modify", props, "modified", modified, "current", current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
save(info) {
|
|
|
|
save(info) {
|
|
|
|
if (!info) return;
|
|
|
|
if (!info) return;
|
|
|
|
let item = this.getCurrent("item"),
|
|
|
|
let item = this.getCurrent("item"),
|
|
|
|
create = "added" == item.state;
|
|
|
|
create = "added" == item.state;
|
|
|
|
|
|
|
|
|
|
|
|
ajax.post({
|
|
|
|
ajax.post({
|
|
|
|
url:!create ? this.urls.update : this.urls.create,
|
|
|
|
url:!create ? this.urls.update : this.urls.create,
|
|
|
|
data:info,
|
|
|
|
data:info,
|
|
|
|
success:resp => this.onSave(resp)
|
|
|
|
success:resp => this.onSave(resp)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onSave(resp) {
|
|
|
|
onSave(resp) {
|
|
|
|
if (resp.saved) {
|
|
|
|
if (resp.saved) {
|
|
|
|
dialog.alert("저장됐습니다.");
|
|
|
|
dialog.alert("저장됐습니다.");
|
|
|
@ -1371,7 +1371,7 @@ class DatasetControl {
|
|
|
|
this._load();
|
|
|
|
this._load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remove(params) {
|
|
|
|
remove(params) {
|
|
|
|
let selected = this.dataset.getKeys("selected");
|
|
|
|
let selected = this.dataset.getKeys("selected");
|
|
|
|
if (selected.length < 1) return;
|
|
|
|
if (selected.length < 1) return;
|
|
|
@ -1380,14 +1380,14 @@ class DatasetControl {
|
|
|
|
params = {};
|
|
|
|
params = {};
|
|
|
|
params[this.prefixed("IDs")] = selected.join(",");
|
|
|
|
params[this.prefixed("IDs")] = selected.join(",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ajax.post({
|
|
|
|
ajax.post({
|
|
|
|
url:this.urls.remove,
|
|
|
|
url:this.urls.remove,
|
|
|
|
data:params,
|
|
|
|
data:params,
|
|
|
|
success:resp => this.onRemove(selected, resp)
|
|
|
|
success:resp => this.onRemove(selected, resp)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onRemove(selected, resp) {
|
|
|
|
onRemove(selected, resp) {
|
|
|
|
if (resp.saved)
|
|
|
|
if (resp.saved)
|
|
|
|
this._load();
|
|
|
|
this._load();
|
|
|
|