'use strict' /** * Copyright (c) 2017~2021, OBCon Inc. * All rights reserved. */ /** * @file * @copyright 2017~2021, OBCon Inc. * @author gye hyun james kim [pnuskgh@gmail.com] */ let moment = require('moment'); class Fields { //--- To-Do. Field 설정(module.fieldDesc)을 참조하여 field를 화면에 표시 //--- 현재는 사용하지 않음 display(moduleName, fieldName, item, options={ // type: 'string', len: 8, // allowNull: false, // defaultValue: 'HTTP', // validate: {}, // title: 'Method', // strType: 'string', // enum: [ // ['HTTP', 'HTTP/HTTPS'], //--- 브라우저부터의 요청 // ['GET', 'GET'], ['POST', 'POST'], ['PUT', 'PUT'], ['DELETE', 'DELETE'] //--- Open API로부터의 요청 // ] }) { let html = []; return html.join(''); } get layout() { let MARGIN_BOTTOM = 10; return { fieldStyle: 'margin-bottom: ' + MARGIN_BOTTOM + 'px;', fieldRequire: ' (*)' }; } get date() { return { format: this.dateFormat.bind(this), viewDuration: this._dateViewDuration.bind(this) }; } dateFormat(argDate, format='YYYY-MM-DD HH:mm:ss') { if (argDate == null) { return ''; } let strDate = moment(argDate).format(format); return (strDate == 'Invalid date') ? '':strDate; } _dateViewDuration(label, id, type='text', size=6, value='', options={}) { return this.show(label, id, type, size, value, options); } get string() { if (config.theme.version == '2.00') { //--- 실행되지 않음 //--- 현재 2.00 버전을 사용하는 고객사는 한 곳도 없음 return { viewDetail: this._stringViewDetail_200.bind(this), viewDetailFull: this._stringViewDetailFull_200.bind(this), viewBlank: this._stringViewBlank_200.bind(this), viewBlankLine: this._stringViewBlankLine_200.bind(this), viewUpdate: this._stringViewUpdate_200.bind(this), viewUpdateFull: this._stringViewUpdateFull_200.bind(this), viewSelect: this._stringViewSelect_200.bind(this), searchSelect: this._stringSearchSelect_200.bind(this), getSelectValue: this.getSelectValue.bind(this) }; } else { if (config.theme.defaultName == 'default_2022') { return { viewDetail: this._stringViewDetail_100_2022.bind(this), viewDetailFull: this._stringViewDetailFull_100_2022.bind(this), viewBlank: this._stringViewBlank_100_2022.bind(this), viewBlankLine: this._stringViewBlankLine_100_2022.bind(this), viewUpdate: this._stringViewUpdate_100_2022.bind(this), viewUpdateFull: this._stringViewUpdateFull_100_2022.bind(this), viewSelect: this._stringViewSelect_100_2022.bind(this), searchSelect: this._stringSearchSelect_100_2022.bind(this), getSelectValue: this.getSelectValue.bind(this) }; } else { //--- 실행되지 않음 //--- default_2022 을 사용하지 않는 곳이 한 곳도 없음 return { viewDetail: this._stringViewDetail_100.bind(this), viewDetailFull: this._stringViewDetailFull_100.bind(this), viewBlank: this._stringViewBlank_100.bind(this), viewBlankLine: this._stringViewBlankLine_100.bind(this), viewUpdate: this._stringViewUpdate_100.bind(this), viewUpdateFull: this._stringViewUpdateFull_100.bind(this), viewSelect: this._stringViewSelect_100.bind(this), searchSelect: this._stringSearchSelect_100.bind(this), getSelectValue: this.getSelectValue.bind(this) }; } } } _stringViewDetail_100(title, name, value, theme, type='text', size=6) { let content = ''; content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; return content; } _stringViewDetailFull_100(title, name, value, theme, type='text', row=10) { let content = ''; if (type == 'textarea') { content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; } else { content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; } return content; } _stringViewBlank_100(size=6, id="") { let content = ''; if (id == "") { content = content + '
'; } else { content = content + '
'; } content = content + '  '; content = content + '
'; return content; } _stringViewBlankLine_100(gap=20) { let content = ''; content = content + '
'; content = content + '  '; content = content + '
'; return content; } _stringViewUpdate_100(title, name, value, theme, type='text', size=6, isRequire=false) { let content = ''; content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; return content; } _stringViewUpdateFull_100(title, name, value, theme, type='text', isRequire=false, row=10) { let content = ''; if (type == 'textarea') { content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; } else { content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; } return content; } _stringViewSelect_100(title, name, value, data, theme, type='text', size=6) { let content = ''; content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; return content; } _stringSearchSelect_100(title, name, value, data, theme, type='text', size=3, allowAll=false) { let content = ''; content = content + '
'; content = content + '
'; content = content + ' '; content = content + '
'; content = content + ' '; content = content + '
'; return content; } _getValue(value, type) { let displayValue = ((typeof(value) == 'undefined') || (value == null)) ? '':value; switch (utils.typeof(displayValue)) { case 'date': if (displayValue != '') { switch (type) { case 'date': displayValue = moment(displayValue).format('YYYY-MM-DD'); break; case 'datetime': displayValue = moment(displayValue).format('YYYY-MM-DD HH:mm:ss'); break; } } break; case 'boolean': displayValue = (displayValue) ? 'true':'false' break; } return displayValue; } _stringViewDetail_100_2022(title, name, value, theme, type='text', size=6) { const displayValue = this._getValue(value, type); let content = ''; content = content + `
`; content = content + '
'; content = content + ' '; if (type == 'color') { content = content + ' '; } else { content = content + ' '; } content = content + '
'; content = content + '
'; return content; } _stringViewDetailFull_100_2022(title, name, value, theme, type='text', row=10) { const displayValue = this._getValue(value, type); let content = ''; if (type == 'textarea') { content = content + '
'; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; } else { content = content + '
'; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; } return content; } _stringViewBlank_100_2022(size=6, id="") { let content = ''; if (id == "") { content = content + '
'; } else { content = content + '
'; } content = content + '  '; content = content + '
'; return content; } _stringViewBlankLine_100_2022(gap=20) { let content = ''; content = content + '
'; content = content + '  '; content = content + '
'; return content; } _stringViewUpdate_100_2022(title, name, value, theme, type='text', size=6, isRequire=false) { const displayValue = this._getValue(value, type); let content = ''; content = content + `
`; content = content + '
'; content = content + ' '; // content = content + '
'; if (type == 'color') { content = content + ' '; } else { content = content + ' '; } content = content + '
'; content = content + '
'; return content; } _stringViewUpdateFull_100_2022(title, name, value, theme, type='text', isRequire=false, row=10) { const displayValue = this._getValue(value, type); let content = ''; if (type == 'textarea') { content = content + `
`; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; } else { content = content + `
`; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; } return content; } _stringViewSelect_100_2022(title, name, value, data, theme, type='text', size=6) { const displayValue = this._getValue(value, type); let content = ''; content = content + `
`; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; return content; } _stringSearchSelect_100_2022(title, name, value, data, theme, type='text', size=3, allowAll=false) { const displayValue = this._getValue(value, type); let content = ''; content = content + `
`; content = content + '
'; content = content + ' '; content = content + ' '; content = content + '
'; content = content + '
'; return content; } show(label, id, type='text', size=6, value='', options={ // readonly: false, // require: false, // allowAll: false, //--- 향후 삭제할 것 // options: [ [ 'value', 'label' ] ], // rows: 5, //--- textarea 필드에서 rows // isDuration: false, }) { let content = []; let attrs = []; if ((typeof(options.readonly) != 'undefined') && (options.readonly == true)) { attrs.push('readonly'); } if ((typeof(options.require) != 'undefined') && (options.require == true)) { label = `${label}(*)`; } if (size != null) { content.push(`
`); } content.push('
'); switch (type) { case 'select': content.push(this._showLabel(label, id, `form-label input-group-text obcon-col obcon-col${size}-label`)); content.push(` '); break; case 'textarea': content.push(this._showLabel(label, id, `form-label input-group-text obcon-col obcon-col${size}-label-textarea align-middle`)); content.push(``); break; case 'datetime-local': case 'date': if (options.isDuration) { attrs.push('datetimeonly'); content.push(this._showLabel((label == null) ? null:label[0], `${id}Fr`, `form-label input-group-text obcon-col obcon-col${size}-label`)); content.push(this._showFieldInput(`${id}Fr`, type, `form-control obcon-col obcon-col-date`, value[0], attrs)); content.push(' ~ '); content.push(this._showLabel((label == null) ? null:label[1], `${id}To`, `form-label input-group-text obcon-col obcon-col${size}-label`)); content.push(this._showFieldInput(`${id}To`, type, `form-control obcon-col obcon-col-date`, value[1], attrs)); } else { content.push(this._showLabel(label, id, `form-label input-group-text obcon-col obcon-col${size}-label`)); content.push(this._showFieldInput(id, type, `form-control obcon-col obcon-col${size}-field`, value, attrs)); } break; case 'text': default: content.push(this._showLabel(label, id, `form-label input-group-text obcon-col obcon-col${size}-label`)); content.push(this._showFieldInput(id, type, `form-control obcon-col obcon-col${size}-field`, value, attrs)); break; } content.push('
'); if (size != null) { content.push('
'); } return content.join(''); } _showLabel(label, id, classes) { return (label == null) ? '':`` } _showFieldInput(id, type, classes, value, attrs) { return ``; } _stringViewDetail_200(title, name, value, theme, type='text', size=6) { return this.show(title, name, type, size, value, { readonly: true }); } _stringViewDetailFull_200(title, name, value, theme, type='text', rows=10) { if (type == 'textarea') { return this.show(title, name, type, 12, value, { rows: rows, readonly: true }); } else { return this.show(title, name, type, 12, value, { readonly: true }); } } _stringViewBlank_200(size=6, id=null) { return `
`; } _stringViewBlankLine_200(gap=3) { return `
`; } _stringViewUpdate_200(title, name, value, theme, type='text', size=6, isRequire=false) { return this.show(title, name, type, size, value, { require: isRequire }); } _stringViewUpdateFull_200(title, name, value, theme, type='text', isRequire=false, rows=10) { if (type == 'textarea') { return this.show(title, name, type, 12, value, { rows: rows, require: isRequire }); } else { return this.show(title, name, type, 12, value, { require: isRequire }); } } _stringViewSelect_200(title, name, value, data, theme, type='text', size=6) { return this.show(title, name, 'select', size, value, { options: data }); } _stringSearchSelect_200(title, name, value, data, theme, type='text', size=3, allowAll=false) { return this.show(title, name, 'select', size, value, { options: data, allowAll: allowAll }); } getSelectValue(value, data) { const displayValue = this._getValue(value, ''); let rtValue = ''; data.forEach(opt => { if ((displayValue == opt[0]) || (value == opt[0])) { rtValue = opt[1]; } }); return rtValue; } get disp() { return { contentTitle: this.displayContentTitle.bind(this), contentTitleButton: this.displayContentTitleButton.bind(this), contentTitleButton2: this.displayContentTitleButton2.bind(this), contentError: this.displayContentError.bind(this), contentMenuButton: this.displayContentMenuButton.bind(this), contentTabMenu: this.displayContentTabMenu.bind(this), contentTableButton: this.displayContentTableButton.bind(this) }; } _showSettingAndHelp(settings=null, helps=null) { let content = []; // settings = [ // { // name: '설정 이름', // target: '설정 타겟 이름' // } // ]; if (utils.isArray(settings)) { if (settings.length == 0) { } else if (settings.length == 1) { content.push(`  `); } else { content.push(''); content.push(' '); content.push(' '); content.push(''); } } //--- To-Do : 도움말 파일을 생성 한다. // ${module}_${action}_${순서}_${라벨}_${service}_${theme}.md //--- service별 theme별 도움말 // ${module}_${action}_${순서}_${라벨}_${service}_default.md //--- service별 도움말 // ${module}_${action}_${순서}_${라벨}_default_${theme}.md //--- theme별 도움말 // ${module}_${action}_${순서}_${라벨}.md //--- 디폴트 도움말 // Action이 호출되면 도움말 파일을 검색하여 있는 경우 해당 파일을 도움말 링크에 표시하도록 한다. // helps = [ // { // name: '도움말 이름', // url: '도움말 URL' // } // ]; if (utils.isArray(helps)) { if (helps.length == 0) { } else if (helps.length == 1) { content.push(` `); } else { content.push(''); content.push(' '); content.push(' '); content.push(''); } } return content.join(''); } displayContentTitle(title, settings=null, helps=null) { let content = []; // if (settings == null) { // settings = [ { name: '설정', target: 'pageSetting' } ]; // } // if (helps == null) { // helps = [ { name: '도움말', action: 'linkHelp();' } ]; // } content.push('
'); content.push(`
${title}
`); content.push('
'); content.push('
 '); content.push(this._showSettingAndHelp(settings, helps)); content.push('
'); content.push('
'); return content.join(''); } displayContentTitleButton(title, buttons, settings=null, helps=null) { let content = []; // if (settings == null) { // settings = [ { name: '설정', target: 'pageSetting' } ]; // } // if (helps == null) { // helps = [ { name: '도움말', action: 'linkHelp();' } ]; // } content.push('
'); content.push(`
${title}
`); content.push('   '); buttons.forEach(btn => { if (typeof(btn.id) == 'undefined') { content.push(` `); } else { content.push(` `); } }); content.push('
'); content.push('
 '); content.push(this._showSettingAndHelp(settings, helps)); content.push('
'); content.push('
'); return content.join(''); } displayContentTitleButton2(title, buttons, settings=null, helps=null, msgSave) { let content = []; content.push('
'); content.push(`
${title}
`); content.push('   '); buttons.forEach(btn => { if (typeof(btn.id) == 'undefined') { content.push(` `); } else { content.push(` `); } }); content.push('
'); content.push('
 '); content.push(this._showSettingAndHelp(settings, helps)); content.push('
'); content.push('
'); content.push(` `); content.push('
'); content.push('
'); return content.join(''); } displayContentError() { let content = []; content.push(''); return content.join(''); } displayContentMenuButton(buttons, menu=null, isGroup=true) { let content = []; if (menu == null) { if (isGroup) { content.push('
'); buttons.forEach(btn => { if (typeof(btn.id) == 'undefined') { content.push(` `); } else { content.push(` `); } }); content.push('
') } else { buttons.forEach(btn => { if (typeof(btn.id) == 'undefined') { content.push(` `); } else { content.push(` `); } }); } } else { content.push('
'); content.push(' '); content.push('
'); } return content.join(''); } displayContentTabMenu(options) { let content = []; content.push(`'); return content.join(''); } displayContentTableButton(buttons, menu=null) { let content = []; if (menu == null) { buttons.forEach(btn => { content.push('`); }); } else { content.push(''); } return content.join(''); } } module.exports = Fields;