manager.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. $crudServiceBaseUrl = contextPath + "/admin/manager";
  11. /**
  12. * 초기화
  13. */
  14. this.init = function(){
  15. initGrid();
  16. addEvent();
  17. };
  18. /**
  19. * 이벤트 등록
  20. */
  21. var addEvent = function(){
  22. };
  23. // 데이터소스
  24. var dataSource = new kendo.data.DataSource({
  25. transport: {
  26. read: {
  27. url: $crudServiceBaseUrl + "/getList.json",
  28. method: "post",
  29. dataType: "json",
  30. contentType: "application/json",
  31. complete : gridReadComplete
  32. },
  33. create: {
  34. url: $crudServiceBaseUrl + "/save.json",
  35. method: "post",
  36. dataType: "json",
  37. contentType: "application/json",
  38. complete: gridActionComplete
  39. },
  40. update: {
  41. url: $crudServiceBaseUrl + "/save.json",
  42. method: "post",
  43. dataType: "json",
  44. contentType: "application/json",
  45. complete: gridActionComplete
  46. },
  47. destroy: {
  48. url: $crudServiceBaseUrl + "/remove.json",
  49. method: "post",
  50. dataType: "json",
  51. contentType: "application/json",
  52. complete: gridActionComplete
  53. },
  54. parameterMap: function( options, operation ) {
  55. if( operation !== "read" && options.models ) {
  56. return self.util.stringifyJson( options.models[0] );
  57. }else if( operation === "read" ){
  58. return self.util.stringifyJson( options );
  59. }
  60. }
  61. },
  62. batch: true,
  63. pageSize: 14,
  64. serverPaging : true,
  65. serverSorting: true,
  66. schema: {
  67. data : "data",
  68. total : "totalCount",
  69. model: {
  70. id: "userId",
  71. fields: {
  72. userId: { type: "string", nullable: false, validation: { required: true }},
  73. userName: { type: "string", nullable: false, validation: { required: true }},
  74. pwdValue: { type: "string", nullable: false, validation: { required: true }},
  75. deptName: { type: "string", nullable: false},
  76. enabledYn: { type: "string", nullable: false, defaultValue:"Y"},
  77. }
  78. }
  79. }
  80. });
  81. /**
  82. * 그리드 이벤트 동작 complate
  83. * @private
  84. */
  85. function gridActionComplete( e ){
  86. var result = self.util.parseJson( e.responseText );
  87. if( result.msg )
  88. alert( result.msg );
  89. $grid.data("kendoGrid").dataSource.read();
  90. };
  91. /**
  92. * 그리드 이벤트 동작 complate
  93. * @private
  94. */
  95. function gridReadComplete( e ){
  96. var result = self.util.parseJson( e.responseText );
  97. if( result.msg ){
  98. alert( result.msg );
  99. if( result.type == "AuthException" ){
  100. window.location.href = contextPath + "/admin/logout.page";
  101. return;
  102. }
  103. }
  104. };
  105. /**
  106. * 그리드 초기화
  107. */
  108. var initGrid = function(){
  109. // 그리드 옵션
  110. var option = {
  111. dataSource: dataSource,
  112. pageable: true,
  113. sortable: true,
  114. resizable: true,
  115. height: 620,
  116. toolbar: [{ name : "create", text: "추가", complete: function(e) {
  117. $grid.data("kendoGrid").dataSource.read();
  118. } }],
  119. columns: [
  120. { field: "userId", title: "아이디", width: 80, attributes: {style: "text-align: center;"}}
  121. ,{ field: "userName", title: "이름", width: 100, attributes: {style: "text-align: center;"}}
  122. ,{ field: "pwdValue", title: "비밀번호", width: 120, attributes: {style: "text-align: center;"},editor:passwordEditor}
  123. ,{ field: "deptName", title: "소속", width: 120, attributes: {style: "text-align: center;"}}
  124. ,{ field: "enabledYn", title: "활성화여부", width: 80, attributes: {style: "text-align: center;"}}
  125. ,{ command: ["edit", "destroy"], title: " ", width: 170, attributes: {style: "text-align: center;"}}
  126. ],
  127. editable: {
  128. mode:"inline",
  129. confirmation : "정말 삭제하시겠습니까?"
  130. },
  131. edit: function(e) {
  132. if (!e.model.isNew()) {
  133. e.container.find( "input[name=userId]" ).attr("readonly", true);
  134. }
  135. },
  136. dataBound: function () {
  137. var rowCount = $grid.find( ".k-grid-content tbody tr" ).length;
  138. if( rowCount < dataSource._take ) {
  139. var addRows = dataSource._take - rowCount;
  140. for( var i = 0; i < addRows; i++ ) {
  141. $grid.find( ".k-grid-content tbody" )
  142. .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  143. }
  144. }
  145. }
  146. };
  147. //그리드 초기화
  148. self.grid( $grid, option );
  149. };
  150. function passwordEditor(container,options){
  151. $('<input class="k-input k-textbox" type="password" required data-bind="value:' + options.field + '"/>').appendTo(container);
  152. }
  153. };