agreement.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * admin/agreement
  3. */
  4. var mcare_admin_agreement = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $crudServiceBaseUrl = contextPath + "/admin/agreement";
  11. /**
  12. * 초기화
  13. */
  14. this.init = function(){
  15. initGrid();
  16. addEvent();
  17. };
  18. /**
  19. * 이벤트 등록
  20. */
  21. var addEvent = function(){
  22. };
  23. var setDataSource = function(){
  24. // 데이터소스
  25. var dataSource = new kendo.data.DataSource({
  26. transport: {
  27. read: {
  28. url: $crudServiceBaseUrl + "/getList.json",
  29. method: "post",
  30. dataType: "json",
  31. contentType: "application/json",
  32. complete: gridReadComplete
  33. },
  34. create: {
  35. url: $crudServiceBaseUrl + "/save.json",
  36. method: "post",
  37. dataType: "json",
  38. contentType: "application/json",
  39. complete: gridActionComplete
  40. },
  41. update: {
  42. url: $crudServiceBaseUrl + "/addVersion.json",
  43. method: "post",
  44. dataType: "json",
  45. contentType: "application/json",
  46. complete: gridActionComplete
  47. },
  48. destroy: {
  49. url: $crudServiceBaseUrl + "/remove.json",
  50. method: "post",
  51. dataType: "json",
  52. contentType: "application/json",
  53. complete: gridActionComplete
  54. },
  55. parameterMap: function( options, operation ) {
  56. if( operation !== "read" && options.models ) {
  57. options.models[0].requiredYn = $("select[data-id=requireDropDownEditor]").data("kendoDropDownList").value();
  58. options.models[0].enableddYn = $("select[data-id=enabledDropDownEditor]").data("kendoDropDownList").value();
  59. options.models[0].agreementCl = $("textarea[data-id=contentEditor]").val();
  60. options.models[0].typeName = $("select[data-id=typeNameEditor]").data("kendoDropDownList").value();
  61. return self.util.stringifyJson( options.models[0] );
  62. }else if( operation === "read" ){
  63. return self.util.stringifyJson( options );
  64. }
  65. }
  66. },
  67. batch: true,
  68. pageSize: 14,
  69. serverPaging: true,
  70. serverSorting: true,
  71. schema: {
  72. data : function(result){
  73. if( result.msg !== undefined ){
  74. alert(result.msg);
  75. return [];
  76. } else if( typeof result === "object" && result.data === undefined ){
  77. if( result["typeName"]==="ALL" ){
  78. result["typeName"] = "일반";
  79. } else {
  80. result["typeName"] = "14세이하";
  81. }
  82. return result;
  83. }else {
  84. var resultList = result.data;
  85. var strSet = {"ALL":"일반","UNDER14":"14세이하"};
  86. for( var i = 0; i < resultList.length; i++ ){
  87. if( resultList[i]["typeName"] === "ALL" || resultList[i]["typeName"] === "UNDER14" ){
  88. resultList[i]["typeName"] = strSet[ resultList[i]["typeName"] ];
  89. }
  90. }
  91. return resultList;
  92. }
  93. },
  94. total: "totalCount",
  95. model: {
  96. id: "agreementSeq",
  97. fields: {
  98. agreementSeq: { type: "number"},
  99. agreementOrder: { type: "string", nullable: false, validation: { required: true }},
  100. agreementId: { type: "string", nullable: false, validation: { required: true }},
  101. versionNumber: { type: "string", nullable: false,editable:false,defaultValue:"1", validation: { required: true }},
  102. agreementName: { type: "string", nullable: false, validation: { required: true }},
  103. agreementCl: { type: "string", nullable: false, validation: { required: true }},
  104. requiredYn : { type: "string", defaultValue:"N", nullable: false, validation: { required: true }},
  105. enabledYn : { type: "string", defaultValue:"N",nullable: false, validation: { required: true }},
  106. typeName : { type : "string", defaultValue:"ALL"}
  107. }
  108. }
  109. }
  110. });
  111. /**
  112. * 그리드 이벤트 동작 complate
  113. * @private
  114. */
  115. function gridActionComplete( e ){
  116. var result = self.util.parseJson( e.responseText );
  117. if( result.msg )
  118. alert( result.msg );
  119. $grid.data("kendoGrid").dataSource.read();
  120. };
  121. /**
  122. * 그리드 이벤트 동작 complate
  123. * @private
  124. */
  125. function gridReadComplete( e ){
  126. var result = self.util.parseJson( e.responseText );
  127. if( result.msg ){
  128. alert( result.msg );
  129. if( result.type == "AuthException" ){
  130. window.location.href = contextPath + "/admin/logout.page";
  131. return;
  132. }
  133. }
  134. };
  135. return dataSource;
  136. };
  137. var dataSource = setDataSource();
  138. /**
  139. * 그리드 초기화
  140. */
  141. var initGrid = function(){
  142. // 그리드 옵션
  143. var option = {
  144. dataSource: dataSource,
  145. pageable: true,
  146. sortable: true,
  147. resizable: true,
  148. height: 620,
  149. toolbar: [{ name : "create", text: "추가", complete: function(e) {
  150. $grid.data("kendoGrid").dataSource.read();
  151. } }],
  152. columns: [
  153. { field: "agreementSeq", title: "약관seq",hidden:true, width: 50, attributes: {style: "text-align: center;"}}
  154. ,{ field: "agreementOrder", title: "약관순서", width: 50, attributes: {style: "text-align: center;"}}
  155. ,{ field: "agreementId", title: "약관 Id", width: 70, attributes: {style: "text-align: center;"}}
  156. ,{ field: "versionNumber", title: "약관 버전", width: 50, attributes: {style: "text-align: center;"}}
  157. ,{ field: "agreementName", title: "약관 이름", width: 100, attributes: {style: "text-align: center;"}}
  158. ,{ field: "agreementCl", title: "약관 내용", width: 170,sortable:false, attributes: {style: "text-align: center;"}, editor:contentEditor}
  159. ,{ field: "requiredYn", title: "필수여부", width: 50, editor: requireDropDownEditor,attributes: {style: "text-align: center;"}}
  160. ,{ field: "enabledYn", title: "활성화 여부", width: 50, editor: enabledDropDownEditor,attributes: {style: "text-align: center;"}}
  161. ,{ field: "typeName", title: "동의서유형", width: 70, editor: typeNameEditor,attributes: {style: "text-align: center;"}}
  162. ,{ command: [{name:"edit",text:"수정"}], title: "&nbsp;", width: 100, attributes: {style: "text-align: center;"}}
  163. ],
  164. editable: "popup",
  165. // dataBound: function (con,opt) {
  166. // var rowCount = $grid.find( ".k-grid-content tbody tr" ).length;
  167. // if( rowCount < dataSource._take ) {
  168. // var addRows = dataSource._take - rowCount;
  169. // for( var i = 0; i < addRows; i++ ) {
  170. // $grid.find( ".k-grid-content tbody" )
  171. // .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  172. // }
  173. // }
  174. // },
  175. edit: function(e){
  176. //수정일때
  177. if( !e.model.isNew() ){
  178. e.container.kendoWindow("title","수정");
  179. //동의서id readonly
  180. $("input[name=agreementId]").prop("readonly",true);
  181. $("select[data-id=typeNameEditor]").data("kendoDropDownList").readonly(true);
  182. //약관seq
  183. $("div[data-container-for=agreementSeq]").prev("div").hide();
  184. $("div[data-container-for=agreementSeq]").hide();
  185. //약관id
  186. $("div[data-container-for=agreementId]").prev("div").hide();
  187. $("div[data-container-for=agreementId]").hide();
  188. //버전번호
  189. $("div.k-edit-form-container label[for=versionNumber]").parent().hide();
  190. $("div.k-edit-form-container label[for=versionNumber]").parent().next("div").hide();
  191. //약관id
  192. $("div[data-container-for=typeName]").prev("div").hide();
  193. $("div[data-container-for=typeName]").hide();
  194. //활성화는 Y이면 못고치게
  195. if( e.model.enabledYn === "Y" ){
  196. $("select[data-id=enabledDropDownEditor]").data("kendoDropDownList").readonly(true);
  197. }
  198. $("div[data-container-for=agreementCl]").prev("div").css("vertical-align","top");
  199. } else {
  200. e.container.kendoWindow("title","추가");
  201. //약관seq
  202. $("div.k-edit-form-container label[for=agreementSeq]").parent().hide();
  203. $("div[data-container-for=agreementSeq]").hide();
  204. //버전번호
  205. $("div.k-edit-form-container label[for=versionNumber]").parent().hide();
  206. $("div.k-edit-form-container label[for=versionNumber]").parent().next("div").hide();
  207. $("div.k-edit-label label[for=agreementCl]").parent().css("vertical-align","top");
  208. }
  209. }
  210. };
  211. function requireDropDownEditor(container, options) {
  212. var select = $("<select></select>").attr({"data-id":"requireDropDownEditor","data-bind":"value:"+options.field});
  213. select.html("<option value='Y'>Y</option>");
  214. select.append("<option value='N'>N</option>");
  215. select.val(options.model.requiredYn).appendTo(container).kendoDropDownList({autoBind: false});
  216. }
  217. function enabledDropDownEditor(container, options) {
  218. var select = $("<select></select>").attr({"data-id":"enabledDropDownEditor","data-bind":"value:"+options.field});
  219. select.html("<option value='Y'>Y</option>");
  220. select.append("<option value='N'>N</option>");
  221. select.val(options.model.requiredYn).appendTo(container).kendoDropDownList({autoBind: false});
  222. }
  223. function contentEditor(container, options){
  224. var textArea = $("<textarea></textarea").attr({"data-id":"contentEditor","data-bind":"value:"+options.field});
  225. textArea.css({"height":"300px","width":"98%"});
  226. textArea.val(options.model.agreementCl).appendTo(container);
  227. }
  228. function typeNameEditor(container, options){
  229. var select = $("<select></select>").attr({"data-id":"typeNameEditor","data-bind":"value:"+options.field});
  230. select.html("<option value='ALL'>일반</option>");
  231. select.append("<option value='UNDER14'>14세이하</option>");
  232. options.model.typeName = (options.model.typeName==="일반"?"ALL":"UNDER14");
  233. select.val(options.model.typeName).appendTo(container).kendoDropDownList({autoBind: false});
  234. }
  235. //그리드 초기화
  236. self.grid( $grid, option );
  237. };
  238. };