pushForm.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * admin/pushForm
  3. */
  4. var mcare_admin_pushForm = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $crudServiceBaseUrl = contextPath + "/admin/pushform";
  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 + "/update.json",
  42. method: "post",
  43. dataType: "json",
  44. contentType: "application/json",
  45. complete: gridActionComplete
  46. },
  47. parameterMap: function( options, operation ) {
  48. if( operation !== "read" && options.models ) {
  49. options.models[0].formType = $("select[data-id=formTypeEditor]").val();
  50. if( options.models[0].formType === "PAGE" ){
  51. options.models[0].menuId = $("select[data-id=menuIdEditor]").val();
  52. options.models[0].menuName = $("select[data-id=menuIdEditor] option:selected").text();
  53. } else {
  54. options.models[0].menuId = "";
  55. options.models[0].menuName = "";
  56. }
  57. var id = options.models[0].formId,
  58. rex1 = /[~!@\#$%<>^&*\()\-=+\’]/gi,
  59. rex2 = /\s/gi;
  60. if( rex1.test(id) ){
  61. alert("특수문자는 사용할 수 없습니다.");
  62. return false;
  63. } else if( rex2.test(id) ){
  64. alert("공백은 포함할 수 없습니다." );
  65. return false;
  66. }
  67. return self.util.stringifyJson( options.models[0] );
  68. } else if( operation === "read" ){
  69. return self.util.stringifyJson( options );
  70. }
  71. }
  72. },
  73. batch: true,
  74. pageSize: 13,
  75. serverPaging: true,
  76. serverSorting: true,
  77. schema: {
  78. data: "data",
  79. total: "totalCount",
  80. model: {
  81. id: "formId",
  82. fields: {
  83. formId: {type:"string"},
  84. formType: { type: "string"},
  85. useYn : {type:"string",defaultValue:"N"},
  86. menuId: { type: "string"},
  87. menuName: { type: "string"},
  88. includeNameYn: { type: "string", defaultValue:"N"},
  89. formDesc : { type:"string" }
  90. }
  91. }
  92. }
  93. });
  94. /**
  95. * 그리드 이벤트 동작 complate
  96. * @private
  97. */
  98. function gridActionComplete( e ){
  99. if( e.responseText !== "" ){
  100. var result = self.util.parseJson( e.responseText );
  101. if( result.msg !== undefined && result.msg !== "" ){
  102. alert( result.msg );
  103. }
  104. }
  105. $grid.data("kendoGrid").dataSource.read();
  106. };
  107. /**
  108. * 그리드 이벤트 동작 complate
  109. * @private
  110. */
  111. function gridReadComplete( e ){
  112. var result = self.util.parseJson( e.responseText );
  113. if( result.msg ){
  114. alert( result.msg );
  115. if( result.type == "AuthException" ){
  116. window.location.href = contextPath + "/admin/logout.page";
  117. return;
  118. }
  119. }
  120. };
  121. /**
  122. * 그리드 초기화
  123. */
  124. var initGrid = function(){
  125. // 그리드 옵션
  126. var option = {
  127. dataSource: dataSource,
  128. pageable: true,
  129. sortable: true,
  130. resizable: true,
  131. height: 580,
  132. toolbar: [{ name : "create", text: "추가", complete: function(e) {
  133. $grid.data("kendoGrid").dataSource.read();
  134. } }],
  135. columns: [
  136. { field: "formId", title: "이름",filterable:false, width: 120, attributes: {style: "text-align: center;"}}
  137. ,{ field: "formType", title: "타입",filterable:false, width: 50,editor:formTypeEditor, attributes: {style: "text-align: center;"}}
  138. ,{ field: "useYn", title: "사용여부",filterable:false, width: 50,editor:useYnEditor, attributes: {style: "text-align: center;"}}
  139. ,{ field: "menuId", title: "메뉴명",filterable:false,hidden:true,editor:menuIdEditor, width: 80, attributes: {style: "text-align: center;"}}
  140. ,{ field: "menuName", title: "메뉴명", width: 80, attributes: {style: "text-align: center;"}}
  141. ,{ field: "includeNameYn", title: "이름포함여부",filterable:false, width:50, editor:includeNameYnEditor,attributes: {style: "text-align: center;"}}
  142. ,{ field: "formDesc", title: "설명", width: 120,filterable:false, attributes: {style: "text-align: center;"}}
  143. ,{ command: [{name:"edit",text:"수정"}], title: "&nbsp;", width: 80, attributes: {style: "text-align: center;"}}
  144. ],
  145. editable: "popup",
  146. edit: function(e) {
  147. $("label[for=menuName]").parent().hide();
  148. $("div[data-container-for=menuName]").hide();
  149. if (!e.model.isNew()) {
  150. $("input[name=formId]").prop("readonly",true);
  151. $("label[for=formType]").parent().hide();
  152. $("div[data-container-for=formType]").hide();
  153. $("label[for=menuId]").parent().hide();
  154. $("div[data-container-for=menuId]").hide();
  155. }
  156. },
  157. filterable: {
  158. extra : false,
  159. operators : {
  160. string : {
  161. contains : " 포함 "
  162. }
  163. }
  164. },
  165. dataBound: function () {
  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. };
  176. function formTypeEditor(container,options){
  177. var select = $("<select></select>").attr({"data-id":"formTypeEditor","data-bind":"value:"+options.field});
  178. select.html("<option value='PAGE'>PAGE</option>");
  179. select.append("<option value='MAP'>MAP</option>");
  180. select.append("<option value='GUIDE'>GUIDE</option>");
  181. select.val(options.model.formType).appendTo(container).kendoDropDownList({autoBind: true,
  182. change : function(e){
  183. if( this.value() !== "PAGE" ){
  184. $("label[for=menuId]").parent().hide();
  185. $("div[data-container-for=menuId]").hide();
  186. } else {
  187. $("label[for=menuId]").parent().show();
  188. $("div[data-container-for=menuId]").show();
  189. }
  190. }});
  191. }
  192. function useYnEditor(container,options){
  193. var select = $("<select></select>").attr({"data-id":"useYnEditor","data-bind":"value:"+options.field});
  194. select.html("<option value='Y'>Y</option>");
  195. select.append("<option value='N'>N</option>");
  196. select.val(options.model.useYn).appendTo(container).kendoDropDownList({autoBind: true});
  197. }
  198. function menuIdEditor(container,options){
  199. // $.ajax({
  200. // url: contextPath + "/admin/menu/getList.json",
  201. // method : "POST",
  202. // dataType : "json",
  203. // success: function(data){
  204. // var select = $("<select></select>").attr({"data-id":"menuIdEditor","data-bind":"value:"+options.field});
  205. // for( var i = 0; i < data.length; i++ ){
  206. // var item = data[i];
  207. //
  208. // if( (item.accessUriAddr).indexOf(".page") > 0 ){
  209. //
  210. // select.append("<option value='"+ item.menuId+"'>"+item.menuName+"</option>");
  211. // }
  212. // }
  213. // select.val(options.model.menuId).appendTo(container).kendoDropDownList({autoBind: true});
  214. // },
  215. // error: function(xhr){
  216. //
  217. // },
  218. // complete: function(){
  219. //
  220. // }
  221. // });
  222. var opt = {
  223. url: contextPath + "/admin/menu/getList.json",
  224. method : "POST",
  225. dataType : "json",
  226. complete : function(){
  227. }
  228. };
  229. var success = function(data){
  230. var select = $("<select></select>").attr({"data-id":"menuIdEditor","data-bind":"value:"+options.field});
  231. for( var i = 0; i < data.length; i++ ){
  232. var item = data[i];
  233. if( (item.accessUriAddr).indexOf(".page") > 0 ){
  234. select.append("<option value='"+ item.menuId+"'>"+item.menuName+"</option>");
  235. }
  236. }
  237. select.val(options.model.menuId).appendTo(container).kendoDropDownList({autoBind: true});
  238. };
  239. var error = function(xhr,d,t){
  240. };
  241. self.ajaxAdmin( opt, success, error );
  242. }
  243. function includeNameYnEditor(container,options){
  244. var select = $("<select></select>").attr({"data-id":"includeNameYnEditor","data-bind":"value:"+options.field});
  245. select.html("<option value='Y'>Y</option>");
  246. select.append("<option value='N'>N</option>");
  247. select.val(options.model.includeNameYn).appendTo(container).kendoDropDownList({autoBind: true});
  248. }
  249. //그리드 초기화
  250. self.grid( $grid, option );
  251. };
  252. };