From ab996200214be86373e579c12c358d90c0baec6c Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Tue, 7 May 2024 09:03:18 +0900 Subject: [PATCH] =?UTF-8?q?base.js,=20code.js,=20dataset.js=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/resources/js/base/base.js | 107 +++++++++++++++--- src/main/webapp/resources/js/base/code.js | 16 +++ src/main/webapp/resources/js/base/dataset.js | 51 +++++++-- .../js/fims/cmmn/initAfterPageLoad.js | 44 +------ 4 files changed, 155 insertions(+), 63 deletions(-) diff --git a/src/main/webapp/resources/js/base/base.js b/src/main/webapp/resources/js/base/base.js index 1ef9a236..ac3a3ac4 100644 --- a/src/main/webapp/resources/js/base/base.js +++ b/src/main/webapp/resources/js/base/base.js @@ -728,20 +728,39 @@ class FormFields { } }; -/* -$.datepicker.setDefaults({ - dateFormat:"yy-mm-dd", - yearSuffix:"년", - monthNames:["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"], - dayNames:["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"], - dayNamesMin:["일", "월", "화", "수", "목", "금", "토"], - showMonthAfterYear:true, - showOtherMonths:true, - selectOtherMonths:true, - nextText:"다음 달", - prevText:"이전 달" -}); -*/ +$.fn.datePicker = function(selector) { + return this.each(function() { + $(this) + .datepicker() + .attr("maxlength", "10") + .on("input",function(e) { + if (this.value.length <= 0 + || this.value.length != this.selectionStart + ) + return; + + var value = this.value.replaceAll("-",""); + if (value.length > 7) { + this.value = value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6); + } else if (value.length > 5) { + this.value = value.substring(0,4)+"-"+value.substring(4); + } + }) + .on("paste", function(e) { + var value = e.originalEvent.clipboardData.getData('text'); + if (value.length == 8) + this.value = value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6); + }); + + var calendarIcon = $(this).next("button.bx-calendar"); + if (calendarIcon.length > 0) { + $(calendarIcon).on("click", function() { + $(this).prev().focus(); + }); + } + }); +} + /** * @param fromSource 시작값을 갖는 input의 selector * @param toSource 종료값을 갖는 input의 selector @@ -767,3 +786,63 @@ function inputsInRange(fromSource, toSource) { function ignore() { console.log.apply(console, arguments); } + +function fileInput(conf) { + conf = conf || {}; + var name = conf.name || "upload", + tag = "" + .replace(/{name}/, name) + .replace(/{multiple}/, conf.multiple ? " multiple" : "") + .replace(/{accept}/, conf.accept ? " accept='" + conf.accept + "'" : ""), + obj = { + name:name, + input:null, + files:[], + + select:function(onSelect) { + if (!obj.input) { + var input = obj.input = $(tag); + $("body").append(input); + input.change(function() { + var files = $(this).get(0).files, + length = files.length, + selected = []; + for (var i = 0; i < length; ++i) { + var file = files[i]; + file.id = name + (obj.files.length); + selected.push(file); + obj.files.push(file); + } + onSelect(selected); + }) + } + obj.input.click(); + }, + + getFiles:function() { + return obj.files; + }, + + remove:function(id) { + if (!id) return; + + var files = obj.files; + for (var i = 0; i < files.length; ++i) { + var file = files[i]; + if (id == file.id) { + files.splice(i, 1); + break; + } + } + }, + + clear:function() { + if (obj.input) + $(obj.input).remove(); + obj.input = null; + obj.files.forEach(function(file) {delete file;}); + obj.files = []; + } + }; + return obj; +} diff --git a/src/main/webapp/resources/js/base/code.js b/src/main/webapp/resources/js/base/code.js index 99f04ae8..b4f45c05 100644 --- a/src/main/webapp/resources/js/base/code.js +++ b/src/main/webapp/resources/js/base/code.js @@ -26,6 +26,22 @@ class CodeControl { REG_DT:datetimeFormat } }); + this.codes.remove = (params) => { + let selected = this.codes.dataset.getKeys("selected"); + if (selected.length < 1) return; + + if (!params) { + params = {}; + } + params.groupID = this.groups.dataset.getCurrent()["GRP_ID"]; + params.codes = selected.join(","); + + ajax.post({ + url:this.codes.urls.remove, + data:params, + success:resp => this.codes.onRemove(selected, resp) + }); + }; this.groups.onDatasetChange = obj => this.onGroupListChange(obj); this.groups.onCurrentChange = item => { diff --git a/src/main/webapp/resources/js/base/dataset.js b/src/main/webapp/resources/js/base/dataset.js index 12a81872..e549de72 100644 --- a/src/main/webapp/resources/js/base/dataset.js +++ b/src/main/webapp/resources/js/base/dataset.js @@ -486,8 +486,10 @@ class Dataset { let state = this.state; this._byKeys = {}; this._current = null; - - let data = this._getDataItems(obj = obj || {}); + + obj = obj || {}; + + let data = this._getDataItems(obj); this._items = data.items; this._byKeys = data.byKeys; /* @@ -510,6 +512,7 @@ class Dataset { } _getDataItems(obj) { + obj = obj || {}; let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || []; if (!Array.isArray(array)) throw new Error("The data must be an array"); @@ -544,13 +547,15 @@ class Dataset { return this.setData(obj); let state = this.state; - let data = this._getDataItems(obj = obj || {}); + let data = this._getDataItems(obj); this._items = this._items.concat(data.items); this._byKeys = { ...this._byKeys, ...data.byKeys }; - + + obj = obj || {} + this.onDatasetChange(obj); this.setState(!Array.isArray(obj) ? obj.state : state); this.onDirtiesChange(this.dirty); @@ -1289,9 +1294,6 @@ class DatasetControl { } download(type) { - if (!this.query.pageNum) - this.query.pageNum = 1; - this.query.download = type || "xls"; let query = toQuery(this.query); this.query.download = null; @@ -1415,4 +1417,39 @@ class DatasetControl { if (resp.saved) 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); + }); + } } \ No newline at end of file diff --git a/src/main/webapp/resources/js/fims/cmmn/initAfterPageLoad.js b/src/main/webapp/resources/js/fims/cmmn/initAfterPageLoad.js index 975031c3..154e9345 100644 --- a/src/main/webapp/resources/js/fims/cmmn/initAfterPageLoad.js +++ b/src/main/webapp/resources/js/fims/cmmn/initAfterPageLoad.js @@ -1,48 +1,8 @@ function initDatepicker(elementId){ var executionArea = $("#"+elementId); - - /*--------------------- 달력 제어 ---------------------*/ - executionArea.find(".form-date").each(function(){ - - $(this) - .datepicker() - .attr("maxlength", "10") - .on("input",function(e){ - - if(this.value.length <= 0){ - return; - } - if(this.value.length != this.selectionStart){ - return; - } - - var value = this.value.replaceAll("-",""); - - if(value.length > 7){ - this.value = value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6); - } else if(value.length > 5){ - this.value = value.substring(0,4)+"-"+value.substring(4); - } - - }) - .on("paste", function(e){ - - var value = e.originalEvent.clipboardData.getData('text'); - if(value.length == 8){ - this.value = value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6); - } - - }) - ; - - var calendarIcon = $(this).next("button.bx-calendar"); - if(calendarIcon.length > 0){ - $(calendarIcon).on("click", function() { - $(this).prev().focus(); - }); - } - }); + + executionArea.find(".form-date").datePicker(); }