67f5ec13a047b2ac3e66aa68262cd1b2222e500a.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. BemsWebApplication.WorkCodeCauseClass = function (params, viewInfo) {
  2. "use strict";
  3. var dbModelId = 'FmsWorkCodeCauseClass';
  4. var initialized = false,
  5. shouldReload = false,
  6. dataViewModel = new BemsWebApplication.FmsWorkCodeCauseClassViewModel(),
  7. isNewInPopup = ko.observable(false),
  8. isEditModeInPopup = ko.observable(false),
  9. isViewModeInPopup = ko.observable(true),
  10. visibleCancelButton = ko.observable(false),
  11. selectedIds = [{}, {}, {}],
  12. gridViews = [],
  13. popupVisible = ko.observable(false),
  14. popupVisibles = [ko.observable(false), ko.observable(false)],
  15. buttonEditDisabledFlags = [ko.observable(true), ko.observable(true)],
  16. dataSources = [];
  17. var selectedClass = 0;
  18. var isClass2 = ko.observable(false);
  19. popupVisible.subscribe(function (visible) {
  20. if (visible == false) {
  21. //$.each( selectedIds[selectedClass] , function( name ) {
  22. // delete selectedIds[selectedClass][name];
  23. //});
  24. $.each(popupVisibles, function (i, item) {
  25. item(false);
  26. });
  27. }
  28. });
  29. popupVisibles[0].subscribe(function (visible) {
  30. selectedClass = 0;
  31. isClass2(false);
  32. if (visible) popupVisible(visible);
  33. });
  34. popupVisibles[1].subscribe(function (visible) {
  35. selectedClass = 1;
  36. isClass2(true);
  37. if (visible) popupVisible(visible);
  38. });
  39. function handleModification() {
  40. shouldReload = true;
  41. }
  42. function handleSelectionChanged(selectedRowsInfo) {
  43. var id = $(selectedRowsInfo.element).attr('id');
  44. console.log(selectedRowsInfo.selectedRowKeys.length);
  45. switch (id) {
  46. case 'gridContainer1':
  47. {
  48. buttonEditDisabledFlags[0](selectedRowsInfo.selectedRowKeys.length == 0);
  49. break;
  50. }
  51. case 'gridContainer2':
  52. {
  53. buttonEditDisabledFlags[1](selectedRowsInfo.selectedRowKeys.length == 0);
  54. break;
  55. }
  56. }
  57. console.log(selectedRowsInfo.selectedRowKeys);
  58. }
  59. function handleViewShown() {
  60. if (shouldReload) {
  61. shouldReload = false;
  62. for (var i = 0 ; i < 2 ; i++) {
  63. dataSources[i].pageIndex(0);
  64. dataSources[i].load();
  65. }
  66. }
  67. if (initialized === false) {
  68. for (var j = 0 ; j < 2 ; j++) {
  69. var options = j == 1 ? {
  70. columns: [
  71. { dataField: 'Name', caption: $G('className'), width: '70%', alignment: 'center' },
  72. utils.datagrid.columnIsUse('30%')
  73. ],
  74. } : {
  75. columns: [
  76. { dataField: 'Number', caption: $G('number'), width: '30%', alignment: 'center' },
  77. { dataField: 'Name', caption: $G('className'), width: '70%', alignment: 'center' }
  78. ],
  79. useNumberColumn: true,
  80. };
  81. options.selectedSourceItem = dataViewModel;
  82. options.dbId = dbModelId;
  83. options.dxDataSource = dataSources[j];
  84. options.selectedId = selectedIds[j];
  85. options.datagridId = 'gridContainer' + (j + 1);
  86. options.selectionChanged = handleSelectionChanged;
  87. options.popupVisible = popupVisibles[j];
  88. options.handleDataGridRowClick = handleDataGridRowClick;
  89. var id = '#' + options.datagridId;
  90. $(id).dxDataGrid(utils.datagrid.defaultOptions(options));
  91. gridViews[j] = $(id).dxDataGrid('instance');
  92. }
  93. initialized = true;
  94. }
  95. $SideMenu.showSideMenuIfWill(params.view);
  96. }
  97. function refreshDataSource(dataIndex, parentId) {
  98. dataSources[dataIndex].filter('ParentId', '=', parentId);
  99. dataSources[dataIndex].pageIndex(0);
  100. dataSources[dataIndex].load();
  101. gridViews[dataIndex].option('dataSource', utils.datagrid.dataSource(dataSources[dataIndex]));
  102. gridViews[dataIndex].refresh();
  103. }
  104. function handleDataGridRowClick(id, dataGrid, clickRow) {
  105. switch (id) {
  106. case 'gridContainer1':
  107. {
  108. refreshDataSource(1, clickRow.data.ClassId());
  109. break;
  110. }
  111. }
  112. }
  113. function handleViewDisposing() {
  114. BemsWebApplication.db[dbModelId].modified.remove(handleModification);
  115. }
  116. var dataSourceOptions = {
  117. store: BemsWebApplication.db[dbModelId],
  118. map: function (item) {
  119. return new BemsWebApplication.FmsWorkCodeCauseClassViewModel(item);
  120. }
  121. };
  122. for (var k = 0 ; k < 2 ; k++) {
  123. dataSources[k] = new DevExpress.data.DataSource(dataSourceOptions);
  124. }
  125. dataSources[0].filter([
  126. ['SiteId', '=', BWA.UserInfo.SiteId()],
  127. 'and',
  128. ['ParentId', '=', 0]
  129. ]);
  130. dataSources[1].filter('ParentId', '=', -1);
  131. function refreshList() {
  132. for (var i = 0 ; i < 2 ; i++) {
  133. dataSources[i].pageIndex(0);
  134. dataSources[i].load();
  135. gridViews[i].refresh();
  136. }
  137. }
  138. function handlePopupShowing(e) {
  139. visibleCancelButton(false);
  140. if (isNewInPopup() == false) {
  141. activePopupViewMode();
  142. BemsWebApplication.db[dbModelId].byKey(selectedIds[selectedClass]).done(function (data) {
  143. dataViewModel.fromJS(data);
  144. });
  145. }
  146. else {
  147. //activePopupInsertMode();
  148. clearDataModelValue(dataViewModel);
  149. }
  150. }
  151. function clearDataModelValue(v) {
  152. $.each(v, function (name, value) {
  153. if (name !== 'ParentId') {
  154. v[name](null);
  155. }
  156. });
  157. v.SiteId(BWA.UserInfo.SiteId());
  158. console.log(v.ParentId());
  159. }
  160. BemsWebApplication.db[dbModelId].modified.add(handleModification);
  161. function handleConfirmDelete() {
  162. BemsWebApplication.db[dbModelId].remove(selectedIds[selectedClass]).done(function () {
  163. popupVisible(false);
  164. utils.toast.show('데이터베이스 항목 삭제 작업이 성공하였습니다.');
  165. });
  166. }
  167. function update() {
  168. //console.log( dataViewModel.BuildingId() );
  169. BemsWebApplication.db[dbModelId].update(selectedIds[selectedClass], dataViewModel.toJS()).done(function () {
  170. refreshList();
  171. utils.toast.show('데이터베이스 항목 수정 작업이 성공하였습니다.');
  172. // popupVisible( false );
  173. });
  174. }
  175. function insert() {
  176. BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS()).done(function (values, newId) {
  177. refreshList();
  178. popupVisible(false);
  179. });
  180. }
  181. function activePopupEditMode() {
  182. isViewModeInPopup(false);
  183. isEditModeInPopup(true);
  184. }
  185. function activePopupViewMode() {
  186. isViewModeInPopup(true);
  187. isEditModeInPopup(false);
  188. }
  189. function handlePopupButtonEdit() {
  190. activePopupEditMode();
  191. visibleCancelButton(true);
  192. }
  193. function handlePopupButtonCancel() {
  194. activePopupViewMode();
  195. visibleCancelButton(false);
  196. }
  197. function popupInsertView() {
  198. activePopupEditMode();
  199. popupVisible(true);
  200. }
  201. function handlePopupButtonSave() {
  202. if (isNewInPopup())
  203. insert();
  204. else
  205. update();
  206. }
  207. function handlePopupButtonDelete() {
  208. DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
  209. if (result) {
  210. handleConfirmDelete();
  211. refreshList();
  212. }
  213. else {
  214. // toast
  215. }
  216. });
  217. }
  218. function handlePopupButtonClose() {
  219. popupVisible(false);
  220. }
  221. var toolbarItems = [
  222. { location: 'before', text: $G('detailInfo') },
  223. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: isViewModeInPopup, clickAction: handlePopupButtonEdit } },
  224. { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: isViewModeInPopup, clickAction: handlePopupButtonDelete } },
  225. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, clickAction: handlePopupButtonSave } },
  226. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'arrowleft', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  227. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  228. //{ location: 'right', widget: 'button', options: { text: '@edit', click: handleEdit } },
  229. //{ location: 'after', widget: 'button', options: { icon: 'find' } },
  230. //{ location: 'menu', text: 'Add' },
  231. //{ location: 'center', text: 'Products' }
  232. ];
  233. var popupOptions = {
  234. width: '480px',
  235. height: 'auto',
  236. visible: popupVisible,
  237. closeOnOutsideClick: true,
  238. showingAction: handlePopupShowing,
  239. animation: {
  240. show: { type: "pop", duration: 200, from: { opacity: 1, scale: 0.4 }, to: { scale: 1 } },
  241. hide: { type: "fade", duration: 200, from: 1, to: 0 }
  242. }
  243. };
  244. function setInsertPopupInfo(index, classId) {
  245. isNewInPopup(true);
  246. activePopupEditMode();
  247. dataViewModel.ParentId(classId);
  248. popupVisibles[index](true);
  249. }
  250. return {
  251. dataModel: dataViewModel,
  252. refreshList: refreshList,
  253. buttonEditDisabledFlags: buttonEditDisabledFlags,
  254. //viewShowing: handleViewShowing ,
  255. viewShown: handleViewShown,
  256. viewDisposing: handleViewDisposing,
  257. popupInsertView: popupInsertView,
  258. isViewModeInPopup: isViewModeInPopup,
  259. isEditModeInPopup: isEditModeInPopup,
  260. isNewInPopup: isNewInPopup,
  261. popupOptions: popupOptions,
  262. toolbarItems: toolbarItems,
  263. isClass2: isClass2,
  264. buttonInsertClass1: function () {
  265. setInsertPopupInfo(0, 0);
  266. },
  267. buttonInsertClass2: function () {
  268. setInsertPopupInfo(1, selectedIds[0].ClassId);
  269. },
  270. buttonEditClass1: function () {
  271. isNewInPopup(false);
  272. popupVisibles[0](true);
  273. },
  274. buttonEditClass2: function () {
  275. isNewInPopup(false);
  276. popupVisibles[1](true);
  277. },
  278. };
  279. };