7226ddb5a67c37b1f559ac67ffe3e377b7a79c51.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. BemsWebApplication.SetMenu = function (params, viewInfo) {
  2. "use strict";
  3. var viewModel, sidemenuHashSet;
  4. var headerCheckBoxValues = ko.observable(false);
  5. var saving = ko.observable(false);
  6. var headerTemplate = function (header, info) {
  7. var dataGrid = $('#gridContainer').dxDataGrid('instance');
  8. var checkbox = $('<div>');
  9. checkbox.appendTo(header);
  10. checkbox.dxCheckBox({
  11. value: headerCheckBoxValues(),
  12. valueChangeAction: function (e) {
  13. headerCheckBoxValues(e.value);
  14. }
  15. });
  16. $('<div>')
  17. .css('display', 'inline-block')
  18. .html(info.column.caption)
  19. .appendTo(header);
  20. };
  21. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmMenu', {
  22. popupWidth: 480,
  23. columns: [
  24. { dataField: 'SiteId', caption: '번호', width: '10%', allowSorting: false },
  25. { dataField: 'MenuPath', caption: '메뉴 경로', width: '60%', allowSorting: true },
  26. { dataField: 'Name', caption: '메뉴 이름', width: '20%', allowSorting: false },
  27. { dataField: 'MenuId', caption: '메뉴 ID', width: '20%', allowSorting: false },
  28. { dataField: 'Used', caption: '사용', width: '20%', allowSorting: false },
  29. ],
  30. "export": {
  31. enabled: true,
  32. fileName: '메뉴 목록',
  33. },
  34. onExporting: function (e) {
  35. e.component.columnOption("SiteId", "visible", false);
  36. },
  37. onExported: function (e) {
  38. e.component.columnOption("SiteId", "visible", true);
  39. },
  40. paging: {
  41. pageSize: 18,
  42. enabled: true
  43. },
  44. pager: {
  45. },
  46. cellPrepared: function (cellElement, cellInfo) {
  47. if (cellInfo.columnIndex == 4) {
  48. (function (element, info) {
  49. if (info.rowType == 'data') {
  50. var index = info.columnIndex - 4; //
  51. var checker = (1 << index);
  52. var checked = (info.value & checker);
  53. //console.log(info.columnIndex + ' ' + checked);
  54. $(cellElement).text('');
  55. var checkbox = $('<div>');
  56. checkbox.appendTo(element);
  57. checkbox.dxCheckBox({
  58. value: checked > 0 ? true : false,
  59. valueChangeAction: function (e) {
  60. var p = info.data.Used
  61. if (e.value) {
  62. p(p() | checker);
  63. }
  64. else {
  65. p(p() & ~checker);
  66. }
  67. }
  68. });
  69. var dataCheckBoxes = info.data.checkboxes = info.data.checkboxes || [];
  70. dataCheckBoxes[index] = checkbox;
  71. }
  72. })(cellElement, cellInfo);
  73. }
  74. },
  75. selection: {
  76. mode: 'none'
  77. },
  78. searchViewItems: [
  79. { id: 'MenuPath' },
  80. { id: 'Name' },
  81. { id: 'MenuId' }//ignoreValue: 0, defaultValue: 0, withCheckId: 'FirstClassId', value: searchFacilityClassValues[1], dataSource: searchFacilityClasses[1], handleChangedValue: handleSecondClassChangedValueInSearchView },
  82. ],
  83. handleViewShown: function () {
  84. sidemenuHashSet = $SideMenu.getSidemenuHashSet();
  85. _.each(sidemenuHashSet, function (items, id) {
  86. items['MenuId'] = id;
  87. items['Used'] = true;
  88. });
  89. //$SearchView.visibleObservable(false);
  90. },
  91. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  92. }
  93. });
  94. function handleSave() {
  95. saving(true);
  96. var rows = utils.datagrid.getItems($('#gridContainer').dxDataGrid('instance'));
  97. var newmenus = [];
  98. _.each(rows, function (menu) {
  99. newmenus.push({
  100. SiteId: BWA.UserInfo.SiteId(),
  101. MenuId: menu.MenuId(),
  102. MenuPath: menu.MenuPath(),
  103. Used: menu.Used(),
  104. Name: menu.Name(),
  105. });
  106. });
  107. BWA.api.post('CmMenu/DeleteAll', { SiteId: BWA.UserInfo.SiteId() }).done(function () {
  108. BWA.api.post('CmMenu/InsertAll', newmenus).done(function () {
  109. viewModel.refreshList();
  110. utils.toast.show($G('successDatabaseProcessMsg'));
  111. saving(false);
  112. });
  113. });
  114. }
  115. // 메뉴 초기화
  116. function handleEdit() {
  117. var newmenus = [];
  118. _.each(sidemenuHashSet, function (menu) {
  119. newmenus.push({
  120. SiteId: BWA.UserInfo.SiteId(),
  121. MenuId: menu.MenuId,
  122. MenuPath: menu.MenuPath,
  123. Name: menu.Name,
  124. Used: true,
  125. });
  126. });
  127. BWA.api.post('CmMenu/DeleteAll', { SiteId: BWA.UserInfo.SiteId() }).done(function () {
  128. BWA.api.post('CmMenu/InsertAll', newmenus).done(function () {
  129. viewModel.refreshList();
  130. utils.toast.show($G('successDatabaseProcessMsg'));
  131. });
  132. });
  133. }
  134. function handleHeaderCheckboxValueFunc(index) {
  135. return function (check) {
  136. var rows = utils.datagrid.getItems($('#gridContainer').dxDataGrid('instance'));
  137. _.each(rows, function (data, i) {
  138. data.checkboxes[index].dxCheckBox({
  139. value: check
  140. });
  141. });
  142. };
  143. }
  144. headerCheckBoxValues.subscribe(handleHeaderCheckboxValueFunc(0))
  145. viewModel.popupVisible.subscribe(function (visible) {
  146. });
  147. viewModel.handleSave = handleSave;
  148. viewModel.handleEdit = handleEdit;
  149. viewModel.sidemenuHashSet = sidemenuHashSet;
  150. viewModel.saving = saving;
  151. return viewModel;
  152. };