code.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * admin/code
  3. */
  4. var mcare_admin_code = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $crudServiceBaseUrl = contextPath + "/admin/code";
  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 + "/getCodeList.json",
  29. method: "post",
  30. dataType: "json",
  31. contentType: "application/json"
  32. },
  33. create: {
  34. url: $crudServiceBaseUrl + "/saveCode.json",
  35. method: "post",
  36. dataType: "json",
  37. contentType: "application/json",
  38. complete: gridActionComplete
  39. },
  40. update: {
  41. url: $crudServiceBaseUrl + "/saveCode.json",
  42. method: "post",
  43. dataType: "json",
  44. contentType: "application/json",
  45. complete: gridActionComplete
  46. },
  47. destroy: {
  48. url: $crudServiceBaseUrl + "/removeCode.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. }
  58. }
  59. },
  60. batch: true,
  61. pageSize: 10,
  62. schema: {
  63. model: {
  64. platformType: "platformType",
  65. versionValue: "versionValue",
  66. appName: "appName",
  67. fields: {
  68. platformType: { type: "string", nullable: false, validation: { required: true }},
  69. appName: { type: "string", nullable: false, validation: { required: true }},
  70. versionValue: { type: "string", nullable: false, validation: { required: true }},
  71. }
  72. }
  73. }
  74. });
  75. /**
  76. * 그리드 이벤트 동작 complate
  77. * @private
  78. */
  79. function gridActionComplete( e ){
  80. var result = self.util.parseJson( e.responseText );
  81. if( result.msg )
  82. alert( result.msg );
  83. $grid.data("kendoGrid").dataSource.read();
  84. };
  85. return dataSource;
  86. };
  87. var dataSource = setDataSource();
  88. /**
  89. * 그리드 초기화
  90. */
  91. var initGrid = function(){
  92. // 그리드 옵션
  93. var option = {
  94. dataSource: dataSource,
  95. pageable: true,
  96. sortable: true,
  97. resizable: true,
  98. height: 420,
  99. toolbar: [{ name : "create", text: "추가", complete: function(e) {
  100. $grid.data("kendoGrid").dataSource.read();
  101. } }],
  102. columns: [
  103. { field: "platform", title: "아이디", width: 120, attributes: {style: "text-align: center;"}}
  104. ,{ field: "appName", title: "이름", width: 240, attributes: {style: "text-align: center;"}}
  105. ,{ field: "versionValue", title: "버전", width: 80, attributes: {style: "text-align: center;"}}
  106. ,{ command: ["edit", "destroy"], title: " ", width: 170, attributes: {style: "text-align: center;"}}
  107. ],
  108. editable: "popup",
  109. edit: function(e) {
  110. if (!e.model.isNew()) {
  111. e.container.find( "input[name=id]" ).attr("readonly", true);
  112. }
  113. },
  114. dataBound: function () {
  115. var rowCount = $grid.find( ".k-grid-content tbody tr" ).length;
  116. if( rowCount < dataSource._take ) {
  117. var addRows = dataSource._take - rowCount;
  118. for( var i = 0; i < addRows; i++ ) {
  119. $grid.find( ".k-grid-content tbody" )
  120. .append( "<tr class='kendo-data-row'><td>&nbsp;</td></tr>" );
  121. }
  122. }
  123. }
  124. };
  125. //그리드 초기화
  126. self.grid( $grid, option );
  127. };
  128. };