공백,탭 수정

main
이범준 5 months ago
parent 2ad91cc78f
commit 06eff26dd1

@ -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);
@ -60,7 +60,7 @@ const dateFormat = {
default: return ""; default: return "";
} }
}, },
parse(value) { parse(value) {
return isEmpty(value) ? "" : value.replace(/-/gi, ""); return isEmpty(value) ? "" : value.replace(/-/gi, "");
} }
@ -68,7 +68,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
*/ */
@ -80,7 +80,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 = {
default: return ""; default: return "";
} }
}, },
parse(value) { parse(value) {
return isEmpty(value) ? "" : value.replace(/:/gi, ""); return isEmpty(value) ? "" : value.replace(/:/gi, "");
} }
@ -98,7 +98,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
*/ */
@ -110,7 +110,7 @@ const datetimeFormat = {
default: return ""; default: return "";
} }
}, },
parse(value) { parse(value) {
return isEmpty(value) ? "" : timeFormat.parse(dateFormat.parse(value)).replace(/ /gi, ""); return isEmpty(value) ? "" : timeFormat.parse(dateFormat.parse(value)).replace(/ /gi, "");
} }
@ -126,8 +126,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>
*/ */
@ -149,24 +149,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)
@ -184,7 +184,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 */
@ -195,7 +195,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
@ -285,7 +285,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) {
@ -303,7 +303,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;},
* ... * ...
@ -350,12 +350,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>
@ -370,21 +370,21 @@ class Dataset {
* <li>{@link Dataset#onReplace onReplace}</li> * <li>{@link Dataset#onReplace onReplace}</li>
* <li>{@link Dataset#onRemove onRemove}</li> * <li>{@link Dataset#onRemove onRemove}</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 = () => {};
@ -438,12 +438,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));
@ -495,7 +495,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);
@ -505,29 +505,29 @@ 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) {
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))
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
@ -543,7 +543,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); let data = this._getDataItems(obj);
this._items = this._items.concat(data.items); this._items = this._items.concat(data.items);
@ -557,13 +557,13 @@ 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;
} }
/**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);
@ -603,7 +603,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.
@ -636,7 +636,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>
@ -734,7 +734,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));
@ -833,13 +833,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";
@ -849,10 +849,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;
}; };
@ -880,11 +880,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),
@ -898,11 +898,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";
@ -946,30 +946,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;
@ -999,7 +999,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 => {
@ -1012,13 +1012,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;
} }
@ -1026,7 +1026,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;
} }
@ -1037,7 +1037,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;
} }
@ -1049,7 +1049,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
@ -1058,7 +1058,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 => {
@ -1069,16 +1069,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;
} }
@ -1086,7 +1086,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;
} }
@ -1104,7 +1104,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) {
@ -1136,7 +1136,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;
} }
@ -1157,7 +1157,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:
@ -1181,41 +1181,41 @@ 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 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>
@ -1230,9 +1230,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),
@ -1245,7 +1245,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"),
@ -1254,11 +1254,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));
} }
@ -1284,7 +1284,7 @@ class DatasetControl {
} }
}); });
} }
download(type) { download(type) {
this.query.download = type || "xls"; this.query.download = type || "xls";
let query = toQuery(this.query); let query = toQuery(this.query);
@ -1295,7 +1295,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);
} }
@ -1303,7 +1303,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);
} }
@ -1345,42 +1345,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("저장됐습니다.");
@ -1388,7 +1388,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;
@ -1397,14 +1397,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();

Loading…
Cancel
Save