auth.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. * admin/menu
  3. */
  4. var mcare_admin_auth = function( language_code ){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //언어코드
  9. var DEFAULT_LANGUAGE = language_code;
  10. //변수
  11. var $wrapper = $(".main-wrapper #wrapper"),
  12. $addItem = $("#add-item"),
  13. $saveItem = $("#save-item"),
  14. $reloadItem = $("#reload-item"),
  15. $removeItem = $("#remove-item"),
  16. $deselectItem = $("#deselect-item"),
  17. $treeView = $("#tree-view"),
  18. $addAttrList = $("#addAttrList"),
  19. $minusAttrList = $("#minusAttrList")
  20. $authDesc = $("#authDesc");
  21. $crudServiceBaseUrl = contextPath + "/admin/auth"
  22. $attrCrudServiceBaseUrl = contextPath + "/admin/attr"; //속성 관련 요청을 위해 별도로 작성
  23. var attrTypes;
  24. var hospitalAttr;
  25. var dutyAttr;
  26. var workAttr;
  27. var extraAttr;
  28. var attrs = null;
  29. //트리
  30. this.treeView;
  31. // this.addAttrListGrid;
  32. // this.minusAttrListGrid = null;
  33. this.addAttrList;
  34. this.minusAttrList;
  35. /**
  36. * 객체 초기화
  37. */
  38. this.init = function(){
  39. // 왼쪽이랑 오른쪽 구분
  40. initSplitter();
  41. // 왼쪽 트리
  42. initTree();
  43. //설명 글자수 이벤트 - core에 선언
  44. self.checkDescBytes($authDesc);
  45. addEvent();
  46. initAttrTypes();
  47. initGrid();
  48. };
  49. /**
  50. * 이벤트 등록
  51. */
  52. var addEvent = function(){
  53. // 아이템 생성
  54. $addItem.on("click", function(e) {
  55. addItem(e);
  56. });
  57. // 아이템 저장
  58. $saveItem.on("click",function(e) {
  59. saveItem(e);
  60. });
  61. // 아이템 갱신 (to 모바일 서버)
  62. $reloadItem.on("click",function(e) {
  63. reloadItem(e);
  64. });
  65. // 아이템 삭제
  66. $removeItem.on("click",function(e) {
  67. removeItem(e);
  68. });
  69. // 아이템 선택 해제
  70. $deselectItem.on("click",function(e) {
  71. deselectItem(e);
  72. });
  73. };
  74. // add 랑 minus 랑 따로 데이터소스를 정의
  75. var addAuthAttrDataSource = new kendo.data.DataSource({
  76. transport: {
  77. read: function(options) {
  78. $.ajax({
  79. url: $crudServiceBaseUrl + "/getAuthAttrList.json",
  80. method: "get",
  81. dataType: "json",
  82. data: {authId: self.selectedAuthId, authType : 'add'},
  83. success: function(result) {
  84. options.success(result);
  85. }
  86. });
  87. },
  88. create: function(e) {
  89. e.success();
  90. },
  91. destroy: {},
  92. parameterMap: function( options, operation ) {
  93. if( operation === "read" ){
  94. return {authId: self.selectedAuthId, authType : 'add'};
  95. };
  96. }
  97. },
  98. batch: true,
  99. schema: {
  100. data: function(response) {
  101. return response;
  102. },
  103. // 요게 서버에서 속성들을 내려주는 데이터구조
  104. model: {
  105. id: "authAttrSeq",
  106. fields: {
  107. attrName: { type: "string", editable: true, validation: { required: false }},
  108. attrTypeName: { type: "string", editable: true, validation: { required: false }},
  109. authAttrId: { type: "string", editable: true, validation: { required: false }},
  110. authAttrSeq: { type: "string"},
  111. authAttrType: { type: "string", editable: true, validation: { required: false }},
  112. authId: { type: "string"},
  113. authType: { type: "string"}
  114. }
  115. }
  116. }
  117. });
  118. // 마이너스 쪽은 걍 손안댔다고보면됨.. add 하고 완료되면 해야지했는데ㅋㅋㅋ
  119. var minusAuthAttrDataSource = new kendo.data.DataSource({
  120. transport: {
  121. read: function(options) {
  122. $.ajax({
  123. url: $crudServiceBaseUrl + "/getAuthAttrList.json",
  124. method: "get",
  125. dataType: "json",
  126. data: {authId: self.selectedAuthId, authType : 'minus'},
  127. success: function(result) {
  128. options.success(result);
  129. }
  130. });
  131. },
  132. create: function(e) {
  133. e.success();
  134. },
  135. destroy: {},
  136. parameterMap: function( options, operation ) {
  137. if( operation === "read" ){
  138. return {authId: self.selectedAuthId, authType : 'minus'};
  139. } else {
  140. return;
  141. }
  142. }
  143. },
  144. schema: {
  145. data: function(response) {
  146. return response;
  147. },
  148. // 요게 서버에서 속성들을 내려주는 데이터구조
  149. model: {
  150. id: "authAttrSeq",
  151. fields: {
  152. attrName: { type: "string", editable: true, validation: { required: false }},
  153. attrTypeName: { type: "string", editable: true, validation: { required: false }},
  154. authAttrId: { type: "string", editable: true, validation: { required: false }},
  155. authAttrSeq: { type: "string"},
  156. authAttrType: { type: "string", editable: true, validation: { required: false }},
  157. authId: { type: "string"},
  158. authType: { type: "string"}
  159. }
  160. }
  161. }
  162. });
  163. var initGrid = function () {
  164. var grid = $addAttrList.kendoGrid({
  165. dataSource: addAuthAttrDataSource,
  166. resizable: true,
  167. sortable: false,
  168. toolbar: [{ name : "create", text: "추가" }],
  169. columns: [
  170. { field: "authAttrType", title: "속성 타입", width: 35, attributes: {style: "text-align: center;"},
  171. template: function(data){
  172. for(var i = 0; i < attrTypes.length; i++) {
  173. if(attrTypes[i].attrType == data.authAttrType)
  174. return attrTypes[i].attrTypeName;
  175. }}, editor:attrTypeEditor}
  176. ,{ field: "authAttrId", title: "속성",hidden:false, width: 35, attributes: {style: "text-align: center;"},
  177. template: function(data){
  178. if(data.authAttrType == "hospital") {
  179. for(var i = 0; i < hospitalAttr.length; i++) {
  180. if(hospitalAttr[i].attrId == data.authAttrId)
  181. return hospitalAttr[i].attrName;
  182. }
  183. } else if(data.authAttrType == "duty") {
  184. for(var i = 0; i < dutyAttr.length; i++) {
  185. if(dutyAttr[i].attrId == data.authAttrId)
  186. return dutyAttr[i].attrName;
  187. }
  188. } else if(data.authAttrType == "work") {
  189. for(var i = 0; i < workAttr.length; i++) {
  190. if(workAttr[i].attrId == data.authAttrId)
  191. return workAttr[i].attrName;
  192. }
  193. } else if(data.authAttrType == "extra") {
  194. for(var i = 0; i < extraAttr.length; i++) {
  195. if(extraAttr[i].attrId == data.authAttrId)
  196. return extraAttr[i].attrName;
  197. }
  198. }
  199. },editor:attrEditor}
  200. ,{ command: [{name:"edit",text:{edit: "편집", update: "저장", cancel: "취소"}},{name:"destroy",text:"삭제"}], title: "&nbsp;", width: 30, attributes: {style: "text-align: center;"}}
  201. ],
  202. editable: {
  203. mode:"inline",
  204. confirmation:"정말 삭제하시겠습니까?"
  205. },
  206. edit: function(e) {
  207. //추가event찍힘
  208. }
  209. });
  210. var gridMinus = $minusAttrList.kendoGrid({
  211. dataSource: minusAuthAttrDataSource,
  212. resizable: true,
  213. sortable: false,
  214. toolbar: [{ name : "create", text: "추가"}],
  215. columns: [
  216. { field: "authAttrType", title: "속성 타입", width: 35, attributes: {style: "text-align: center;"},
  217. template: function(data){
  218. for(var i = 0; i < attrTypes.length; i++) {
  219. if(attrTypes[i].attrType == data.authAttrType)
  220. return attrTypes[i].attrTypeName;
  221. }}, editor:attrTypeEditor}
  222. ,{ field: "authAttrId", title: "속성",hidden:false, width: 35, attributes: {style: "text-align: center;"},
  223. template: function(data){
  224. if(data.authAttrType == "hospital") {
  225. for(var i = 0; i < hospitalAttr.length; i++) {
  226. if(hospitalAttr[i].attrId == data.authAttrId)
  227. return hospitalAttr[i].attrName;
  228. }
  229. } else if(data.authAttrType == "duty") {
  230. for(var i = 0; i < dutyAttr.length; i++) {
  231. if(dutyAttr[i].attrId == data.authAttrId)
  232. return dutyAttr[i].attrName;
  233. }
  234. } else if(data.authAttrType == "work") {
  235. for(var i = 0; i < workAttr.length; i++) {
  236. if(workAttr[i].attrId == data.authAttrId)
  237. return workAttr[i].attrName;
  238. }
  239. } else if(data.authAttrType == "extra") {
  240. for(var i = 0; i < extraAttr.length; i++) {
  241. if(extraAttr[i].attrId == data.authAttrId)
  242. return extraAttr[i].attrName;
  243. }
  244. }
  245. },editor:attrEditor}
  246. ,{ command: [{name:"edit",text:"편집"},{name:"destroy",text:"삭제"}], title: "&nbsp;", width: 30, attributes: {style: "text-align: center;"}}
  247. ],
  248. editable: {
  249. mode:"inline",
  250. confirmation:"정말 삭제하시겠습니까?"
  251. },
  252. edit: function(e) {
  253. //추가event찍힘
  254. }
  255. });
  256. function attrTypeEditor(container, options) {
  257. $('<input required name="' + options.field + '"/>')
  258. .appendTo(container)
  259. .kendoDropDownList({
  260. dataSource: attrTypes,
  261. dataTextField: "attrTypeName",
  262. dataValueField: "attrType",
  263. change: selectChangeAttr,
  264. optionLabel: {
  265. attrTypeName: "선택",
  266. attrType: ""
  267. }
  268. }).data("kendoDropDownList").select(0);
  269. };
  270. function selectChangeAttr(e){
  271. var options= e.sender._selectedValue;
  272. var container = $('.k-grid-edit-row [data-container-for=authAttrId]');
  273. if( options == 'hospital') {
  274. container.find('input').data("kendoDropDownList").dataSource.data(hospitalAttr);
  275. } else if( options == 'duty') {
  276. container.find('input').data("kendoDropDownList").dataSource.data(dutyAttr);
  277. } else if( options == 'work') {
  278. container.find('input').data("kendoDropDownList").dataSource.data(workAttr);
  279. } else if( options == 'extra') {
  280. container.find('input').data("kendoDropDownList").dataSource.data(extraAttr);
  281. };
  282. };
  283. function attrEditor(container, options) {
  284. var dataSource;
  285. if(options.model.authAttrType=='hospital'){
  286. dataSource = hospitalAttr;
  287. }else if(options.model.authAttrType=='duty'){
  288. dataSource = dutyAttr;
  289. }else if(options.model.authAttrType=='work'){
  290. dataSource = workAttr;
  291. }else if(options.model.authAttrType=='extra'){
  292. dataSource = extraAttr;
  293. };
  294. $('<input required name="' + options.field + '"/>')
  295. .appendTo(container)
  296. .kendoDropDownList({
  297. autoBind: false,
  298. dataTextField: "attrName",
  299. dataValueField: "attrId",
  300. dataSource: dataSource,
  301. optionLabel: {
  302. attrId: "",
  303. attrName: "선택"
  304. }
  305. }).data("kendoDropDownList").select(0);
  306. };
  307. }
  308. var initSplitter = function(){
  309. $wrapper.kendoSplitter({
  310. panes: [
  311. { collapsible: true, resizable: true, size: '240px' },
  312. { collapsible: false }
  313. ]
  314. });
  315. $wrapper.data("kendoSplitter").trigger("resize");
  316. };
  317. /**
  318. * 트리 아이템 신규 이벤트
  319. * @private
  320. */
  321. var addItem = function(e){
  322. var treeView = self.treeView;
  323. addedNodeCheck(e, treeView.dataSource.data().toJSON());
  324. if (addedNodeArr.length > 0) {
  325. alert("저장하지 않은 아이템 [ " + addedNodeArr[0].menuName + " ] (이)가 있습니다");
  326. addedNodeArr = [];
  327. return false;
  328. }
  329. var node = treeView.select(),
  330. item = treeView.dataItem(node);
  331. var nodeData = null,
  332. defData = {
  333. menuType: "CONT",
  334. menuName: "NewItem",
  335. menuOrder: 0,
  336. enabledYn: "Y",
  337. authYn: "Y",
  338. authViewYn: "N",
  339. aggYn: "N",
  340. accessUriAddr: "",
  341. imageUriAddr: "",
  342. authDesc: "",
  343. childCount: 0,
  344. i18ns: [],
  345. addedNode: true,
  346. selected: false,
  347. menuParam : []
  348. };
  349. /*if( node.length === 0 ) {*/
  350. node = null;
  351. nodeData = $.extend(true, {}, {
  352. menuType: 'MAIN'
  353. }, defData);
  354. /* } else {
  355. if( item.childCount === 0 ) {
  356. item.loaded(true);
  357. }
  358. nodeData = $.extend( true, {}, item.toJSON(), {
  359. menuId: null,
  360. parentMenuId: item.menuId
  361. }, defData);
  362. }*/
  363. treeView.append(nodeData, node);
  364. };
  365. // 다국어 코드 중복 체크
  366. var i18nArr = [];
  367. /**
  368. * 트리 아이템 저장 이벤트
  369. * @private
  370. */
  371. var saveItem = function(e){
  372. var treeView = self.treeView;
  373. var node = treeView.select(),
  374. item = treeView.dataItem(node);
  375. if( node.length === 0 ) {
  376. alert("선택한 아이템이 없습니다");
  377. return false;
  378. }
  379. if( item.authId === null || item.authId === "" ) {
  380. alert( "아이디가 누락되었습니다" );
  381. return false;
  382. }
  383. var addList = $addAttrList.data("kendoGrid").dataSource.data();
  384. var minusList = $minusAttrList.data("kendoGrid").dataSource.data();
  385. var attrList = [];
  386. for(var i=0; i<addList.length; i++) {
  387. var obj = {
  388. authId : addList[i].authId,
  389. authType : "add",
  390. authAttrType : addList[i].authAttrType,
  391. authAttrId : addList[i].authAttrId
  392. };
  393. attrList.push(obj);
  394. };
  395. for(var j=0; j<minusList.length; j++) {
  396. var obj = {
  397. authId : minusList[j].authId,
  398. authType : "minus",
  399. authAttrType : minusList[j].authAttrType,
  400. authAttrId : minusList[j].authAttrId
  401. };
  402. attrList.push(obj);
  403. };
  404. var param = $.extend(true, {}, item, {
  405. authAttrList : attrList
  406. }, null);
  407. var opt = {
  408. url : $crudServiceBaseUrl + "/save.json",
  409. method : "POST",
  410. data : self.util.stringifyJson(param),
  411. dataType : "json",
  412. contentType: "application/json; charset=UTF-8",
  413. complete : function(){
  414. kendo.ui.progress( $wrapper, false );
  415. }
  416. };
  417. var success = function(data){
  418. alert("저장 되었습니다");
  419. location.reload(true);
  420. };
  421. var error = function(xhr,d,t){
  422. console.log(xhr);
  423. console.log(t);
  424. };
  425. self.ajaxAdmin( opt, success, error );
  426. };
  427. /**
  428. * 트리 아이템 reload 이벤트
  429. * @private
  430. */
  431. var reloadItem = function(e){
  432. kendo.ui.progress( $wrapper, true );
  433. var opt = {
  434. url : $crudServiceBaseUrl + "/cacheReload.json",
  435. type : "POST",
  436. contentType: "application/json; charset=UTF-8",
  437. complete : function(){
  438. kendo.ui.progress( $wrapper, false );
  439. }
  440. };
  441. var success = function(data){
  442. if( data === 1 ) {
  443. alert("갱신 되었습니다");
  444. } else {
  445. alert( "수행 중 에러가 발생하였습니다" );
  446. }
  447. };
  448. var error = function(xhr,d,t){
  449. console.log(xhr);
  450. console.log(t);
  451. };
  452. self.ajaxAdmin( opt, success, error );
  453. };
  454. /**
  455. * 트리 아이템 삭제 이벤트
  456. * @private
  457. */
  458. var removeItem = function(e){
  459. var treeView = self.treeView;
  460. var node = treeView.select(),
  461. item = treeView.dataItem(node);
  462. if( node.length === 0 ) {
  463. alert( "선택한 아이템이 없습니다." );
  464. return false;
  465. }
  466. kendo.unbind( $wrapper );
  467. if( item.addedNode === true ) {
  468. treeView.remove(node);
  469. } else {
  470. if( !confirm( "삭제 하시겠습니까?" ) ) {
  471. return false;
  472. }
  473. kendo.ui.progress( $wrapper, true );
  474. var opt = {
  475. url : $crudServiceBaseUrl + "/remove.json",
  476. type : "POST",
  477. data : { authId : item.authId },
  478. dataType : "json",
  479. complete : function(){
  480. kendo.ui.progress( $wrapper, false );
  481. }
  482. };
  483. var success = function(data){
  484. alert( "삭제 되었습니다" );
  485. location.reload(true);
  486. };
  487. var error = function(xhr,d,t){
  488. console.log(xhr);
  489. console.log(t);
  490. };
  491. self.ajaxAdmin( opt, success, error );
  492. }
  493. };
  494. /**
  495. * 트리 아이템 선택 해제 이벤트
  496. * @private
  497. */
  498. var deselectItem = function(e){
  499. console.log(self.util.stringifyJson(e));
  500. self.treeView.select( null );
  501. };
  502. /**
  503. * 데이터소스 설정
  504. */
  505. // tree 데이터소스
  506. var treeDataSource = new kendo.data.HierarchicalDataSource({
  507. transport: {
  508. read: {
  509. url: $crudServiceBaseUrl + "/getList.json",
  510. method : "post",
  511. dataType: "json"
  512. }
  513. },
  514. schema : {
  515. model : {
  516. id: "authId",
  517. hasChildren: function(){
  518. return (this.get("childCount") > 0);
  519. }
  520. }
  521. }
  522. });
  523. /**
  524. * 트리 초기화
  525. */
  526. var initTree = function(){
  527. //kendo tree
  528. var option = {
  529. loadOnDemand: false,
  530. dataSource : treeDataSource,
  531. dataTextField : "authName",
  532. template : treeTemplate,
  533. select : treeSelect,
  534. expand : treeExpand
  535. };
  536. self.treeView = self.tree( $treeView, option );
  537. /**
  538. * tree template
  539. * @private
  540. * @description 트리 구성
  541. */
  542. function treeTemplate(o){
  543. var span = $("<span></span>").addClass("k-sprite");
  544. span.addClass("html");
  545. return span[0].outerHTML + o.item.authName;
  546. };
  547. /**
  548. * tree select
  549. * @private
  550. * @description 트리 선택
  551. */
  552. function treeSelect(o){
  553. kendo.unbind( $wrapper );
  554. var item = this.dataItem( o.node );
  555. console.log(self.util.stringifyJson(item));
  556. var observer = new kendo.observable( item );
  557. observer.bind("change", function(o) {
  558. });
  559. kendo.bind( $wrapper, observer );
  560. if( observer.menuId !== undefined && observer.menuId !== null ){
  561. $("#authId").prop("disabled",true);
  562. } else {
  563. $("#authId").prop("disabled",false);
  564. }
  565. //설명 글자수제한 초기화
  566. $authDesc.trigger("keyup");
  567. if(item.authId !== undefined) {
  568. // 왼쪽 아이템 선택 시 !!!!!!
  569. self.selectedAuthId = item.authId;
  570. $addAttrList.data("kendoGrid").dataSource.read();
  571. $minusAttrList.data("kendoGrid").dataSource.read();
  572. }
  573. };
  574. /**
  575. * tree expand
  576. * @private
  577. * @description 트리 펼치기
  578. */
  579. function treeExpand(o){
  580. };
  581. };
  582. /**
  583. * 속성 데이터 가져오기
  584. */
  585. var initAttrTypes = function() {
  586. $.ajax({
  587. url : $attrCrudServiceBaseUrl + "/getAttrTypeList.json",
  588. method : "POST",
  589. dataType : "json",
  590. contentType : "application/json",
  591. success : function(data){
  592. attrTypes = data.attrType;
  593. hospitalAttr = data.hospital;
  594. dutyAttr = data.duty;
  595. workAttr = data.work;
  596. extraAttr = [];
  597. if(data.extra!=undefined&&data.extra.length>0){
  598. for(var i=0; i<data.extra.length; i++){
  599. extraAttr.push({'attrSeq': data.extra[i].extraAttrSeq,
  600. 'attrId': data.extra[i].extraAttrId,
  601. 'attrName': data.extra[i].extraAttrName
  602. })
  603. };
  604. }
  605. },
  606. error : function(xhr,d,t){
  607. },
  608. complete: function(){
  609. }
  610. });
  611. }
  612. // 저장하지 않은 아이템 배열
  613. var addedNodeArr = [];
  614. /**
  615. * 트리 저장하지 않은 아이템 확인
  616. */
  617. var addedNodeCheck = function(e, treeViewData) {
  618. if( treeViewData ) {
  619. for( var n = 0; n < treeViewData.length; n++ ) {
  620. var childData = treeViewData[n];
  621. if( childData.addedNode === true ){
  622. addedNodeArr.push( childData );
  623. return;
  624. } else {
  625. var child = childData.items;
  626. if( child ) {
  627. if( child.length > 0 ){
  628. addedNodeCheck( e, child );
  629. }
  630. }
  631. }
  632. }
  633. }
  634. };
  635. };
  636. var rowNum = 0;
  637. function resetRowNum(){
  638. rowNum = 0;
  639. }
  640. function getNum(){
  641. return ++rowNum;
  642. }