debff258485e74c1115f158efe3c801dcb6cd207.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. BemsWebApplication.Accident = function (params, viewInfo) {
  2. "use strict";
  3. var imagefileUrl1 = ko.observable(),
  4. imagefileUrl2 = ko.observable(),
  5. imagefileUrl3 = ko.observable(),
  6. dropZone1 = null,
  7. dropZone2 = null,
  8. uploadedFileInfo = {};
  9. var isEditModeInPopup = ko.observable(false);
  10. var eq = BWA.DataUtil.constructEqualFilter,
  11. and = BWA.DataUtil.andFilter,
  12. noteq = BWA.DataUtil.constructNotEqualFilter;
  13. var accidentTypeDataSource = BemsWebApplication.db.createDataSource('FmsAccidentCodeType', true, false, true),
  14. companyDataSource = BemsWebApplication.db.createDataSource('CmCompany', true, true),
  15. departmentDataSource = BemsWebApplication.db.createDataSource('CmDepartment', true, true);
  16. var accidentTypesForSearch = ko.observableArray();
  17. var accidentTypes = ko.observableArray(),
  18. companies = ko.observableArray(),
  19. departments = ko.observableArray();
  20. var deferredForSearch = new $.Deferred();
  21. var dataSourceOptions = {
  22. select: [
  23. 'SiteId',
  24. 'AccidentId',
  25. 'Name',
  26. 'StartDate',
  27. 'EndDate',
  28. 'AccidentTypeId',
  29. 'DepartmentId',
  30. 'AccidentLocation',
  31. 'Reason',
  32. 'Action',
  33. 'Damage',
  34. 'Measurement',
  35. 'FileId1',
  36. 'FileId2',
  37. 'FileId3',
  38. 'CompanyId',
  39. 'CmFile/Name',
  40. 'CmFile1/Name',
  41. 'CmFile2/Name',
  42. 'FmsAccidentCodeType/Name',
  43. 'CmDepartment/Name',
  44. 'CmCompany/Name',
  45. ],
  46. expand: [
  47. 'CmDepartment',
  48. 'CmCompany',
  49. 'FmsAccidentCodeType',
  50. 'CmFile',
  51. 'CmFile1',
  52. 'CmFile2'
  53. ],
  54. extendOptions: {
  55. forceOriginalField: true
  56. }
  57. };
  58. function setupDropZone(isEditModeInPopup, dataViewModel) {
  59. var timer = null;
  60. isEditModeInPopup.subscribe(function (value) {//2019-11-12 변경
  61. if (value) {
  62. if (timer) { clearInterval(timer); }
  63. timer = setInterval(function () {
  64. if ($('#accidentDropZone1').length) {
  65. if (_.isNull(dropZone1)) {
  66. dropZone1 = BWA.DropZone.create({
  67. id: '#accidentDropZone1',
  68. categoryId: $Code.FileCategory.ACCIDENT,
  69. uploadedFileInfo: uploadedFileInfo,
  70. handleRemoveBeforePromise: function () {
  71. var keys = BWA.db.extractKeysObject('FmsAccident', dataViewModel);
  72. return BWA.db.FmsAccident.update(keys, { FileId1: null });
  73. },
  74. handleSuccess: function (fileInfo) {
  75. if (uploadedFileInfo.FileId) {
  76. dataViewModel.FileId1(fileInfo.FileId);
  77. var keys = BWA.db.extractKeysObject('FmsAccident', dataViewModel);
  78. if (keys.AccidentId != null) {
  79. return BWA.db.FmsAccident.update(keys, { FileId1: fileInfo.FileId })
  80. .done(function (res) {
  81. $('#gridContainer').dxDataGrid('instance').refresh();
  82. });
  83. }
  84. }
  85. },
  86. handleRemovedFile: function () {
  87. dataViewModel.FileId1(null);
  88. },
  89. });
  90. }
  91. }
  92. if ($('#accidentDropZone2').length) {
  93. if (_.isNull(dropZone2)) {
  94. dropZone2 = BWA.DropZone.create({
  95. id: '#accidentDropZone2',
  96. categoryId: $Code.FileCategory.ACCIDENT,
  97. uploadedFileInfo: uploadedFileInfo,
  98. handleRemoveBeforePromise: function () {
  99. var keys = BWA.db.extractKeysObject('FmsAccident', dataViewModel);
  100. return BWA.db.FmsAccident.update(keys, { FileId2: null });
  101. },
  102. handleSuccess: function (fileInfo) {
  103. if (uploadedFileInfo.FileId) {
  104. dataViewModel.FileId2(fileInfo.FileId);
  105. var keys = BWA.db.extractKeysObject('FmsAccident', dataViewModel);
  106. if (keys.AccidentId != null) {
  107. return BWA.db.FmsAccident.update(keys, { FileId2: fileInfo.FileId })
  108. .done(function (res) {
  109. $('#gridContainer').dxDataGrid('instance').refresh();
  110. });
  111. }
  112. }
  113. },
  114. handleRemovedFile: function () {
  115. dataViewModel.FileId2(null);
  116. },
  117. });
  118. }
  119. }
  120. }, 100);
  121. }
  122. else {
  123. if (timer) {
  124. clearInterval(timer);
  125. timer = null;
  126. }
  127. dropZone1 = null;
  128. dropZone2 = null;
  129. }
  130. });
  131. }
  132. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsAccident', {
  133. dataSourceOptions: dataSourceOptions,
  134. columns: [
  135. { dataField: 'AccidentId', caption: $G('number'), width: '10%', alignment: 'center' },
  136. { dataField: 'FmsAccidentCodeType/Name', caption: '사고유형', width: '20%', alignment: 'center' },
  137. { dataField: 'Name', caption: '사고명', width: '80%', alignment: 'center' },
  138. { dataField: 'CmDepartment/Name', caption: '담당부서', width: '30%', alignment: 'center' },
  139. {
  140. dataField: 'StartDate', caption: '사고발생일', width: '20%', alignment: 'center', sortOrder: 'desc', dataType: "shortDate", format: "yyyy-MM-dd",
  141. customizeText: function (cellInfo) {
  142. return cellInfo.valueText;
  143. }
  144. },
  145. {
  146. dataField: 'EndDate', caption: '조치완료일', width: '20%', alignment: 'center', dataType: "shortDate", format: "yyyy-MM-dd",
  147. customizeText: function (cellInfo) {
  148. return cellInfo.valueText;
  149. }
  150. },
  151. ],
  152. paging: {
  153. enabled: true,
  154. pageSize: 18
  155. },
  156. pager: {
  157. },
  158. "export": {
  159. enabled: true,
  160. fileName: '사고 목록',
  161. },
  162. onExporting: function (e) {
  163. e.component.columnOption("AccidentId", "visible", false);
  164. },
  165. onExported: function (e) {
  166. e.component.columnOption("AccidentId", "visible", true);
  167. },
  168. popupWidth: '900px',
  169. searchViewItems: [
  170. { id: 'Name' },
  171. { id: 'AccidentTypeId', ignoreValue: 0, defaultValue: 0, dataSource: accidentTypesForSearch },
  172. { id: 'StartDate', type: 'dateRange', isOnlyDate: true },
  173. { id: 'EndDate', type: 'dateRange', isOnlyDate: true }
  174. ],
  175. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  176. var dfd = $.Deferred();
  177. if (dataModel.StartDate() > dataModel.EndDate()) {
  178. return dfd.resolve(false, '사고발생일은 조치완료일 이전으로 선택해야 합니다.');
  179. } else {
  180. return dfd.resolve(true);;
  181. }
  182. },
  183. beforeUpdateDataViewModel: function () {
  184. var dataModel = viewModel.dataModel;
  185. if (dataModel.StartDate() > dataModel.EndDate()) {
  186. utils.toast.show('사고발생일은 조치완료일 이전으로 선택해야 합니다.', 'error');
  187. return 0;
  188. } else {
  189. return 2;
  190. }
  191. },
  192. handleAfterSaveInPopup: function (responseKey, response) {//2019-11-12 변경
  193. viewModel.dataModel.AccidentId(responseKey.AccidentId);
  194. },
  195. handleSaveButtonInPopup: function (isInsert) {//2019-11-12 변경
  196. if (isInsert === false) {//추가, 변경 여부
  197. if (_.isNull(dropZone1) === false) {
  198. if (viewModel.dataModel.FileId1() != null) { //변경 - 그림삭제
  199. var temp1 = {
  200. SiteId: BWA.UserInfo.SiteId(),
  201. FileId: viewModel.dataModel.FileId1()
  202. }
  203. BWA.db.CmFile.byKey(temp1).done(function (data) {
  204. dropZone1.removeFile(data);
  205. dropZone1.processQueue();
  206. });
  207. }
  208. else {
  209. dropZone1.processQueue();//변경 - 그림 삭제 필요없음
  210. }
  211. }
  212. }
  213. else {
  214. if (_.isNull(dropZone1) === false) { //추가
  215. if (viewModel.dataModel.FileId1() == null) {
  216. dropZone1.processQueue();
  217. }
  218. }
  219. }
  220. if (isInsert === false) {//추가, 변경 여부
  221. if (_.isNull(dropZone2) === false) {
  222. if (viewModel.dataModel.FileId2() != null) { //변경 - 그림삭제
  223. var temp2 = {
  224. SiteId: BWA.UserInfo.SiteId(),
  225. FileId: viewModel.dataModel.FileId2()
  226. }
  227. BWA.db.CmFile.byKey(temp2).done(function (data) {
  228. dropZone2.removeFile(data);
  229. dropZone2.processQueue();
  230. });
  231. }
  232. else {
  233. dropZone2.processQueue();//변경 - 그림 삭제 필요없음
  234. }
  235. }
  236. }
  237. else {
  238. if (_.isNull(dropZone2) === false) { //추가
  239. if (viewModel.dataModel.FileId2() == null) {
  240. dropZone2.processQueue();
  241. }
  242. }
  243. }
  244. },
  245. handleBeforeDelete: function () {//2019-11-12 변경
  246. var temp1 = {
  247. SiteId: BWA.UserInfo.SiteId(),
  248. FileId: viewModel.dataModel.FileId1()
  249. }
  250. if (temp1.FileId != null) {
  251. BWA.db.CmFile.byKey(temp1).done(function (data) {
  252. if ($('#accidentDropZone3').length) {
  253. if (_.isNull(dropZone1)) {
  254. dropZone1 = BWA.DropZone.create({
  255. id: '#accidentDropZone3',
  256. categoryId: $Code.FileCategory.ACCIDENT
  257. });
  258. dropZone1.removeFile(data);
  259. dropZone1 = null;
  260. }
  261. }
  262. });
  263. }
  264. var temp2 = {
  265. SiteId: BWA.UserInfo.SiteId(),
  266. FileId: viewModel.dataModel.FileId2()
  267. }
  268. if (temp2.FileId != null) {
  269. BWA.db.CmFile.byKey(temp2).done(function (data) {
  270. if ($('#accidentDropZone4').length) {
  271. if (_.isNull(dropZone2)) {
  272. dropZone2 = BWA.DropZone.create({
  273. id: '#accidentDropZone4',
  274. categoryId: $Code.FileCategory.ACCIDENT
  275. });
  276. dropZone2.removeFile(data);
  277. dropZone2 = null;
  278. }
  279. }
  280. });
  281. }
  282. },
  283. handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
  284. if (isNewInPopup() == false) {
  285. BWA.DataUtil.setArrayDataSourceFilter(departmentDataSource, 'CompanyId', dataViewModel.CompanyId(), departments);
  286. if (_.isNull(dataViewModel.FileId1()) === false) {
  287. imagefileUrl1('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId1()));
  288. }
  289. else {
  290. imagefileUrl1(undefined);
  291. }
  292. if (_.isNull(dataViewModel.FileId2()) === false) {
  293. imagefileUrl2('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId2()));
  294. }
  295. else {
  296. imagefileUrl2(undefined);
  297. }
  298. if (_.isNull(dataViewModel.FileId3()) === false) {
  299. imagefileUrl3('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId3()));
  300. }
  301. else {
  302. imagefileUrl3(undefined);
  303. }
  304. }
  305. },
  306. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  307. dataGrid.clearSelection();
  308. var data = clickRow.data;
  309. var dataModel = viewModel.dataModel;
  310. if (data['CompanyId']() != null)
  311. dataModel.CompanyName = $KoSet(dataModel.CompanyName, data['CmCompany/Name']());
  312. else dataModel.CompanyName('');
  313. if (data['DepartmentId']() != null)
  314. dataModel.DepartmentName = $KoSet(dataModel.DepartmentName, data['CmDepartment/Name']());
  315. else dataModel.DepartmentName('');
  316. dataModel.AccidentTypeName = $KoSet(dataModel.AccidentTypeName, data['FmsAccidentCodeType/Name']());
  317. if (data['FileId1']() != null)
  318. dataModel.AttachmentFileName1(data['CmFile/Name']());
  319. else dataModel.AttachmentFileName1('');
  320. if (data['FileId2']() != null)
  321. dataModel.AttachmentFileName2(data['CmFile1/Name']());
  322. else dataModel.AttachmentFileName2('');
  323. if (data['FileId3']() != null)
  324. dataModel.AttachmentFileName3(data['CmFile2/Name']());
  325. else dataModel.AttachmentFileName3('');
  326. popupVisible(true);
  327. },
  328. handleViewShowing: function (dataModel) {
  329. $.when(
  330. accidentTypeDataSource.load(),
  331. companyDataSource.load()
  332. )
  333. .done(function (dbAccidents, dbCompanies) {
  334. accidentTypes(dbAccidents[0]);
  335. companies(dbCompanies[0]);
  336. departments([]);
  337. accidentTypesForSearch($SearchView.createArrayOfSelectBox('AccidentTypeId', accidentTypes()));
  338. deferredForSearch.resolve();
  339. });
  340. },
  341. handleViewShown: function (dataViewModel, isEditModeInPopup) {
  342. setupDropZone(isEditModeInPopup, dataViewModel);
  343. },
  344. handleCancelInPopup: function () {
  345. isEditModeInPopup(false);
  346. },
  347. handlePopupButtonEdit: function (dataModel) {
  348. isEditModeInPopup(true);
  349. },
  350. handlePopupButtonClose: function () {
  351. isEditModeInPopup(false);
  352. },
  353. handleSaveSuccess: function () {
  354. if (_.isNull(dropZone1) === false) {
  355. dropZone1.resetUploadedFileInfo();
  356. }
  357. if (_.isNull(dropZone2) === false) {
  358. dropZone2.resetUploadedFileInfo();
  359. }
  360. isEditModeInPopup(false);
  361. },
  362. handlePopupShowing: function (isEditMode, isNew, dataViewModel) {
  363. imagefileUrl1(undefined);
  364. imagefileUrl2(undefined);
  365. if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
  366. if (_.isNull(dropZone2) === false) dropZone2.resetUploadedFileInfo();
  367. if (isNew) { // 신규등록인 경우
  368. dropZone1 = null;
  369. dropZone2 = null;
  370. }
  371. },
  372. handlePopupShown: function (isEditMode, isNew, dataViewModel) {
  373. var accidentTypes = viewModel.accidentTypes();
  374. isEditModeInPopup(false);
  375. if (isNew) { // 신규등록인 경우
  376. isEditModeInPopup(true);
  377. if (!_.isEmpty(accidentTypes)) {
  378. dataViewModel.AccidentTypeId(accidentTypes[0].AccidentTypeId());
  379. }
  380. }
  381. }
  382. });
  383. viewModel.handleSelectBoxChangeCompanyInPopup = function (e) {
  384. BWA.DataUtil.setArrayDataSourceFilter(departmentDataSource, 'CompanyId', e.value, departments);
  385. viewModel.dataModel.DepartmentId(null);
  386. }
  387. viewModel.imagefileUrl1 = imagefileUrl1;
  388. viewModel.imagefileUrl2 = imagefileUrl2;
  389. viewModel.imagefileUrl3 = imagefileUrl3;
  390. viewModel.isEditModeInPopup = isEditModeInPopup;
  391. viewModel.accidentTypes = accidentTypes;
  392. viewModel.companies = companies;
  393. viewModel.departments = departments;
  394. viewModel.dataModel.CompanyName = ko.observable();
  395. viewModel.dataModel.DepartmentName = ko.observable();
  396. viewModel.dataModel.AccidentTypeName = ko.observable();
  397. viewModel.dataModel.AttachmentFileName1 = ko.observable();
  398. viewModel.dataModel.AttachmentFileName2 = ko.observable();
  399. viewModel.dataModel.AttachmentFileName3 = ko.observable();
  400. return viewModel;
  401. };