userAttr.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /**
  2. * admin/vers
  3. */
  4. var mcare_admin_manager = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $searchBtn = $("#searchBtn"),
  11. $searchText = $("#search-text"),
  12. $selectHospital = $("#select-hospital"),
  13. $selectDuty = $("#select-duty"),
  14. $selectWork = $("#select-work"),
  15. $selectUser = $("#select-user"),
  16. $btnAttrCreate = $("#btnAttrCreate"),
  17. $btnPopAddLine = $("#btnPopAddLine"),
  18. $btnPopAddLineCancel = $('#btnPopAddLineCancel'),
  19. $crudServiceBaseUrl = contextPath + "/admin/userAttr";
  20. // 검색 조건 데이터
  21. var selectHospitalVal;
  22. var selectDutyVal;
  23. var selectWorkVal;
  24. var selectUserType;
  25. var userVal;
  26. /**
  27. * 초기화
  28. */
  29. this.init = function(){
  30. initGrid();
  31. initDropDown();
  32. addEvent();
  33. };
  34. /**
  35. * 이벤트 등록
  36. */
  37. var addEvent = function(){
  38. $searchBtn.on("click", function(e) {
  39. searchUserAttr(e);
  40. });
  41. $selectHospital.on("change", function(e) {
  42. selectHospitalVal = $selectHospital.val();
  43. });
  44. $selectDuty.on("change", function(e) {
  45. selectDutyVal = $selectDuty.val();
  46. });
  47. $selectWork.on("change", function(e) {
  48. selectWorkVal = $selectWork.val();
  49. });
  50. $btnAttrCreate.on("click", function(e){
  51. attrPopupOpen();
  52. });
  53. $btnPopAddLine.on("click", function(e){
  54. popAddLine();
  55. });
  56. $btnPopAddLineCancel.on("click", function(e){
  57. popAddLineCancel();
  58. });
  59. };
  60. var hospitalList;
  61. var dutyList;
  62. var workList;
  63. var searchTypeList;
  64. var initDropDown = function(){
  65. $.ajax ({
  66. url : '/mcare-plus/admin/attr/getAttrTypeList.json',
  67. type : 'POST',
  68. success: function(result){
  69. hospitalList = result.hospital;
  70. dutyList = result.duty;
  71. workList = result.work;
  72. searchTypeList = [{attrId: 'userId', attrName: '아이디'},{attrId: 'userName', attrName: '이름'}];
  73. $selectHospital.kendoDropDownList({
  74. dataSource: hospitalList,
  75. dataTextField: "attrName",
  76. dataValueField: "attrId",
  77. optionLabel: {
  78. attrId: "",
  79. attrName: "전체"
  80. }
  81. }).data("kendoDropDownList").select(0);
  82. $selectDuty.kendoDropDownList({
  83. dataSource: dutyList,
  84. dataTextField: "attrName",
  85. dataValueField: "attrId",
  86. optionLabel: {
  87. attrId: "",
  88. attrName: "전체"
  89. },
  90. change: selectWorkChange
  91. }).data("kendoDropDownList").select(0);
  92. $selectWork.kendoDropDownList({
  93. dataSource: workList,
  94. dataTextField: "attrName",
  95. dataValueField: "attrId",
  96. optionLabel: {
  97. attrId: "",
  98. attrName: "전체"
  99. }
  100. }).data("kendoDropDownList").select(0);
  101. $selectUser.kendoDropDownList({
  102. dataSource: searchTypeList,
  103. dataTextField: "attrName",
  104. dataValueField: "attrId",
  105. optionLabel: {
  106. attrId: "",
  107. attrName: "전체"
  108. }
  109. }).data("kendoDropDownList").select(0);
  110. }
  111. })
  112. }
  113. function selectWorkChange(e){
  114. var temWorkList=[];
  115. for(var i=0; i<workList.length; i++){
  116. if($selectDuty.val()==workList[i].upperAttr){
  117. temWorkList.push(workList[i]);
  118. };
  119. };
  120. $("#select-work").kendoDropDownList({
  121. dataSource: temWorkList,
  122. dataTextField: "attrName",
  123. dataValueField: "attrId",
  124. optionLabel: {
  125. attrId: "",
  126. attrName: "전체"
  127. },
  128. change: selectWorkChange
  129. }).data("kendoDropDownList").select(0);
  130. }
  131. // 데이터소스
  132. var dataSource = new kendo.data.DataSource({
  133. transport: {
  134. read: function(options) {
  135. $.ajax({
  136. url: $crudServiceBaseUrl + "/getList.json",
  137. method: "POST",
  138. dataType: "json",
  139. contentType : "application/json",
  140. data: self.util.stringifyJson( {
  141. "take":options.data.take,
  142. "skip":options.data.skip,
  143. "page":options.data.page,
  144. "pageSize":options.data.pageSize,
  145. "sort":options.data.sort,
  146. "hospitalId":$("#select-hospital").val(),
  147. "dutyId":$("#select-duty").val(),
  148. "workId":$("#select-work").val(),
  149. "selectUserType":$("#select-user").val(),
  150. "searchText":$("#search-text").val()
  151. }),
  152. success: function(result) {
  153. options.success(result);
  154. gridReadComplete(result);
  155. }
  156. });
  157. },
  158. update: function(options) {
  159. console.log(options.data.models[0]);
  160. var updateData = options.data.models[0];
  161. $.ajax({
  162. url: $crudServiceBaseUrl + "/save.json",
  163. method: "POST",
  164. dataType: "json",
  165. contentType : "application/json",
  166. data: self.util.stringifyJson({
  167. "userId": updateData.userId,
  168. "userName": updateData.userName,
  169. "userAttrOrder": updateData.userAttrOrder,
  170. "hospitalId": updateData.hospitalId,
  171. "dutyId": updateData.dutyId,
  172. "workId": updateData.workId,
  173. "addedNode": updateData.addedNode==undefined? false: updateData.addedNode,
  174. }),
  175. success: function(result) {
  176. alert('저장되었습니다');
  177. options.success(result);
  178. gridActionComplete(result);
  179. }
  180. });
  181. },
  182. destroy: function(options) {
  183. console.log(options);
  184. var deleteData = options.data.models[0];
  185. if(deleteData.userAttrOrder==1){
  186. alert('사용자는 최소 하나의 속성을 가져야 합니다.');
  187. $("#grid").data("kendoGrid").cancelChanges();
  188. return;
  189. };
  190. if(deleteData.addedNode!=true){
  191. $.ajax ({
  192. url : $crudServiceBaseUrl + "/remove.json",
  193. type : 'POST',
  194. data: self.util.stringifyJson({
  195. "userId": deleteData.userId,
  196. "userAttrOrder": deleteData.userAttrOrder
  197. }),
  198. success: function(result) {
  199. if(result.msg==undefined){
  200. alert('삭제되었습니다');
  201. options.success(result);
  202. gridActionComplete(result);
  203. }else{
  204. alert(result.msg);
  205. $("#grid").data("kendoGrid").cancelChanges();
  206. }
  207. }
  208. })
  209. };
  210. }
  211. },
  212. batch: true,
  213. pageSize: 13,
  214. serverPaging: true,
  215. serverSorting: true,
  216. schema: {
  217. data: "data",
  218. total: "totalCount",
  219. model: {
  220. id: "rnum",
  221. fields: {
  222. userId: { type: "string", nullable: false, editable: false, validation: { required: true }},
  223. userName: { type: "string", nullable: false, editable: false, validation: { required: true }},
  224. userAttrOrder: { type: "string", nullable: false, editable: false, validation: { required: true }},
  225. hospitalId: { type: "string", nullable: false, validation: { required: true }},
  226. hospitalName: { type: "string" },
  227. dutyId: { type: "string", nullable: false,validation: { required: true }},
  228. dutyName: { type: "string" },
  229. workId: { type: "string", nullable: false, validation: { required: true }},
  230. workName: { type: "string" }
  231. }
  232. }
  233. }
  234. });
  235. /**
  236. * 그리드 이벤트 동작 complate
  237. * @private
  238. */
  239. function gridActionComplete( result ){
  240. if(result.msg !=undefined){
  241. alert(result.msg);
  242. }else{
  243. $grid.data("kendoGrid").dataSource.read();
  244. };
  245. };
  246. /**
  247. * 그리드 이벤트 동작 complate
  248. * @private
  249. */
  250. function gridReadComplete( result ){
  251. if(result.msg !=undefined){
  252. alert(result.msg);
  253. if( result.type == "AuthException" ){
  254. window.location.href = contextPath + "/admin/logout.page";
  255. return;
  256. }
  257. };
  258. };
  259. /**
  260. * 그리드 초기화
  261. */
  262. var initGrid = function(){
  263. // 그리드 옵션
  264. var grid = $("#grid").kendoGrid({
  265. dataSource: dataSource,
  266. pageable: true,
  267. sortable: true,
  268. resizable: true,
  269. height: 620,
  270. columns: [
  271. { field: "userId", title: "아이디", width: 80, attributes: {style: "text-align: center;"}}
  272. ,{ field: "userName", title: "이름", width: 100, attributes: {style: "text-align: center;"}}
  273. ,{ field: "userAttrOrder", title: "순서", width: 50, attributes: {style: "text-align: center;"}}
  274. ,{ field: "hospitalId", title: "소속", width: 120, attributes: {style: "text-align: center;"}, editor: hospitalDropDownEditor, template: "#=hospitalName#"}
  275. ,{ field: "dutyId", title: "직무", width: 120, attributes: {style: "text-align: center;"}, editor: dutyDropDownEditor, template: "#=dutyName#"}
  276. ,{ field: "workId", title: "업무", width: 80, attributes: {style: "text-align: center;"}, editor: workDropDownEditor, template: "#=workName#"}
  277. ,{ command: [{name:"edit",text:{edit: "편집", update: "저장", cancel: "취소"}},{name:"destroy",text:"삭제"}], title: "&nbsp;", width: 170, attributes: {style: "text-align: center;"}}
  278. ],
  279. editable: {
  280. mode: "inline",
  281. confirmation:"정말 삭제하시겠습니까?"
  282. },
  283. edit: function(e) {
  284. if (!e.model.isNew()) {
  285. /*$("select[id=pop-select-hospital]").parent().hide();*/
  286. }else{
  287. /*var editWindow = this.editable.element.data("kendoWindow");
  288. $('.k-edit-form-container').css('width', '580px');
  289. editWindow.wrapper.css({top: "20%" });
  290. $("div[id=createDataBox]").hide();*/
  291. }
  292. },
  293. change: function(data, arg){
  294. $('input[name=attrAddUser]').removeAttr("checked");
  295. $('input[name=attrAddUser]')[$(this.select()).index()].checked=true
  296. var selected = this.select(),
  297. item = this.dataItem(selected);
  298. createData = item;
  299. },
  300. dataBound: function () {
  301. var rowCount = $grid.find( ".k-grid-content tbody tr" ).length;
  302. if( rowCount < dataSource._take ) {
  303. var addRows = dataSource._take - rowCount;
  304. for( var i = 0; i < addRows; i++ ) {
  305. $grid.find( ".k-grid-content tbody" )
  306. .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  307. }
  308. }
  309. $('.k-grid-edit', grid.element).on("click", function () {
  310. //추가할 데이터가 저장되지 않은 경우
  311. if($('#grid .k-grid-edit-row').length>0
  312. &&$('#grid').data("kendoGrid").dataSource.data()[0].addedNode==true){
  313. alert('저장하지 않은 데이터가 있습니다.' );
  314. return false;
  315. };
  316. });
  317. }
  318. }).data("kendoGrid");
  319. /*$('.k-grid-add', grid.element).on("click", function () {
  320. // Temporarily set editable to "popup"
  321. if($(".k-grid-cancel").length>0){
  322. $(".k-grid-cancel").click();
  323. };
  324. grid.options.editable = {
  325. mode: "popup",
  326. template: $('#popTemplate').html()
  327. };
  328. });*/
  329. };
  330. function hospitalDropDownEditor(container, options) {
  331. $('<input required name="' + options.field + '"/>')
  332. .appendTo(container)
  333. .kendoDropDownList({
  334. autoBind: false,
  335. dataTextField: "attrName",
  336. dataValueField: "attrId",
  337. dataSource: hospitalList,
  338. optionLabel: {
  339. attrId: "",
  340. attrName: "선택"
  341. }
  342. }).data("kendoDropDownList").select(0);
  343. };
  344. function dutyDropDownEditor(container, options) {
  345. $('<input required name="' + options.field + '"/>')
  346. .appendTo(container)
  347. .kendoDropDownList({
  348. autoBind: false,
  349. dataTextField: "attrName",
  350. dataValueField: "attrId",
  351. change: selectChangeDuty,
  352. dataSource: dutyList,
  353. optionLabel: {
  354. attrId: "",
  355. attrName: "선택"
  356. }
  357. }).data("kendoDropDownList").select(0);
  358. };
  359. function selectChangeDuty(e){
  360. var options= {model:{dutyId: e.sender._selectedValue}};
  361. var container = $('.k-grid-edit-row [data-container-for=workId]');
  362. var temWorkList=[];
  363. for(var i=0; i<workList.length; i++){
  364. if(options.model.dutyId==workList[i].upperAttr){
  365. temWorkList.push(workList[i]);
  366. };
  367. };
  368. container.find('input').data("kendoDropDownList").dataSource.data(temWorkList);
  369. };
  370. function workDropDownEditor(container, options) {
  371. var temWorkList=[];
  372. for(var i=0; i<workList.length; i++){
  373. if(options.model.dutyId==workList[i].upperAttr){
  374. temWorkList.push(workList[i]);
  375. };
  376. };
  377. $('<input required name="' + options.field + '"/>')
  378. .appendTo(container)
  379. .kendoDropDownList({
  380. autoBind: false,
  381. dataTextField: "attrName",
  382. dataValueField: "attrId",
  383. dataSource: temWorkList,
  384. optionLabel: {
  385. attrId: "",
  386. attrName: "선택"
  387. }
  388. }).data("kendoDropDownList").select(0);
  389. };
  390. function searchUserAttr(e) {
  391. $grid.data("kendoGrid").dataSource.read();
  392. };
  393. /**
  394. * 그리드 이벤트 동작 complate
  395. * @private
  396. */
  397. function popGridActionComplete( result ){
  398. if(result.msg !=undefined){
  399. alert(result.msg);
  400. }else{
  401. $('#grid3').data("kendoGrid").dataSource.read();
  402. };
  403. };
  404. /**
  405. * 그리드 이벤트 동작 complate
  406. * @private
  407. */
  408. function popGridReadComplete( result ){
  409. if(result.msg !=undefined){
  410. alert(result.msg);
  411. if( result.type == "AuthException" ){
  412. window.location.href = contextPath + "/admin/logout.page";
  413. return;
  414. }
  415. };
  416. };
  417. /**
  418. * 그리드 초기화
  419. */
  420. var popInitGrid = function(){
  421. // 그리드 옵션
  422. var option = {
  423. dataSource: popDataSource,
  424. pageable: true,
  425. sortable: true,
  426. resizable: true,
  427. selectable: true,
  428. height: 400,
  429. columns: [
  430. { title: "", width: 30, template: '<input type="radio" name="attrAddUser"/>'}
  431. ,{ field: "userId", title: "아이디", width: 80, attributes: {style: "text-align: center;"}}
  432. ,{ field: "userName", title: "이름", width: 100, attributes: {style: "text-align: center;"}}
  433. ,{ field: "userAttrOrder", title: "순서", width: 50, hidden: true, attributes: {style: "text-align: center;"}}
  434. ,{ field: "hospitalId", title: "소속ID", width: 120, hidden: true, attributes: {style: "text-align: center;"}}
  435. ,{ field: "hospitalName", title: "소속", width: 120, attributes: {style: "text-align: center;"}}
  436. ,{ field: "dutyId", title: "직무ID", width: 120, hidden: true, attributes: {style: "text-align: center;"}}
  437. ,{ field: "dutyName", title: "직무", width: 120, attributes: {style: "text-align: center;"}}
  438. ,{ field: "workId", title: "업무ID", width: 80, hidden: true, attributes: {style: "text-align: center;"}}
  439. ,{ field: "workName", title: "업무", width: 80, attributes: {style: "text-align: center;"}}
  440. ],
  441. change: function(data, arg){
  442. $('input[name=attrAddUser]').removeAttr("checked");
  443. $('input[name=attrAddUser]')[$(this.select()).index()].checked=true
  444. var selected = this.select(),
  445. item = this.dataItem(selected);
  446. createData = item;
  447. },
  448. dataBound: function () {
  449. var rowCount = $('#grid3').find( ".k-grid-content tbody tr" ).length;
  450. if( rowCount < popDataSource._take ) {
  451. var addRows = popDataSource._take - rowCount;
  452. for( var i = 0; i < addRows; i++ ) {
  453. $('#grid3').find( ".k-grid-content tbody" )
  454. .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  455. }
  456. }
  457. }
  458. };
  459. //그리드 초기화
  460. self.grid( $('#grid3'), option );
  461. };
  462. var popDataSource = new kendo.data.DataSource({
  463. transport: {
  464. read: {
  465. url: $crudServiceBaseUrl + "/getList.json",
  466. method: "post",
  467. dataType: "json",
  468. contentType: "application/json",
  469. complete: popGridReadComplete
  470. },
  471. parameterMap: function parameterMap( options, operation ){
  472. kendo.ui.progress($("#grid3"), true);
  473. var param = $.extend(true, {}, options, {
  474. hospitalId: $('#pop-select-hospital').val(),
  475. dutyId : $('#pop-select-duty').val(),
  476. workId : $('#pop-select-work').val(),
  477. selectUserType : $('#pop-select-user').val(),
  478. searchText : $('#pop-search-text').val(),
  479. userAttrOrder: "1"
  480. }, null);
  481. console.log(self.util.stringifyJson( param ));
  482. return self.util.stringifyJson( param );
  483. }
  484. },
  485. pageSize: 10,
  486. serverPaging: true,
  487. serverSorting: true,
  488. schema: {
  489. data: "data",
  490. total: "totalCount",
  491. model: {
  492. id: "rnum",
  493. fields: {
  494. userId: { type: "string", nullable: false, validation: { required: true }},
  495. userName: { type: "string", nullable: false, validation: { required: true }},
  496. userAttrOrder: { type: "string", nullable: false, validation: { required: true }},
  497. hospitalId: { type: "string", nullable: false, validation: { required: true }},
  498. dutyId: { type: "string", nullable: false,validation: { required: true }},
  499. workId: { type: "string", nullable: false, validation: { required: true }}
  500. }
  501. }
  502. }
  503. });
  504. function popSearchUserAttr(e) {
  505. popDataSource.page(1);
  506. }
  507. function setWidth(el)
  508. {
  509. var d = el;
  510. if (d.data("kendoDropDownList") !== undefined) {
  511. var p = d.data("kendoDropDownList").popup.element;
  512. var w = p.css("visibility", "hidden").show().outerWidth() + 20;
  513. p.hide().css("visibility", "visible");
  514. var kw = d.closest(".k-widget");
  515. if (kw.width() < w) {
  516. d.data("kendoDropDownList").list.width(100);
  517. }
  518. }
  519. }
  520. function attrPopupOpen(e){
  521. if($('#grid .k-grid-edit-row').length>0){
  522. alert('저장하지 않은 데이터가 있습니다.' );
  523. return;
  524. };
  525. popInitGrid();
  526. $("#pop-search").on("click", function(e) {
  527. popSearchUserAttr(e);
  528. });
  529. $("#pop-select-hospital").width(100).kendoDropDownList({
  530. dataSource: hospitalList,
  531. dataTextField: "attrName",
  532. dataValueField: "attrId",
  533. optionLabel: {
  534. attrName: "전체",
  535. attrId: ""
  536. }
  537. }).data("kendoDropDownList").select(0);
  538. $("#pop-select-duty").width(100).kendoDropDownList({
  539. dataSource : dutyList,
  540. dataTextField: "attrName",
  541. dataValueField: "attrId",
  542. optionLabel: {
  543. attrName: "전체",
  544. attrId: ""
  545. }
  546. }).data("kendoDropDownList").select(0);
  547. $("#pop-select-work").width(100).kendoDropDownList({
  548. dataSource : workList,
  549. dataTextField: "attrName",
  550. dataValueField: "attrId",
  551. optionLabel: {
  552. attrName: "전체",
  553. attrId: ""
  554. }
  555. }).data("kendoDropDownList").select(0);
  556. $("#pop-select-user").width(100).kendoDropDownList({
  557. dataSource : searchTypeList,
  558. dataTextField: "attrName",
  559. dataValueField: "attrId",
  560. optionLabel: {
  561. attrName: "전체",
  562. attrId: ""
  563. }
  564. }).data("kendoDropDownList").select(0);
  565. $("#attrCreatePop").kendoWindow({
  566. modal: true,
  567. title: "사용자 속성 추가",
  568. width:600,
  569. position:{
  570. top:"15%",
  571. left:"35%"
  572. }
  573. }).data("kendoWindow").center().open();
  574. };
  575. function popAddLine(e){
  576. $('#grid').data("kendoGrid").dataSource.insert(0, {
  577. "dutyId" : "",
  578. "dutyName" : "",
  579. "hospitalId" : "",
  580. "hospitalName": "",
  581. "id": createData.userId,
  582. "userAttrOrder": createData.lastOrder+1,
  583. "userId": createData.userId,
  584. "userName": createData.userName,
  585. "workId": "",
  586. "workName": "",
  587. "addedNode": true
  588. });
  589. $('.k-grid-edit')[0].click();
  590. $("#attrCreatePop").data("kendoWindow").close();
  591. $('.k-grid-cancel').on('click', function(e){
  592. $('#grid').data("kendoGrid").dataSource.remove($('#grid').data("kendoGrid").dataSource.data()[0]);
  593. });
  594. };
  595. function popAddLineCancel(e){
  596. $("#attrCreatePop").data("kendoWindow").close();
  597. }
  598. };