/*dd* * admin/menu */ var mplus_admin_attr = function( language_code ){ //상속 mplus_admin.call(this); var self = this; //언어코드 var DEFAULT_LANGUAGE = language_code; //변수 var $sltAttrType = $('#sltAttrType'), $txtAttrId = $('#txtAttrId'), $txtAttrName = $('#txtAttrName'), $sltUpperAttr = $('#sltUpperAttr'), $txtExtraAttrId = $('#txtExtraAttrId'), $txtExtraAttrName = $('#txtExtraAttrName'), $txtExtraAttrDesc = $('#txtExtraAttrDesc'), $btnSave_attr = $('#btnSave_attr'), $btnRemove_attr = $('#btnRemove_attr'), $btnSave_extraAttr = $('#btnSave_extraAttr'), $btnRemove_extraAttr = $('#btnRemove_extraAttr'), $sltUser = $('#sltUser'), $txtSearch = $('#txtSearch'), $btnSearch = $('#btnSearch'), $btnEditExtraAttrUser = $('#btnEditExtraAttrUser'), $btnSaveExtraAttrUser = $('#btnSaveExtraAttrUser'), $attrCrudServiceBaseUrl = contextPath + '/admin/attr', $crudServiceBaseUrl = contextPath + '/admin/extraAttr', $userAttrCrudServiceBaseUrl = contextPath + '/admin/userAttr'; //속성 관련 요청을 위해 별도로 작성 var attrTypeList = []; var attrList = []; var attrInfo; var extraAttrList = []; var extraAttrUserList = []; var extraAttrUserEditList = []; var userList = []; var extraAttrInfo; var totalCount = 0; var pageSize = 15; /** * 객체 초기화 */ this.init = function(){ initDropdownList(); initAttrList($('#sltAttrType option:first').val(), 'attrType'); initExtraAttrList(); //설명 글자수 이벤트 - core에 선언 self.checkDescBytes($txtExtraAttrDesc); addEvent(); if($('#table_attr tr[seq=0]')[0]==undefined){ $('#attrDetail').css('display', 'none'); $('#attrDetailEmpty').css('display', 'block'); }else{ $('#table_attr tr[seq=0]').click(); }; if($('#table_extraAttr tr[seq=0]')[0]==undefined){ $('#extraAttrDetail').css('display', 'none'); $('#extraAttrDetailEmpty').css('display', 'block'); }else{ $('#table_extraAttr tr[seq=0]').click(); } }; var initDropdownList = function(){ var opt = { url: $attrCrudServiceBaseUrl + "/getAttrTypeList.json", type : "post", async: false, dataType: "json", contentType: "application/json" } var success = function(result){ attrTypeList = result.attrTypeList; $sltAttrType.empty(); for(var i=0; i').clone().attr('value', attrTypeList[i].attrType).text(attrTypeList[i].attrTypeName); $('#sltAttrType').append(option); }; }; $sltAttrType.on('change', function(e){ /*getExtraAttrInfo(e.currentTarget.attributes.seq.value); $('#table_extraAttr tr').removeClass('active'); $(this).addClass('active');*/ $('#table_attr').empty(); initAttrList(e.currentTarget.value, 'attrType'); if(e.currentTarget.value=='work'){ $('#divUpperAttr').css('display', 'block'); initAttrList('duty', 'upperAttr'); }else{ $('#divUpperAttr').css('display', 'none'); } }); } var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; var initAttrList = function(attrType, sltType){ var opt = { url: $attrCrudServiceBaseUrl + "/getAttrList.json", type : "post", async: false, dataType: "json", contentType: "application/json", data: self.util.stringifyJson({ attrType: attrType }) } var success = function(result){ if(sltType=='attrType'){ attrList = result.attrList; $('#table_attr').empty(); $txtAttrId.val(''); $txtAttrName.val(''); $sltUpperAttr.val(''); attrInfo = {}; for(var i=0; i').clone().attr('seq', i).attr('attrSeq', attrList[i].attrSeq).attr('attrId', attrList[i].attrId); var tdAttrId = $('').clone().text(attrList[i].attrId); var tdAttrName = $('').clone().text(attrList[i].attrName); $('#table_attr').append(tr.append(tdAttrId).append(tdAttrName)); }; $('#table_attr tr').on('click', function(e){ getAttrInfo(e.currentTarget.attributes.seq.value); $('#table_attr tr').removeClass('active'); $(this).addClass('active'); }); }else{ var upperAttrList = result.attrList; $('#sltUpperAttr').empty(); var option = $('').clone().attr('value', '').text('선택'); $('#sltUpperAttr').append(option); for(var i=0; i').clone().attr('value', upperAttrList[i].attrId).text(upperAttrList[i].attrName); $('#sltUpperAttr').append(option); }; }; if($('#table_attr tr[seq=0]')==undefined){ $('#attrDetail').css('display', 'none'); $('#attrDetailEmpty').css('display', 'block'); }else{ $('#table_attr tr[seq=0]').click(); }; } var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; var initExtraAttrList = function(){ var opt = { url: $crudServiceBaseUrl + "/getList.json", type : "post", async: false, dataType: "json", contentType: "application/json" } var success = function(result){ extraAttrList = result; totalCount = result.totalCount; $('#table_extraAttr').empty(); for(var i=0; i').clone().attr('seq', i).attr('extraAttrSeq', extraAttrList[i].extraAttrSeq).attr('extraAttrId', extraAttrList[i].extraAttrId); var tdExtraAttrId = $('').clone().text(extraAttrList[i].extraAttrId); var tdExtraAttrName = $('').clone().text(extraAttrList[i].extraAttrName); $('#table_extraAttr').append(tr.append(tdExtraAttrId).append(tdExtraAttrName)); }; $('#table_extraAttr tr').on('click', function(e){ getExtraAttrInfo(e.currentTarget.attributes.seq.value); $('#table_extraAttr tr').removeClass('active'); $(this).addClass('active'); }); } var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; /** * 이벤트 등록 */ var addEvent = function(){ $('#btnNew_attr, #btnNewEmpty_attr').on('click', function(e){ newItemAttr(); }); $btnSave_attr.on('click', function(e){ saveItemAttr(); }); $btnRemove_attr.on('click', function(e){ removeItemAttr(); }); $('#btnNew_extraAttr, #btnNewEmpty_extraAttr').on('click', function(e){ newItemExtraAttr(); }); $btnSave_extraAttr.on('click', function(e){ saveItemExtraAttr(); }); $btnRemove_extraAttr.on('click', function(e){ removeItemExtraAttr(); }); $btnEditExtraAttrUser.on('click', function(e){ editExtraAttrUser(); }); $btnSaveExtraAttrUser.on('click', function(e){ confirmExtraAttrUser(); }); $btnSearch.on('click', function(e){ initUserList(1, $sltUser.val(), $txtSearch.val()); }); }; var getAttrInfo = function(seq){ $txtAttrId.attr('readonly', true); attrInfo = attrList[seq]; $txtAttrId.val(attrInfo.attrId); $txtAttrName.val(attrInfo.attrName); $sltUpperAttr.val(attrInfo.upperAttr); $('#attrDetail').css('display', 'block'); $('#attrDetailEmpty').css('display', 'none'); }; var newItemAttr = function(){ attrInfo = {}; $('#table_attr tr').removeClass('active'); $txtAttrId.attr('readonly', false); $txtAttrId.val(''); $txtAttrName.val(''); $sltUpperAttr.val(''); $('#attrDetail').css('display', 'block'); $('#attrDetailEmpty').css('display', 'none'); $txtAttrId.focus(); }; var saveItemAttr = function(){ var param = {}; if($txtAttrId.val()==''){ alert('아이디를 입력해주세요.'); return; }; if($txtAttrName.val()==''){ alert('이름을 입력해주세요.'); return; }; if($sltAttrType.val()=='work'&&$sltUpperAttr.val()==''){ alert('상위속성을 선택해주세요.'); return; }; if(attrInfo.attrSeq==undefined){ param = { attrSeq: null, attrId: $txtAttrId.val(), attrName: $txtAttrName.val(), attrType: $sltAttrType.val(), upperAttr: $sltAttrType.val()=='work'? $sltUpperAttr.val():null } }else{ param = { attrSeq: attrInfo.attrSeq, attrId: $txtAttrId.val(), attrName: $txtAttrName.val(), attrType: $sltAttrType.val(), upperAttr: $sltAttrType.val()=='work'? $sltUpperAttr.val():null } }; var opt = { url : $attrCrudServiceBaseUrl + "/save.json", type : "POST", data : self.util.stringifyJson(param), dataType : "json", contentType: "application/json" }; var success = function(data){ alert("저장 되었습니다"); initAttrList(data.attrType, 'attrType'); $('#table_attr tr[attrId='+data.attrId+']').click(); }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; var removeItemAttr = function(){ if($('#table_attr tr.active').length==0){ alert('삭제할 속성을 선택해주세요.'); return; }; if(confirm('해당 속성을 삭제하시겠습니까?')){ var param = {}; param = { attrSeq: attrInfo.attrSeq, attrId: attrInfo.attrId, attrType: attrInfo.attrType }; var opt = { url : $attrCrudServiceBaseUrl + "/remove.json", type : "POST", data : self.util.stringifyJson(param), contentType: "application/json" }; var success = function(data){ alert("삭제 되었습니다"); initAttrList($sltAttrType.val(), 'attrType'); attrInfo = {}; $('#attrDetail').css('display', 'none'); $('#attrDetailEmpty').css('display', 'block'); }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; }; var getExtraAttrInfo = function(seq){ extraAttrInfo = extraAttrList[seq]; $txtExtraAttrId.attr('readonly', true); $txtExtraAttrId.val(extraAttrInfo.extraAttrId); $txtExtraAttrName.val(extraAttrInfo.extraAttrName); $txtExtraAttrDesc.val(extraAttrInfo.extraAttrDesc); var opt = { url: $crudServiceBaseUrl + "/getExtraAttrUserList.json", type : "post", async: false, dataType: "json", contentType: "application/json", data: self.util.stringifyJson({ extraAttrId: extraAttrInfo.extraAttrId }) } var success = function(result){ extraAttrUserList = result; $('#table_extraAttrUser_view').empty(); for(var i=0; i').clone().attr('seq', i); var tdUserId = $('').clone().text(extraAttrUserList[i].userId); var tdUserName = $('').clone().text(extraAttrUserList[i].userName); var tdUserHospital = $('').clone().text(extraAttrUserList[i].hospitalName==null? '': extraAttrUserList[i].hospitalName); var tdUserDuty = $('').clone().text(extraAttrUserList[i].dutyName==null? '': extraAttrUserList[i].dutyName); var tdUserWork = $('').clone().text(extraAttrUserList[i].workName==null? '': extraAttrUserList[i].workName); $('#table_extraAttrUser_view').append(tr.append(tdUserId).append(tdUserName).append(tdUserHospital).append(tdUserDuty).append(tdUserWork)); } } var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); $('#extraAttrDetail').css('display', 'block'); $('#extraAttrDetailEmpty').css('display', 'none'); }; var saveItemExtraAttr = function(){ var param = {}; if($txtExtraAttrId.val()==''){ alert('아이디를 입력해주세요.'); return; }; if($txtExtraAttrName.val()==''){ alert('이름을 입력해주세요.'); return; }; if(extraAttrInfo.extraAttrId==undefined){ param = { extraAttrId: $txtExtraAttrId.val(), extraAttrName: $txtExtraAttrName.val(), extraAttrDesc: $txtExtraAttrDesc.val(), addedNode: true, extraAttrUserList: extraAttrUserList, extraAttrSeq: extraAttrUserList.length+1 } }else{ param = { extraAttrId: extraAttrInfo.extraAttrId, extraAttrName: $txtExtraAttrName.val(), extraAttrDesc: $txtExtraAttrDesc.val(), addedNode: extraAttrInfo.addedNode, extraAttrUserList: extraAttrUserList, extraAttrSeq: extraAttrInfo.extraAttrSeq } }; var opt = { url : $crudServiceBaseUrl + "/save.json", type : "POST", data : self.util.stringifyJson(param), dataType : "json", contentType: "application/json" }; var success = function(data){ alert("저장 되었습니다"); initExtraAttrList(); $('#table_extraAttr tr[extraAttrId='+data.extraAttrId+']').click(); }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; var newItemExtraAttr = function(){ extraAttrInfo = {}; $('#table_extraAttr tr').removeClass('active'); $txtExtraAttrId.attr('readonly', false); $txtExtraAttrId.val(''); $txtExtraAttrName.val(''); $txtExtraAttrDesc.val(''); extraAttrUserList = []; extraAttrUserEditList = []; $('#table_extraAttrUser_view').empty(); $('#extraAttrDetail').css('display', 'block'); $('#extraAttrDetailEmpty').css('display', 'none'); $txtExtraAttrId.focus(); }; var removeItemExtraAttr = function(){ if($('#table_extraAttr tr.active').length==0){ alert('삭제할 속성을 선택해주세요.'); return; }; if(confirm('해당 추가속성을 삭제하시겠습니까?')){ var param = {extraAttrId: extraAttrInfo.extraAttrId}; var opt = { url : $crudServiceBaseUrl + "/remove.json", type : "POST", data : self.util.stringifyJson(param), dataType : "json", contentType: "application/json" }; var success = function(data){ alert("삭제 되었습니다"); initExtraAttrList(); $('#extraAttrDetail').css('display', 'none'); $('#extraAttrDetailEmpty').css('display', 'block'); }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; } var editExtraAttrUser = function(){ $sltUser.val($('#sltUser option:first').val()); $txtSearch.val(''); initUserList(1, '', ''); $('#table_extraAttrUser').empty(); for (var i = 0; i < extraAttrUserList.length; i++) { var tr = $('').clone(); var tdUserId = $('').clone().text(extraAttrUserList[i].userId); var tdUserName = $('').clone().text(extraAttrUserList[i].userName); var tdHospital = $('').clone().text(extraAttrUserList[i].hospitalName==null? '': extraAttrUserList[i].hospitalName); var tdDuty = $('').clone().text(extraAttrUserList[i].dutyName==null? '': extraAttrUserList[i].dutyName); var tdWork = $('').clone().text(extraAttrUserList[i].workName==null? '': extraAttrUserList[i].workName); var tdEdit = $('').clone().append( ''); $('#table_extraAttrUser').append(tr.append(tdUserId).append(tdUserName).append(tdHospital).append(tdDuty).append(tdWork).append(tdEdit)); }; $('[id*=btnRemoveExtraAttrUser_]').on('click', function(e) { removeExtraAttrUser(e); }); extraAttrUserEditList = []; $.extend(extraAttrUserEditList, extraAttrUserList); // 객체 복사, 위의 방식으로하면 객체 공유가 되어버림! $('#addExtraAttrModal').modal('show'); }; var initUserList = function(page, selectType, searchText){ userList = []; var opt = { url: $userAttrCrudServiceBaseUrl + "/getList.json", type: "post", dataType: "json", async: false, contentType: "application/json", data: self.util.stringifyJson({ pageSize: pageSize, page: page, selectUserType: selectType, searchText: searchText, hospitalId: "", dutyId: "", workId: "" }) }; var success = function(result){ userList = result.data; totalCount = result.totalCount; $('#table_user').empty(); for(var i=0; i').clone().attr('seq', i).attr('rnum', userList[i].rnum); var tdUserId = $('').clone().text(userList[i].userId); var tdUserName = $('').clone().text(userList[i].userName); var tdHospital = $('').clone().text(userList[i].hospitalName==null? '':userList[i].hospitalName); var tdDuty = $('').clone().text(userList[i].dutyName==null? '': userList[i].dutyName); var tdWork = $('').clone().text(userList[i].workName==null? '': userList[i].workName); var tdEdit = $('').clone().append( ''); $('#table_user').append(tr.append(tdUserId).append(tdUserName).append(tdHospital).append(tdDuty).append(tdWork).append(tdEdit)); }; $('[id*=btnAddExtraAttrUser_]').on('click', function(e) { addExtraAttrUser(e); }); if(page<11){ $('#ulPagination').empty(); if(totalCount>0){ for(j=0; j').clone(); var a = $('').clone().attr('seq', j+1).text(j+1); var span = $('').clone().addClass('sr-only'); $('#ulPagination').append(li.attr('id', 'page_'+(j+1)).append(a.append(span))); }else if(j==10){ $('#ulPagination').append('
  • >>
  • '); $('#next_'+(j+1)).on('click', function(e){ next(e); }); }else {}; }; }else{ var li = $('
  • ').clone(); var a = $('').clone().attr('seq', 1).text(1); var span = $('').clone().addClass('sr-only'); $('#ulPagination').append(li.attr('id', 'page_'+(1)).append(a.append(span))); }; }; $('#ulPagination li[id*="page_"]').removeClass('active'); if($('#page_'+page)!=null) $('#page_'+page).addClass('active'); $('#ulPagination li[id*="page_"]').unbind(); $('#ulPagination li[id*="page_"]').on('click', function(e){ initUserList(Number(e.currentTarget.id.split('_')[1]), '', ''); }); }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; var previous = function(e){ var startNo = Number(e.currentTarget.id.split('_')[1]); if(startNo>Math.ceil(totalCount/pageSize)) return; $('#ulPagination').empty(); if(startNo-10>1){ $('#ulPagination').append('
  • <<
  • '); $('#previous_'+(startNo-10)).on('click', function(e){ previous(e); }); }; for(i=startNo-10; i'+i+''); $('#ulPagination li[id*="page_"]').unbind(); $('#ulPagination li[id*="page_"]').on('click', function(e){ initUserList(Number(e.currentTarget.id.split('_')[1]), '', ''); }); if((startNo)==(i+1)){ $('#ulPagination').append('
  • >>
  • '); $('#next_'+(i+1)).on('click', function(e){ next(e); }); }; }; }; var next = function(){ var startNo = Number(event.currentTarget.id.split('_')[1]); if(startNo>Math.ceil(totalCount/pageSize)) return; $('#ulPagination').empty(); $('#ulPagination').append('
  • <<
  • '); $('#previous_'+startNo).on('click', function(e){ previous(e); }); for(i=startNo; iMath.ceil(totalCount/pageSize)) return; $('#ulPagination').append('
  • '+i+'
  • '); $('#ulPagination li[id*="page_"]').unbind(); $('#ulPagination li[id*="page_"]').on('click', function(e){ initUserList(Number(e.currentTarget.id.split('_')[1]), '', ''); }); if((startNo+10)==(i+1) && i!=Math.ceil(totalCount/pageSize)){ $('#ulPagination').append('
  • >>
  • '); $('#next_'+(i+1)).on('click', function(e){ next(e); }); }; }; }; var addExtraAttrUser = function(e){ var userInfo = userList[e.currentTarget.id.split('_')[1]]; for(i=0; i').clone(); var tdUserId = $('').clone().text(userInfo.userId); var tdUserName = $('').clone().text(userInfo.userName); var tdHospital = $('').clone().text(userInfo.hospitalName==null? '': userInfo.hospitalName); var tdDuty = $('').clone().text(userInfo.dutyName==null? '': userInfo.dutyName); var tdWork = $('').clone().text(userInfo.workName==null? '': userInfo.workName); var tdEdit = $('').clone().append( ''); $('#table_extraAttrUser').append(tr.append(tdUserId).append(tdUserName).append(tdHospital).append(tdDuty).append(tdWork).append(tdEdit)); $('[id*=btnRemoveExtraAttrUser_]').unbind(); $('[id*=btnRemoveExtraAttrUser_]').on('click', function(e) { removeExtraAttrUser(e); }); }; var removeExtraAttrUser = function(e){ $('#table_extraAttrUser [id*=trExtraAttrUser_' + e.currentTarget.id.split('_')[1]).remove(); for(var i=0; i').clone().attr('seq', i); var tdUserId = $('').clone().text(extraAttrUserEditList[i].userId); var tdUserName = $('').clone().text(extraAttrUserEditList[i].userName); var tdUserHospital = $('').clone().text(extraAttrUserEditList[i].hospitalName==null? '': extraAttrUserEditList[i].hospitalName); var tdUserDuty = $('').clone().text(extraAttrUserEditList[i].dutyName==null? '': extraAttrUserEditList[i].dutyName); var tdUserWork = $('').clone().text(extraAttrUserEditList[i].workName==null? '': extraAttrUserEditList[i].workName); $('#table_extraAttrUser_view').append(tr.append(tdUserId).append(tdUserName).append(tdUserHospital).append(tdUserDuty).append(tdUserWork)); } ; extraAttrUserList = []; $.extend(extraAttrUserList, extraAttrUserEditList); // 객체 복사 }; /** * 트리 아이템 reload 이벤트 * @private */ var reloadItem = function(e){ kendo.ui.progress( $wrapper, true ); var opt = { url : $crudServiceBaseUrl + "/cacheReload.json", type : "POST", contentType: "application/json", complete : function(){ kendo.ui.progress( $wrapper, false ); } }; var success = function(data){ if( data === 1 ) { alert("갱신 되었습니다"); } else { alert( "수행 중 에러가 발생하였습니다" ); } }; var error = function(xhr,d,t){ console.log(xhr); console.log(t); }; self.ajaxAdmin( opt, success, error ); }; }; var rowNum = 0; function resetRowNum(){ rowNum = 0; } function getNum(){ return ++rowNum; }