From f8023f61db3ce2928d4590c70bfb2a5086327539 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 9 Jul 2024 13:49:20 +0900 Subject: [PATCH] =?UTF-8?q?setData,=20addData,=20onDatasetChange=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/resources/js/base/dataset.js | 65 +++++++++++--------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/main/webapp/resources/js/base/dataset.js b/src/main/webapp/resources/js/base/dataset.js index 2c141a0..0433515 100644 --- a/src/main/webapp/resources/js/base/dataset.js +++ b/src/main/webapp/resources/js/base/dataset.js @@ -485,9 +485,10 @@ class Dataset { * * are called back. * @param {array|object} obj user data or an object that has user data + * @param {object} obj optional information * @returns {Dataset} the Dataset */ - setData(obj) { + setData(obj, option) { this._byKeys = {}; this._current = null; @@ -508,7 +509,7 @@ class Dataset { this._byKeys[key] = item; }); */ - this.onDatasetChange(obj); + this.onDatasetChange(obj, option); this.setState(obj.state); this.onDirtiesChange(this.dirty); @@ -544,9 +545,10 @@ class Dataset { * * are called back. * @param {array|object} obj user data or an object that has user data + * @param {object} obj optional information * @returns {Dataset} the Dataset */ - addData(obj) { + addData(obj, option) { if (this.empty) return this.setData(obj); @@ -560,7 +562,7 @@ class Dataset { obj = obj || {} - this.onDatasetChange(obj); + this.onDatasetChange(obj, option); this.setState(!Array.isArray(obj) ? obj.state : state); this.onDirtiesChange(this.dirty); @@ -1203,8 +1205,9 @@ class Dataset { /**Called back when user data are set. * @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. * @param {DataItem} currentItem current dataItem @@ -1258,7 +1261,7 @@ class DatasetControl { this.query = {}; - conf.onDatasetChange = obj => this.onDatasetChange(obj); + conf.onDatasetChange = (obj, option) => this.onDatasetChange(obj, option); conf.onCurrentChange = item => this.onCurrentChange(item); conf.onSelectionChange = selected => this.onSelectionChange(selected); conf.onAppend = items => this.onAppend(items); @@ -1297,43 +1300,49 @@ class DatasetControl { this._load(); } - _load(state, prev, callback) { + _load(option) { + option = option || {}; + if (!this.query.pageNum) this.query.pageNum = 1; - if (prev) + if (option.prev) this.query.pageNum = Math.max(1, this.query.pageNum - 1); ajax.get({ url:this.urls.load, data:this.query, success:resp => { - if (!prev) - resp.state = state; + if (!option.prev) + resp.state = option.state; if (!this.appendData || this.query.pageNum == 1) - this.setData(resp); + this.setData(resp, option); else { - this.addData(resp); + this.addData(resp, option); } - if (callback) - callback(); + if (option.callback) + option.callback(); } }); } - + reload(option) { - let all = option ? option.all : false, - prev = option ? option.prev : false, + if (!option) + option = {}; + option.reloaded = true; + + let all = option.all, + prev = option.prev, state = this.dataset.state; + option.state = state; if (!all) { - this._load(state, prev); + this._load(option); } else { - let query = Object.assign({}, this.query), - state = this.dataset.state; + let query = Object.assign({}, this.query); this.query.fetchSize = this.dataset.length; this.query.pageNum = 1; - this.dataset.clear(); - this._load(state, prev, () => {this.query = query;}); + option.callback = () => {this.query = query;}; + this._load(option); } } @@ -1344,16 +1353,16 @@ class DatasetControl { document.location.href = this.urls.load + "?" + query; } - setData(obj) { - this.dataset.setData(obj); + setData(obj, option) { + this.dataset.setData(obj, option); } - addData(obj) { - this.dataset.addData(obj); + addData(obj, option) { + this.dataset.addData(obj, option); } - onDatasetChange(obj) { - debug("onDatasetChange", obj); + onDatasetChange(obj, option) { + debug("onDatasetChange", obj, option); } getCurrent(option) {