b8bae2cb3d3558b087864925ed8a25ad659e67c9.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. BemsWebApplication.WorkExecution = function (params, viewInfo) {
  2. "use strict";
  3. //권한설정
  4. var hasnotModificationPermission = ko.observable(true);
  5. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  6. var businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true),
  7. workTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeType'),
  8. progressDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeProgress'),
  9. businessFields = ko.observableArray(),
  10. workTypes = ko.observableArray(),
  11. progresses = ko.observableArray();
  12. var isVisibleExecutionButton = ko.observable(true);
  13. var popup, workExecutionRegisterPopup = null;
  14. var deferredForSearch = new $.Deferred();
  15. var workTypesForSearch = ko.observableArray(),
  16. businessFieldsForSearch = ko.observableArray(),
  17. progressesForSearch = ko.observableArray();
  18. var eq = BWA.DataUtil.constructEqualFilter,
  19. and = BWA.DataUtil.andFilter,
  20. noteq = BWA.DataUtil.constructNotEqualFilter;
  21. var selectedFacilityData = ko.observable(),
  22. selectedUserData = params.selectedUserData || ko.observable();
  23. var dataSourceOptions = {
  24. select: [
  25. 'SiteId', 'WorkRequestId',
  26. 'FmsWorkRequest/WorkTypeId', 'Title', 'OrderDate', 'FmsWorkRequest/WorkProgressId',
  27. 'CmUser/Name', // 작업지시자
  28. //'CmUser1/Name', // 반려자
  29. 'FmsWorkRequest/FmsWorkCodeType/Name',
  30. 'FmsWorkRequest/CmBusinessField/Name',
  31. 'FmsWorkRequest/FmsWorkCodeProgress/Name',
  32. 'FmsWorkResult/CmUser/Name', 'BusinessFieldId',
  33. 'FmsWorkRequest/Content',
  34. 'FmsWorkRequest/StartWorkDate',
  35. 'StartWorkDate', // 2016 03 11 추가 hcLee
  36. 'FmsWorkResult/StartDate', // 2016 03 11 추가 hcLee
  37. 'FmsWorkRequest/BusinessFieldId'
  38. ],
  39. expand: [
  40. 'FmsWorkRequest',
  41. 'FmsWorkResult',
  42. 'FmsWorkResult/CmUser',
  43. 'FmsWorkRequest/FmsWorkCodeType',
  44. 'FmsWorkRequest/CmBusinessField',
  45. 'FmsWorkRequest/FmsWorkCodeProgress',
  46. 'CmBusinessField', 'CmUser'],
  47. //expand: ['FmsWorkCodeType', 'CmBusinessField', 'FmsWorkCodeProgress', 'CmUser', 'CmUser1'],
  48. extendOptions: {
  49. forceOriginalField: true
  50. }
  51. };
  52. if (!useBusinessFiltering) {
  53. dataSourceOptions.filter = [
  54. eq('SiteId', BWA.UserInfo.SiteId()),
  55. and,
  56. [
  57. eq('FmsWorkRequest/WorkProgressId', 3),
  58. 'or',
  59. eq('FmsWorkRequest/WorkProgressId', 7)
  60. ]
  61. ];
  62. }
  63. else {
  64. dataSourceOptions.filter = [
  65. eq('SiteId', BWA.UserInfo.SiteId()),
  66. and,
  67. [
  68. eq('FmsWorkRequest/WorkProgressId', 3),
  69. 'or',
  70. eq('FmsWorkRequest/WorkProgressId', 7)
  71. ],
  72. and,
  73. [
  74. eq('FmsWorkRequest/BusinessFieldId', BWA.UserInfo.BusinessFieldId()),
  75. 'or',
  76. eq('FmsWorkRequest/BusinessFieldId', 1)
  77. ]
  78. ];
  79. }
  80. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkOrder', {
  81. popupWidth: 1200,
  82. dataSourceOptions: dataSourceOptions,
  83. columns: [
  84. { dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center' },
  85. { dataField: 'FmsWorkRequest/CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
  86. { dataField: 'FmsWorkRequest/FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '10%', alignment: 'center' },
  87. {
  88. dataField: 'OrderDate', caption: $G('orderedDate'), width: '12%', alignment: 'center', sortOrder: 'desc', visible: false,
  89. customizeText: function (cellInfo) {
  90. return $G.date(cellInfo.value);
  91. }
  92. },
  93. //{ dataField: 'FmsWorkRequest/FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '10%', alignment: 'center' },
  94. {
  95. dataField: 'StartWorkDate', caption: '시작일', width: '12%', alignment: 'center', sortOrder: 'desc',
  96. customizeText: function (cellInfo) {
  97. return $G.date(cellInfo.value);
  98. }
  99. },
  100. /* {
  101. //dataField: 'StartWorkDate', caption: '작업시작일', width: '12%', alignment: 'center', sortOrder: 'desc',
  102. dataField: 'FmsWorkResult/StartDate', caption: '작업시작일', width: '12%', alignment: 'center', sortOrder: 'desc',
  103. customizeText: function (cellInfo) {
  104. return $G.date(cellInfo.value);
  105. } // 만일 이게 문제가 발생되면 Order의 StartDate를 업데이트가 필요하다. hcLee 2016 03 11
  106. }, */
  107. { dataField: 'Title', caption: '작업명', width: '35%', alignment: 'center' },
  108. { dataField: 'FmsWorkRequest/FmsWorkCodeProgress/Name', caption: $G('workProgressName'), width: '10%', alignment: 'center' },
  109. { dataField: 'CmUser/Name', caption: '작업지시자', width: '15%', alignment: 'center' },
  110. { dataField: 'FmsWorkResult/CmUser/Name', caption: '작업자', width: '15%', alignment: 'center', visible: false },
  111. { dataField: 'FmsWorkRequest/Content', caption: '신청내용', width: '0%', alignment: 'center' },
  112. ],
  113. rowPrepared: function (rowElement, rowInfo) {
  114. if (rowInfo.rowType == 'data') {
  115. var now = new Date();
  116. var data = rowInfo.data;
  117. if (data['FmsWorkRequest/WorkProgressId']() == 3) {
  118. if (data['StartWorkDate']() <= now) {
  119. rowElement.css('background-color', 'rgba(255,0,0,0.1)');
  120. }
  121. }
  122. }
  123. },
  124. promiseDataInSearchView: deferredForSearch.promise(),
  125. searchViewItems: _.compact([
  126. { id: 'FmsWorkRequest/BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  127. //{ id: 'WorkTypeId', ignoreValue: 0, defaultValue: 0, dataSource: workTypesForSearch },
  128. { id: 'CmUser/Name' },
  129. { id: 'Title' },
  130. { id: 'WorkProgressId', ignoreValue: 0, defaultValue: 0, dataSource: progressesForSearch },
  131. { id: 'StartWorkDate', type: 'dateRange', isOnlyDate: true }
  132. ]),
  133. getAddedToolbarItemsInPopup: function (e) {
  134. var isEditModeInPopup = e.isEditModeInPopup;
  135. return [
  136. {
  137. location: 'after', widget: 'button', options: {
  138. text: '작업수행', icon: 'add', type: 'success', visible: isVisibleExecutionButton, disabled: hasnotModificationPermission,
  139. clickAction: saveWorkResult
  140. }
  141. },
  142. {
  143. location: 'after', widget: 'button', options: {
  144. text: $G('facilityInsertion'), icon: 'search', visible: isEditModeInPopup,
  145. clickAction: function () {
  146. popup.facilitySearchPopup.show();
  147. }
  148. }
  149. },
  150. {
  151. location: 'after', widget: 'button', options: {
  152. text: $G('facilityDeletion'), icon: 'remove', type: 'danger', visible: isEditModeInPopup,
  153. clickAction: function () {
  154. if (popup && popup.handleDeleteSelectedFacilities) {
  155. popup.handleDeleteSelectedFacilities();
  156. }
  157. }
  158. }
  159. }];
  160. },
  161. beforeInsertingDataViewModel: function (dataModel) {
  162. return true;
  163. },
  164. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  165. dataGrid.clearSelection();
  166. var data = clickRow.data;
  167. var dataModel = viewModel.dataModel;
  168. if (data['FmsWorkRequest/WorkProgressId']() >= $Code.WorkProgress.WORKING) {
  169. isVisibleExecutionButton(false);
  170. }
  171. else {
  172. isVisibleExecutionButton(true);
  173. }
  174. if (popup && popup.handleBeforeShowingPopupForEdit) {
  175. popup.handleBeforeShowingPopupForEdit(data, dataModel);
  176. }
  177. popupVisible(true);
  178. },
  179. handleBeforePopupShowingPromise: function () {
  180. if (popup && popup.handleBeforePopupShowingPromise) {
  181. popup.handleBeforePopupShowingPromise.apply(popup, arguments);
  182. }
  183. },
  184. handleAfterLoadingModelByKey: function () {
  185. if (popup && popup.handleAfterLoadingModelByKey) {
  186. popup.handleAfterLoadingModelByKey.apply(popup, arguments);
  187. }
  188. },
  189. handlePopupShowing: function () {
  190. if (popup && popup.handlePopupShowing) {
  191. //viewModel.toolbarItems[4].options.visible = false;
  192. popup.handlePopupShowing.apply(this, arguments);
  193. }
  194. },
  195. handlePopupShown: function (editMode, isNewInPopup, dataModel) {
  196. if (popup && popup.handlePopupShowing) {
  197. popup.handlePopupShown.apply(this, arguments);
  198. }
  199. },
  200. handleSaveButtonInPopup: function (isInsert) {
  201. if (isInsert === false) {
  202. if (popup && popup.handleAfterSave) {
  203. popup.handleAfterSave(undefined);
  204. }
  205. }
  206. },
  207. handleAfterSaveInPopup: function (responseKey, response) {
  208. if (popup && popup.handleAfterSave) {
  209. popup.handleAfterSave(responseKey, response);
  210. }
  211. },
  212. handleViewShowing: function (dataModel) {
  213. //권한설정
  214. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  215. if (useBusinessFiltering) {
  216. businessFieldDataSource.filter([
  217. eq('SiteId', BWA.UserInfo.SiteId()),
  218. and,
  219. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
  220. ]);
  221. }
  222. $.when(
  223. businessFieldDataSource.load(),
  224. workTypeDataSource.load(),
  225. progressDataSource.load()
  226. ).done(function (businessFieldResult, workTypeResult, progressResult) {
  227. businessFields(businessFieldResult[0]);
  228. workTypes(workTypeResult[0]);
  229. progresses(progressResult[0]);
  230. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  231. workTypesForSearch($SearchView.createArrayOfSelectBox('WorkTypeId', workTypes()));
  232. progressesForSearch($SearchView.createArrayOfSelectBox('ProgressId', progresses()));
  233. deferredForSearch.resolve();
  234. });
  235. },
  236. handleViewShown: function () {
  237. }
  238. });
  239. viewModel.businessFields = businessFields;
  240. viewModel.workTypes = workTypes;
  241. popup = viewModel.popup = BWA.Popup.WorkExecution.create(viewInfo, viewModel);
  242. workExecutionRegisterPopup = viewModel.workExecutionRegisterPopup = BWA.Popup.WorkExecutionRegister.create(viewInfo, viewModel);
  243. function saveWorkResult() {
  244. workExecutionRegisterPopup.popupVisible(true);
  245. }
  246. return viewModel;
  247. };