code-support.js 파일 추가

main
이범준 1 year ago
parent 4d61a68480
commit ef510e9948

@ -117,7 +117,7 @@
<script src="<c:url value="/resources/js/base/code.js"/>?${ver}"></script>
<script>
var codeControl = new CodeControl();

@ -33,6 +33,8 @@
<script src="<c:url value="/resources/js/base/base-fims.js?${ver}"/>"></script>
<script src="<c:url value="/resources/js/base/dataset.js?${ver}"/>"></script>
<script src="<c:url value="/resources/js/base/dataset-fims.js?${ver}"/>"></script>
<script src="<c:url value="/resources/js/base/code.js"/>?${ver}"></script>
<script src="<c:url value="/resources/js/base/code-support.js?${ver}"/>"></script>
<script src="<c:url value="/resources/js/base/menu.js"/>?${ver}"></script>
<script src="<c:url value="/resources/js/base/menu-support.js?${ver}"/>"></script>
<script src="<c:url value="/resources/js/base/menu-support-fims.js?${ver}"/>"></script>

@ -0,0 +1,44 @@
class CommonCodes {
constructor(codeList, asObject) {
codeList.forEach(item => this[item.code] = !asObject ? item.value : item);
this.codes = () => codeList.map(item => item.code);
this.list = () => codeList;
}
_value(code, field) {
let found = this[code];
if (!found)
return null;
return "string" == typeof found ? found : found[field]
}
value(code, nt) {
return ifEmpty(this._value(code, "value"), nt);
}
format(code) {
return this.value(code, "");
}
parse(value) {
for (let code in this) {
let val = this.value(code);
if (value == val)
return code;
}
return "";
}
etc1(code) {
return this._value(code, "etc1");
}
etc2(code) {
return this._value(code, "etc2");
}
etc3(code) {
return this._value(code, "etc3");
}
}

@ -3,6 +3,10 @@
/**@file Classes and objects to help control user data in HTML pages
*/
function lpad(v) {
return v < 10 ? "0" + v : v;
}
/** value format for numbers */
const numberFormat = {
/**Parses the value for a number
@ -44,12 +48,8 @@ const dateFormat = {
let _format = v => {
let date = "number" == typeof v ? new Date(v) : v;
let year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate();
if (month < 10)
month = "0" + month;
if (day < 10)
day = "0" + day;
month = lpad(date.getMonth() + 1),
day = lpad(date.getDate());
return year + "-" + month + "-" + day;
};
@ -62,22 +62,43 @@ const dateFormat = {
}
};
/** value format for datetimes */
const datetimeFormat = {
/** value format for time */
const timeFormat = {
/**Formats the value
* @param {number} value value to format
* @returns {string} formatted value
*/
format(value) {
let _format = v => {
let date = "number" == typeof v ? new Date(v) : v;
return date.toLocaleTimeString();
let date = "number" == typeof v ? new Date(v) : v,
hours = lpad(date.getHours()),
minutes = lpad(date.getMinutes()),
seconds = lpad(date.getSeconds());
return hours + ":" + minutes + ":" + seconds;
};
switch (value instanceof Date ? "date" : typeof value) {
case "number":
case "date": return dateFormat.format(value) + " " + _format(value);
case "string": return dateFormat.format(value) + " " + value.substr(8, 2) + ":" + value.substr(10, 2) + ":" + value.substr(12)
case "date": return _format(value);
case "string":
let offset = value.length - 6;
return value.substr(0 + offset, 2) + ":" + value.substr(2 + offset, 2) + ":" + value.substr(4 + offset)
default: return "";
}
}
}
/** value format for datetimes */
const datetimeFormat = {
/**Formats the value
* @param {number} value value to format
* @returns {string} formatted value
*/
format(value) {
switch (value instanceof Date ? "date" : typeof value) {
case "number":
case "date": return dateFormat.format(value) + " " + timeFormat.format(value);
case "string": return dateFormat.format(value) + " " + timeFormat.format(value);
default: return "";
}
}
@ -507,7 +528,6 @@ class Dataset {
if (this.empty)
return this.setData(obj);
let state = this.state;
let data = this._getDataItems(obj);
this._items = this._items.concat(data.items);

Loading…
Cancel
Save