base.js, code.js, dataset.js 수정

main
이범준 6 months ago
parent e10bd08082
commit ab99620021

@ -728,20 +728,39 @@ class FormFields {
} }
}; };
/* $.fn.datePicker = function(selector) {
$.datepicker.setDefaults({ return this.each(function() {
dateFormat:"yy-mm-dd", $(this)
yearSuffix:"년", .datepicker()
monthNames:["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"], .attr("maxlength", "10")
dayNames:["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"], .on("input",function(e) {
dayNamesMin:["일", "월", "화", "수", "목", "금", "토"], if (this.value.length <= 0
showMonthAfterYear:true, || this.value.length != this.selectionStart
showOtherMonths:true, )
selectOtherMonths:true, return;
nextText:"다음 달",
prevText:"이전 달" 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 fromSource 시작값을 갖는 input의 selector
* @param toSource 종료값을 갖는 input의 selector * @param toSource 종료값을 갖는 input의 selector
@ -767,3 +786,63 @@ function inputsInRange(fromSource, toSource) {
function ignore() { function ignore() {
console.log.apply(console, arguments); console.log.apply(console, arguments);
} }
function fileInput(conf) {
conf = conf || {};
var name = conf.name || "upload",
tag = "<input type='file' name='{name}'{multiple}{accept} style='display:none;'>"
.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;
}

@ -26,6 +26,22 @@ class CodeControl {
REG_DT:datetimeFormat 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.onDatasetChange = obj => this.onGroupListChange(obj);
this.groups.onCurrentChange = item => { this.groups.onCurrentChange = item => {

@ -487,7 +487,9 @@ class Dataset {
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);
});
}
} }

@ -2,47 +2,7 @@ function initDatepicker(elementId){
var executionArea = $("#"+elementId); var executionArea = $("#"+elementId);
/*--------------------- 달력 제어 ---------------------*/ executionArea.find(".form-date").datePicker();
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();
});
}
});
} }

Loading…
Cancel
Save