8713fa0857d48e256a585d44166302d8fabd121e.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. BemsWebApplication.AnyCheckSchedule = function (params, viewInfo, executionPlanOptions) {
  2. "use strict";
  3. var businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true),
  4. workTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeType'),
  5. progressDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeProgress'),
  6. FmsWorkRequestDataSource = BemsWebApplication.db.createDataSource('FmsWorkRequest'),
  7. businessFields = ko.observableArray(),
  8. workTypes = ko.observableArray(),
  9. progresses = ko.observableArray();
  10. var workrequest = ko.observableArray();
  11. var RowName;
  12. var deferredForSearch = new $.Deferred();
  13. var workTypesForSearch = ko.observableArray(),
  14. businessFieldsForSearch = ko.observableArray(),
  15. progressesForSearch = ko.observableArray();
  16. var popup;
  17. var eq = BWA.DataUtil.constructEqualFilter,
  18. and = BWA.DataUtil.andFilter,
  19. noteq = BWA.DataUtil.constructNotEqualFilter;
  20. var workTypeId = $Code.WorkType.INNER_CHECK;
  21. var executionPlanViewOptions = undefined,
  22. executionPlanPopupOptions = undefined;
  23. if (executionPlanOptions) {
  24. executionPlanViewOptions = executionPlanOptions.viewOptions;
  25. executionPlanPopupOptions = executionPlanOptions.popupOptions;
  26. }
  27. var selectedFacilityData = ko.observable(),
  28. selectedUserData = params.selectedUserData || ko.observable();
  29. var dataSourceOptions = {
  30. select: [
  31. 'SiteId', 'WorkRequestId', 'WorkTypeId', 'Title', 'RequestDate', 'WorkProgressId', 'StartWorkDate',
  32. 'CmUser/Name', // 신청자
  33. 'CmUser1/Name', // 반려자
  34. 'FmsWorkCodeType/Name', 'CmBusinessField/Name', 'FmsWorkCodeProgress/Name'
  35. ],
  36. expand: ['FmsWorkCodeType', 'CmBusinessField', 'FmsWorkCodeProgress', 'CmUser', 'CmUser1'],
  37. extendOptions: {
  38. forceOriginalField: true
  39. }
  40. };
  41. if (_.isUndefined(executionPlanViewOptions)) {
  42. dataSourceOptions.filter = [
  43. eq('SiteId', BWA.UserInfo.SiteId()),
  44. and,
  45. eq('WorkTypeId', $Code.WorkType.INNER_CHECK),
  46. and,
  47. eq('WorkProgressId', $Code.WorkProgress.WORK_PLAN)
  48. ];
  49. }
  50. else {
  51. // 시설관리 > 실행계획조회 화면에서는 작업계획 상태만 가져옴
  52. dataSourceOptions.filter = [
  53. eq('SiteId', BWA.UserInfo.SiteId()),
  54. and,
  55. [
  56. eq('WorkProgressId', $Code.WorkProgress.WORK_PLAN)
  57. ]
  58. ];
  59. }
  60. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkRequest', {
  61. popupWidth: 1200,
  62. dataSourceOptions: dataSourceOptions,
  63. columns: [
  64. { dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center', sortOrder: 'desc', },
  65. { dataField: 'FmsWorkCodeProgress/Name', caption: $G('workProgressName'), width: '10%', alignment: 'center', visible: false },
  66. { dataField: 'FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '10%', alignment: 'center', visible: false },
  67. { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
  68. { dataField: 'Title', caption: '작업명', width: '55%', alignment: 'center' },
  69. {
  70. dataField: 'StartWorkDate', caption: '작업예정일', width: '12%', alignment: 'center',
  71. customizeText: function (cellInfo) {
  72. return $G.date(cellInfo.value);
  73. }
  74. },
  75. { dataField: 'CmUser/Name', caption: $G('requesterName'), width: '15%', alignment: 'center' }
  76. ],
  77. promiseDataInSearchView: deferredForSearch.promise(),
  78. searchViewItems: _.compact([
  79. { id: 'WorkProgressId', ignoreValue: 0, defaultValue: 0, dataSource: progressesForSearch },
  80. { id: 'WorkTypeId', ignoreValue: 0, defaultValue: 0, dataSource: workTypesForSearch },
  81. { id: 'Title' },
  82. { id: 'CmUser/Name' },
  83. { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  84. { id: 'StartWorkDate', type: 'dateRange', isOnlyDate: true}
  85. ]),
  86. paging: {
  87. enabled: true,
  88. pageSize: 20
  89. },
  90. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  91. dataGrid.clearSelection();
  92. var data = clickRow.data;
  93. var dataModel = viewModel.dataModel;
  94. RowName = data.Title;
  95. // 정기, 법정인 경우는 반려가 안보이게 2016 06 16 hcLee
  96. if (!_.isUndefined(viewModel.executionPlanPopupOptions)) {
  97. if (data.WorkTypeId() < 3)
  98. viewModel.executionPlanPopupOptions.isVisibleRejectButtons(false);
  99. else
  100. viewModel.executionPlanPopupOptions.isVisibleRejectButtons(true);
  101. }
  102. if (popup && popup.handleBeforeShowingPopupForEdit) {
  103. popup.handleBeforeShowingPopupForEdit(data, dataModel);
  104. }
  105. popupVisible(true);
  106. },
  107. handleBeforePopupShowingPromise: function () {
  108. if (popup && popup.handleBeforePopupShowingPromise) {
  109. popup.handleBeforePopupShowingPromise.apply(popup, arguments);
  110. }
  111. },
  112. handleAfterLoadingModelByKey: function () {
  113. if (popup && popup.handleAfterLoadingModelByKey) {
  114. popup.handleAfterLoadingModelByKey.apply(popup, arguments);
  115. }
  116. },
  117. handlePopupShowing: function () {
  118. if (popup && popup.handlePopupShowing) {
  119. popup.handlePopupShowing.apply(this, arguments);
  120. }
  121. FmsWorkRequestDataSource.filter([
  122. ["SiteId", "=", BWA.UserInfo.SiteId()],
  123. 'and',
  124. ["WorkTypeId", "=", 5]
  125. ]);
  126. FmsWorkRequestDataSource.load().done(function (result) {
  127. workrequest(result);
  128. });
  129. },
  130. handlePopupShown: function (editMode, isNewInPopup, dataModel) {
  131. if (popup && popup.handlePopupShown) {
  132. popup.handlePopupShown.apply(this, arguments);
  133. }
  134. },
  135. handleSaveButtonInPopup: function (isInsert) {
  136. if (isInsert === false) {
  137. if (popup && popup.handleAfterSave) {
  138. popup.handleAfterSave(undefined);
  139. }
  140. }
  141. },
  142. handleAfterSaveInPopup: function (responseKey, response) {
  143. if (popup && popup.handleAfterSave) {
  144. popup.handleAfterSave(responseKey, response);
  145. }
  146. },
  147. getAddedToolbarItemsInPopup: function (e) {
  148. var isEditModeInPopup = e.isEditModeInPopup;
  149. var addedTooolbarItems = [
  150. {
  151. location: 'after', widget: 'button', options: {
  152. text: $G('facilityInsertion'), icon: 'search', visible: isEditModeInPopup,
  153. clickAction: function () { popup.facilitySearchPopup.show(); }
  154. }
  155. },
  156. {
  157. location: 'after', widget: 'button', options: {
  158. text: $G('facilityDeletion'), icon: 'remove', type: 'danger', visible: isEditModeInPopup,
  159. clickAction: function () {
  160. if (popup && popup.handleDeleteSelectedFacilities) { popup.handleDeleteSelectedFacilities(); }
  161. }
  162. }
  163. }];
  164. // 실행계획조회 인 경우 툴바아이템 추가
  165. if (!_.isUndefined(executionPlanPopupOptions)) {
  166. var executionToolbarItems = executionPlanPopupOptions.getAddedToolbarItemsInPopup(e);
  167. var resultToolbarItems = addedTooolbarItems.concat(executionToolbarItems);
  168. return resultToolbarItems;
  169. }
  170. return addedTooolbarItems;
  171. },
  172. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  173. var dfd = $.Deferred();
  174. var isDuplicated = false;
  175. for (var i = 0; i < workrequest().length; i++) {
  176. if (dataModel.Title() == workrequest()[i].Title() && dataModel.BusinessFieldId() == workrequest()[i].BusinessFieldId()) {
  177. isDuplicated = true;
  178. }
  179. }
  180. if (!BWA.DataUtil.isValidInputValue(dataModel.Title()))
  181. return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
  182. else {
  183. if (isDuplicated)
  184. return dfd.resolve(false, '이미 동일 정보가 존재합니다.');
  185. else
  186. return dfd.resolve(true);
  187. }
  188. },
  189. beforeUpdateDataViewModel: function () {
  190. var isDuplicated = false;
  191. for (var i = 0; i < workrequest().length; i++) {
  192. if (viewModel.dataModel.Title() == workrequest()[i].Title() && viewModel.dataModel.BusinessFieldId() == workrequest()[i].BusinessFieldId()
  193. && (RowName() != workrequest()[i].Title())) {
  194. isDuplicated = true;
  195. }
  196. }
  197. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Title())) {
  198. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  199. return 0;
  200. }
  201. else {
  202. if (isDuplicated) {
  203. utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
  204. return 0;
  205. }
  206. else
  207. return 2;
  208. }
  209. },
  210. handleViewShowing: function (dataModel) {
  211. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName)
  212. if (useBusinessFiltering) {
  213. dataSourceOptions.filter.push('and');
  214. dataSourceOptions.filter.push([eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  215. businessFieldDataSource.filter([
  216. eq('SiteId', BWA.UserInfo.SiteId()),
  217. and,
  218. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
  219. ]);
  220. }
  221. $.when(
  222. businessFieldDataSource.load(),
  223. workTypeDataSource.load(),
  224. progressDataSource.load()
  225. ).done(function (businessFieldResult, workTypeResult, progressResult) {
  226. businessFields(businessFieldResult[0]);
  227. workTypes(workTypeResult[0]);
  228. progresses(progressResult[0]);
  229. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  230. workTypesForSearch($SearchView.createArrayOfSelectBox('WorkTypeId', workTypes()));
  231. progressesForSearch($SearchView.createArrayOfSelectBox('ProgressId', progresses()));
  232. deferredForSearch.resolve();
  233. });
  234. },
  235. handleViewShown: function () {
  236. }
  237. });
  238. viewModel.businessFields = businessFields;
  239. viewModel.workTypes = workTypes;
  240. viewModel.executionPlanViewOptions = executionPlanViewOptions;
  241. viewModel.executionPlanPopupOptions = executionPlanPopupOptions; // hcLee 2016 06 16
  242. popup = viewModel.popup = BWA.Popup.AnyCheckSchedule.create(viewInfo, viewModel, executionPlanPopupOptions);
  243. return viewModel;
  244. };