version.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**
  2. * admin/vers
  3. */
  4. var mcare_admin_version = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $crudServiceBaseUrl = contextPath + "/admin/version";
  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 + "/getAllVersionList.json",
  28. method: "post",
  29. dataType: "json",
  30. contentType: "application/json",
  31. complete: gridReadComplete
  32. },
  33. create: {
  34. url: $crudServiceBaseUrl + "/insertVersion.json",
  35. method: "post",
  36. dataType: "json",
  37. contentType: "application/json",
  38. complete: gridActionComplete
  39. },
  40. update: {
  41. url: $crudServiceBaseUrl + "/updateVersion.json",
  42. method: "post",
  43. dataType: "json",
  44. contentType: "application/json",
  45. complete: gridActionComplete
  46. },
  47. destroy: {
  48. url: $crudServiceBaseUrl + "/removeVersion.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: function(response) {
  68. //구분할수 있는 id가 없어서 그리드 오류가 생김. 그래서 seq를 인위적으로 넣음
  69. var list = response.data;
  70. if( list !== undefined ){
  71. for (var i = 0; i < list.length; i++) {
  72. var obj = list[i];
  73. obj["seq"] = (i+1);
  74. }
  75. }else {
  76. list = response.data;
  77. }
  78. return list;
  79. },
  80. total: "totalCount",
  81. model: {
  82. id: "seq",
  83. fields: {
  84. seq : { type: "number", editable: false, nullable:true},
  85. platformType: { type: "string", nullable: false, validation: { required: true },defaultValue:"A"},
  86. certType : { type: "string", nullable: false, validation:{required: true}, defaultValue:"InHouse"},
  87. appName: { type: "string", nullable: false, validation: { required: true }},
  88. versionOrder: { type: "number", nullable: false, validation: { required: true }},
  89. marketUrl: { type: "string", nullable: true},
  90. }
  91. }
  92. }
  93. });
  94. /**
  95. * 그리드 이벤트 동작 complate
  96. * @private
  97. */
  98. function gridActionComplete( e ){
  99. var result = self.util.parseJson( e.responseText );
  100. if( result.msg )
  101. alert( result.msg );
  102. $grid.data("kendoGrid").dataSource.read();
  103. };
  104. /**
  105. * 그리드 이벤트 동작 complate
  106. * @private
  107. */
  108. function gridReadComplete( e ){
  109. var result = self.util.parseJson( e.responseText );
  110. if( result.msg ){
  111. alert( result.msg );
  112. if( result.type == "AuthException" ){
  113. window.location.href = contextPath + "/admin/logout.page";
  114. return;
  115. }
  116. }
  117. };
  118. /**
  119. * 그리드 초기화
  120. */
  121. var initGrid = function(){
  122. // 그리드 옵션
  123. var option = {
  124. dataSource: dataSource,
  125. pageable: true,
  126. sortable: true,
  127. resizable: true,
  128. height: 620,
  129. toolbar: [{ name : "create", text: "추가", complete: function(e) {
  130. $grid.data("kendoGrid").dataSource.read();
  131. } }],
  132. columns: [
  133. { field: "seq", title: "seq",hidden:true, width: 30, attributes: {style: "text-align: center;"}}
  134. ,{ field: "platformType", title: "타입", width: 80, attributes: {style: "text-align: center;"}, editor:platformEditor,
  135. template:function(dataItem) {
  136. if(dataItem.platformType === "A"){
  137. return "Android";
  138. } else if(dataItem.platformType === "I"){
  139. return "IOS";
  140. } else {
  141. return "ETC";
  142. }
  143. }
  144. }
  145. ,{ field: "certType", title: "인증서", width: 100, attributes: {style: "text-align: center;"}, editor:certTypeEditor}
  146. ,{ field: "appName", title: "이름", width: 120, attributes: {style: "text-align: center;"}}
  147. ,{ field: "versionOrder", title: "버전", width: 80, attributes: {style: "text-align: center;"}}
  148. ,{ field: "marketUrl", title: "마켓주소", width: 200, attributes: {style: "text-align: center;"}}
  149. ,{ command: [{name:"edit",text:"수정"},{name:"destroy",text:"삭제"}], title: "&nbsp;", width: 100, attributes: {style: "text-align: center;"}}
  150. ],
  151. editable: {
  152. mode:"inline",
  153. confirmation:"정말 삭제하시겠습니까?"
  154. },
  155. edit: function(e) {
  156. if (!e.model.isNew()) {
  157. e.container.find( "input[name='platformType']" ).attr("readonly", true);
  158. e.container.find( "input[name='appName']" ).attr("readonly", true);
  159. $("select[data-id=certTypeEditor]").data("kendoDropDownList").readonly(true);
  160. }
  161. },
  162. dataBound: function () {
  163. var rowCount = $grid.find( ".k-grid-content tbody tr" ).length;
  164. if( rowCount < dataSource._take ) {
  165. var addRows = dataSource._take - rowCount;
  166. for( var i = 0; i < addRows; i++ ) {
  167. $grid.find( ".k-grid-content tbody" )
  168. .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  169. }
  170. }
  171. }
  172. };
  173. function certTypeEditor(container, options){
  174. var select = $("<select></select>").attr({"data-id":"certTypeEditor","data-bind":"value:"+options.field});
  175. select.html("<option value='InHouse'>InHouse</option>");
  176. select.append("<option value='AppStore'>AppStore</option>");
  177. select.append("<option value='Developer'>Developer</option>");
  178. select.val(options.model.certType).appendTo(container).kendoDropDownList({autoBind: false});
  179. };
  180. function platformEditor(container, options){
  181. var select = $("<select></select>").attr({"data-id":"platformEditor","data-bind":"value:"+options.field});
  182. select.html("<option value='A'>Android</option>");
  183. select.append("<option value='I'>IOS</option>");
  184. select.val(options.model.platformType).appendTo(container).kendoDropDownList({autoBind: false});
  185. }
  186. //그리드 초기화
  187. self.grid( $grid, option );
  188. };
  189. };