f7947f84ae37255403a156f14372db46adeea7d6.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. BemsWebApplication.RegularCheckSchedule = function (params, viewInfo, legalCheckOptions) {
  2. "use strict";
  3. var cycleUnitDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeCycleUnit'),
  4. holidayWorkTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeHolidayWorkType', true, true),
  5. businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true),
  6. agencyDataSource = undefined;
  7. //var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, false, true);
  8. //var partnerTypes = ko.observableArray();
  9. //BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
  10. var popup;
  11. var IsUseStatusForSerach = ko.observable(); //추가
  12. var searchIsuseStatus = $SearchView.createObservableCodeNamesOfSelectBoxForSearch($G.IsUseName);// 추가
  13. var eq = BWA.DataUtil.constructEqualFilter, and = BWA.DataUtil.andFilter;
  14. var FmsWorkScheduleDataSource = BemsWebApplication.db.createDataSource('FmsWorkSchedule');
  15. var workschedule = ko.observableArray();
  16. var RowName, RowBusinessFieldId;
  17. var legalCheckViewOptions = undefined, legalCheckPopupOptions = undefined;
  18. var anyCheckViewOptions = undefined;
  19. if (legalCheckOptions) {
  20. legalCheckViewOptions = legalCheckOptions.viewOptions;
  21. legalCheckPopupOptions = legalCheckOptions.popupOptions;
  22. }
  23. var cycleUnits = ko.observableArray(), holidayWorkTypes = ko.observableArray(), businessFields = ko.observableArray(), agencies = undefined,
  24. businessFieldsForSearch = ko.observableArray(), agenciesForSearch = undefined;
  25. var deferredForSearch = new $.Deferred();
  26. var selectedScheduleId;
  27. var selectedScheduleName = ko.observable();
  28. var workTypeId = legalCheckViewOptions ? $Code.WorkType.LEGAL_CHECK : (anyCheckViewOptions ? $Code.WorkType.INNER_CHECK : $Code.WorkType.REGULAR_CHECK),
  29. dataSourceOptions = {
  30. select: [
  31. 'SiteId', 'WorkScheduleId', 'WorkTypeId', 'BusinessFieldId', 'Name',
  32. 'CycleSize', 'IsUse', 'IsAutoOrder', 'WorkDueDate',
  33. 'CmUser/Name', 'CmBusinessField/Name', 'FmsWorkCodeCycleUnit/Name', 'FmsWorkCodeHolidayWorkType/Name',
  34. 'CmPartner/Name'
  35. ],
  36. filter: [
  37. eq('SiteId', BWA.UserInfo.SiteId()),
  38. and,
  39. eq('WorkTypeId', workTypeId)
  40. ],
  41. expand: ['CmUser', 'CmBusinessField', 'FmsWorkCodeCycleUnit', 'FmsWorkCodeHolidayWorkType', 'CmPartner'],
  42. extendOptions: {
  43. forceOriginalField: true
  44. }
  45. };
  46. if (!_.isUndefined(legalCheckViewOptions)) {
  47. //dataSourceOptions.select.push('FmsWorkCodeLegalInspectionAgency/Name');
  48. //dataSourceOptions.expand.push('FmsWorkCodeLegalInspectionAgency');
  49. dataSourceOptions.select.push('CmPartner/Name');
  50. dataSourceOptions.expand.push('CmPartner');
  51. //agencyDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeLegalInspectionAgency', true, true);
  52. agencyDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
  53. agencyDataSource.filter([
  54. eq('PartnerTypeId', 3), // 검사기관
  55. and,
  56. eq('SiteId', BWA.UserInfo.SiteId())
  57. ])
  58. agencies = ko.observableArray();
  59. agenciesForSearch = ko.observableArray();
  60. }
  61. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkSchedule', {
  62. popupWidth: 1200,
  63. dataSourceOptions: dataSourceOptions,
  64. columns: _.compact([
  65. { dataField: 'WorkScheduleId', caption: $G('number'), width: '8%', alignment: 'center', sortOrder: 'desc' },
  66. { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
  67. { dataField: 'Name', caption: $G('facilityCheckScheduleName'), width: '34%', alignment: 'center' },
  68. {
  69. dataField: 'WorkDueDate', caption: $G('workDueDate'), width: '12%', alignment: 'center',
  70. customizeText: function (cellInfo) {
  71. return $G.date(cellInfo.value);
  72. }
  73. },
  74. { dataField: 'FmsWorkCodeHolidayWorkType/Name', caption: $G('facilityCheckScheduleHolidayName'), width: '10%', alignment: 'center' },
  75. { dataField: 'FmsWorkCodeCycleUnit/Name', caption: $G('facilityCheckScheduleCycleUnitName'), width: '10%', alignment: 'center' },
  76. legalCheckViewOptions ? { dataField: 'CmPartner/Name', caption: $G('legalInspectionAgency'), width: '15%', alignment: 'center' } : undefined,
  77. {
  78. dataField: 'IsAutoOrder', caption: $G("autoOrder"), alignment: 'center', width: '8%',
  79. customizeText: function (cellInfo) {
  80. return $G.isUse(cellInfo.value);
  81. }
  82. },
  83. utils.datagrid.columnIsUse('8%')
  84. ]),
  85. promiseDataInSearchView: deferredForSearch.promise(),
  86. searchViewItems: _.compact([
  87. { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  88. legalCheckViewOptions ? { id: 'InspectionAgencyId', ignoreValue: 0, defaultValue: 0, dataSource: agenciesForSearch } : undefined,
  89. { id: 'Name' },
  90. { id: 'WorkDueDate', type: 'dateRange', isOnlyDate: true},
  91. { id: 'IsUse', ignoreValue: 0, defaultValue: true, value: IsUseStatusForSerach, dataSource: searchIsuseStatus, isChecked: true } //추가 //$SearchView.handleSearchInSearchView();
  92. ]),//IsUseStatusForSerach
  93. wordWrapEnabled: true,
  94. cellPrepared: function (cellElement, cellInfo) {
  95. if (cellInfo.rowType == 'data') {
  96. switch (cellInfo.column.dataField) {
  97. case 'FmsWorkCodeCycleUnit/Name':
  98. $(cellElement).text(cellInfo.data.CycleSize() + ' ' + cellInfo.value);
  99. break;
  100. }
  101. }
  102. },
  103. handleInitializeDataModelValue: function (dataModel) {
  104. dataModel.IsAutoOrder(false);
  105. dataModel.WorkTypeId(workTypeId);
  106. dataModel.BusinessFieldId(BWA.UserInfo.BusinessFieldId());
  107. },
  108. // 이름 중복 방지
  109. handlePopupShowing: function () {
  110. if (popup && popup.handlePopupShowing) {
  111. popup.handlePopupShowing.apply(this, arguments);
  112. }
  113. FmsWorkScheduleDataSource.filter([
  114. ["SiteId", "=", BWA.UserInfo.SiteId()],
  115. 'and',
  116. ["WorkTypeId", "=", workTypeId]
  117. ]);
  118. FmsWorkScheduleDataSource.load().done(function (result) {
  119. workschedule(result);
  120. });
  121. },
  122. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  123. var dfd = $.Deferred();
  124. var isDuplicated = false;
  125. for (var i = 0; i < workschedule().length; i++) {
  126. if (dataModel.Name() == workschedule()[i].Name() && dataModel.BusinessFieldId() == workschedule()[i].BusinessFieldId()) {
  127. isDuplicated = true;
  128. }
  129. }
  130. if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
  131. return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
  132. else {
  133. if (isDuplicated)
  134. return dfd.resolve(false, '이미 동일 정보가 존재합니다.');
  135. else
  136. return dfd.resolve(true);
  137. }
  138. },
  139. beforeUpdateDataViewModel: function () {
  140. var isDuplicated = false;
  141. for (var i = 0; i < workschedule().length; i++) {
  142. if (viewModel.dataModel.Name() == workschedule()[i].Name() && viewModel.dataModel.BusinessFieldId() == workschedule()[i].BusinessFieldId()
  143. && (RowName() != workschedule()[i].Name() || RowBusinessFieldId() != workschedule()[i].BusinessFieldId())) {
  144. isDuplicated = true;
  145. }
  146. }
  147. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
  148. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  149. return 0;
  150. }
  151. else {
  152. if (isDuplicated) {
  153. utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
  154. return 0;
  155. }
  156. else
  157. return 2;
  158. }
  159. },
  160. handleViewShowing: function () {
  161. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  162. if (useBusinessFiltering) {
  163. dataSourceOptions.filter.push('and');
  164. dataSourceOptions.filter.push([eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  165. businessFieldDataSource.filter([
  166. eq('SiteId', BWA.UserInfo.SiteId()),
  167. and,
  168. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
  169. ]);
  170. }
  171. var loadFromDataSource = BWA.DataUtil.loadFromDataSource;
  172. //loadFromDataSource(holidayWorkTypeDataSource, holidayWorkTypes);
  173. $.when.apply($, _.compact([
  174. cycleUnitDataSource.load(),
  175. holidayWorkTypeDataSource.load(),
  176. businessFieldDataSource.load(),
  177. agencyDataSource ? agencyDataSource.load() : undefined
  178. ])).done(function (dbCycleUnits, dbHolidayWorkTypes, dbBusinessFields, dbAgencies) {
  179. cycleUnits(dbCycleUnits[0]);
  180. holidayWorkTypes(dbHolidayWorkTypes[0]);
  181. businessFields(dbBusinessFields[0]);
  182. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  183. if (!_.isUndefined(dbAgencies)) {
  184. agencies(dbAgencies[0]);
  185. agenciesForSearch($SearchView.createArrayOfSelectBox('PartnerId', agencies()));
  186. }
  187. deferredForSearch.resolve();
  188. });
  189. },
  190. handleAfterLoadingModelByKey: function (data, dataViewModel) {
  191. var dataModel = viewModel.dataModel;
  192. dataModel.CycleSizeText(data.CycleSize + ' ' + dataModel.CycleUnitName());
  193. if (popup && popup.handleAfterLoadingModelByKey) {
  194. popup.handleAfterLoadingModelByKey(data, dataViewModel);
  195. }
  196. },
  197. handleViewShown: function () { // 추가
  198. setTimeout(delayplay, 100);
  199. },
  200. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  201. dataGrid.clearSelection();
  202. var data = clickRow.data;
  203. var dataModel = viewModel.dataModel;
  204. if (popup && popup.handleBeforeShowingPopupForEdit) {
  205. popup.handleBeforeShowingPopupForEdit(data, dataModel);
  206. }
  207. RowName = data.Name;
  208. RowBusinessFieldId = data.BusinessFieldId;
  209. //selectedScheduleId = data.ScheduleId();
  210. //selectedScheduleName = $KoSet(selectedScheduleName, data.Name());
  211. //selectedCheckGroupDataSource.filter([
  212. // ['SiteId', '=', BWA.UserInfo.SiteId()],
  213. // 'and',
  214. // ['WorkScheduleId', '=', selectedScheduleId]
  215. //]);
  216. popupVisible(true);
  217. },
  218. handleSaveButtonInPopup: function (isInsert) {
  219. if (isInsert === false) {
  220. if (popup && popup.handleAfterSave) {
  221. popup.handleAfterSave(undefined);
  222. }
  223. }
  224. },
  225. handleAfterSaveInPopup: function (responseKey, response) {
  226. if (popup && popup.handleAfterSave) {
  227. popup.handleAfterSave(responseKey, response);
  228. }
  229. },
  230. getAddedToolbarItemsInPopup: function (e) {
  231. var isEditModeInPopup = e.isEditModeInPopup;
  232. return [{
  233. location: 'after', widget: 'button', options: {
  234. text: $G('facilityInsertion'), icon: 'search', visible: isEditModeInPopup,
  235. clickAction: function () {
  236. popup.facilitySearchPopup.show();
  237. }
  238. }
  239. }, {
  240. location: 'after', widget: 'button', options: {
  241. text: $G('facilityDeletion'), icon: 'remove', type: 'danger', visible: isEditModeInPopup,
  242. clickAction: function () {
  243. if (popup && popup.handleDeleteSelectedFacilities) {
  244. popup.handleDeleteSelectedFacilities();
  245. }
  246. }
  247. }
  248. }];
  249. },
  250. //handlePopupShown: function (editMode, isNewInPopup, dataModel) {
  251. // if (popup && popup.handlePopupShowing) {
  252. // popup.handlePopupShown.apply(this, arguments);
  253. // }
  254. //}
  255. });
  256. //function processValueChange(e) {
  257. // if ($G.date(viewModel.dataModel.WorkDueDate()) < $G.date(new Date()))
  258. // {
  259. // viewModel.dataModel.WorkDueDate(new Date());
  260. // utils.toast.show('작업예정일은 오늘 혹은 오늘 이후로 설정하시기 바랍니다.', 'error');
  261. // }
  262. //}
  263. function delayplay() {
  264. BemsWebApplication.app.currentViewInfo = viewInfo;
  265. BemsWebApplication.app.currentViewInfo.model.handleSearchInSearchView();
  266. }
  267. viewModel.dataModel.CycleSizeText = ko.observable();
  268. viewModel.cycleUnits = cycleUnits;
  269. viewModel.holidayWorkTypes = holidayWorkTypes;
  270. viewModel.businessFields = businessFields;
  271. viewModel.agencies = agencies;
  272. viewModel.legalCheckOptions = legalCheckOptions;
  273. popup = viewModel.popup = BWA.Popup.RegularCheckSchedule.create(viewInfo, viewModel, legalCheckPopupOptions);
  274. viewModel.popupVisible.subscribe(function (visible) {
  275. if (!visible) {
  276. popup.facilitiesInView([]);
  277. popup.facilities([]);
  278. }
  279. });
  280. //viewModel.processValueChange = processValueChange;
  281. return viewModel;
  282. };