d21eaa58cd7e9a125126d1c3ffbc6755f3f947ae.svn-base 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. BemsWebApplication.ConstructionPlan = function (params, viewInfo) {
  2. "use strict";
  3. var imagefileUrl1 = ko.observable(),
  4. imagefileUrl2 = ko.observable(),
  5. uploadedFileInfo = {},
  6. //hcLee 2016 03 23
  7. uploadedFileInfo2 = {},
  8. dropZone1 = null,
  9. dropZone2 = null;
  10. var FmsConstructionDataSource = BemsWebApplication.db.createDataSource('FmsConstruction');
  11. var ConstructionInfo = ko.observableArray();
  12. var RowName;
  13. var eq = BWA.DataUtil.constructEqualFilter,
  14. and = BWA.DataUtil.andFilter,
  15. noteq = BWA.DataUtil.constructNotEqualFilter;
  16. var isEditModeInPopup = ko.observable(false);
  17. // 공사업체 데이터 소스...
  18. var partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
  19. constructionTypeDataSource = BemsWebApplication.db.createDataSource('FmsConstructionCodeType', true, false, true),
  20. progressDataSource = BemsWebApplication.db.createDataSource('FmsConstructionCodeProgress');
  21. var partners = ko.observableArray(),
  22. constructionTypes = ko.observableArray(),
  23. dbProgresses = ko.observableArray();
  24. var constructionTypesForSearch = ko.observableArray(),
  25. partnerTypesForSearch = ko.observableArray();
  26. var deferredForSearch = new $.Deferred();
  27. var dataSourceOptions = {
  28. select: [
  29. 'SiteId',
  30. 'ConstructionId',
  31. 'ConstructionTypeId',
  32. 'Name',
  33. 'StartDate',
  34. 'EndDate',
  35. 'PartnerId',
  36. 'ConstructLocation',
  37. 'OwnerShipName',
  38. 'CommitmentMan',
  39. 'OwnerShipPhoneNo',
  40. 'WeldWorkStartTime',
  41. 'WeldWorkEndTime',
  42. 'GasWorkStartTime',
  43. 'GasWorkEndTime',
  44. 'PaintWorkStartTime',
  45. 'PaintWorkEndTime',
  46. 'Comment',
  47. 'ProgressId',
  48. 'AddDate',
  49. 'UpdateDate',
  50. 'FmsConstructionCodeProgress/Name',
  51. 'CmPartner/Name',
  52. 'CmPartner/PhoneNo',
  53. 'FmsConstructionCodeType/Name',
  54. 'ConstructionDetail',
  55. 'InOutStockName',
  56. 'FileId1',
  57. 'FileId2',
  58. 'FileId3',
  59. 'CmFile/Name',
  60. 'CmFile1/Name',
  61. 'CmFile2/Name'
  62. ],
  63. expand: [
  64. 'FmsConstructionCodeProgress',
  65. 'CmPartner',
  66. 'FmsConstructionEstimation',
  67. 'FmsConstructionCodeType',
  68. 'CmFile',
  69. 'CmFile1',
  70. 'CmFile2'
  71. ],
  72. extendOptions: {
  73. forceOriginalField: true
  74. },
  75. filter: [
  76. eq('SiteId', BWA.UserInfo.SiteId()),
  77. 'and',
  78. ['ProgressId', '<', 3] // 공사진행단계 항목 까지만 가져옴
  79. ]
  80. };
  81. function setupDropZone(isEditModeInPopup, dataViewModel) {//2019-11-18 변경
  82. var timer = null;
  83. isEditModeInPopup.subscribe(function (value) {
  84. if (value) {
  85. if (timer) { clearInterval(timer); }
  86. timer = setInterval(function () {
  87. if ($('#constructionDropZone1').length) {
  88. if (_.isNull(dropZone1)) {
  89. dropZone1 = BWA.DropZone.create({
  90. id: '#constructionDropZone1',
  91. categoryId: $Code.FileCategory.CONSTRUCTION,
  92. uploadedFileInfo: uploadedFileInfo,
  93. handleRemoveBeforePromise: function () {
  94. var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
  95. return BWA.db.FmsConstruction.update(keys, { FileId1: null });
  96. },
  97. handleSuccess: function (fileInfo) {
  98. if (uploadedFileInfo.FileId) {
  99. dataViewModel.FileId1(fileInfo.FileId);
  100. var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
  101. if (keys.ConstructionId != null) {
  102. return BWA.db.FmsConstruction.update(keys, { FileId1: fileInfo.FileId })
  103. .done(function (res) {
  104. $('#gridContainer').dxDataGrid('instance').refresh();
  105. });
  106. }
  107. }
  108. },
  109. handleRemovedFile: function () {
  110. dataViewModel.FileId1(null);
  111. },
  112. });
  113. }
  114. }
  115. if ($('#constructionDropZone2').length) {
  116. if (_.isNull(dropZone2)) {
  117. dropZone2 = BWA.DropZone.create({
  118. id: '#constructionDropZone2',
  119. categoryId: $Code.FileCategory.CONSTRUCTION,
  120. uploadedFileInfo: uploadedFileInfo2,
  121. handleRemoveBeforePromise: function () {
  122. var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
  123. return BWA.db.FmsConstruction.update(keys, { FileId2: null });
  124. },
  125. handleSuccess: function (fileInfo) {
  126. if (uploadedFileInfo2.FileId) {
  127. dataViewModel.FileId2(fileInfo.FileId);
  128. var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
  129. if (keys.ConstructionId != null) {
  130. return BWA.db.FmsConstruction.update(keys, { FileId2: fileInfo.FileId })
  131. .done(function (res) {
  132. $('#gridContainer').dxDataGrid('instance').refresh();
  133. });
  134. }
  135. }
  136. },
  137. handleRemovedFile: function () {
  138. dataViewModel.FileId2(null);
  139. },
  140. });
  141. }
  142. }
  143. }, 100);
  144. }
  145. else {
  146. if (timer) {
  147. clearInterval(timer);
  148. timer = null;
  149. }
  150. dropZone1 = null;
  151. dropZone2 = null;
  152. }
  153. });
  154. }
  155. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsConstruction', {
  156. dataSourceOptions: dataSourceOptions,
  157. columns: [
  158. { dataField: 'Number', caption: $G('number'), width: '10%', alignment: 'center' },
  159. { dataField: 'FmsConstructionCodeType/Name', caption: '공사구분', width: '20%', alignment: 'center' },
  160. { dataField: 'Name', caption: '공사명', width: '80%', alignment: 'center' },
  161. { dataField: 'ConstructLocation', caption: '공사위치', width: '30%', alignment: 'center' },
  162. { dataField: 'CmPartner/Name', caption: '공사업체', width: '20%', alignment: 'center' },
  163. { dataField: 'OwnerShipName', caption: '공사책임자', width: '20%', alignment: 'center' },
  164. {
  165. dataField: 'StartDate', caption: '시작일', width: '20%', alignment: 'center',
  166. customizeText: function (cellInfo) { return $G.date(cellInfo.value); }
  167. },
  168. {
  169. dataField: 'EndDate', caption: '종료일', width: '20%', alignment: 'center',
  170. customizeText: function (cellInfo) { return $G.date(cellInfo.value); }
  171. },
  172. ],
  173. popupWidth: '900px',
  174. // jks-2015-12-30 팝업넓이조절
  175. //popupWidth: '740px',
  176. promiseDataInSearchView: deferredForSearch.promise(),
  177. searchViewItems: [
  178. { id: 'Name' },
  179. { id: 'ConstructionTypeId', ignoreValue: 0, defaultValue: 0, dataSource: constructionTypesForSearch },
  180. { id: 'PartnerId', ignoreValue: 0, defaultValue: 0, dataSource: partnerTypesForSearch },
  181. { id: 'StartDate', type: 'dateRange', isOnlyDate: true },
  182. { id: 'EndDate', type: 'dateRange', isOnlyDate: true }
  183. ],
  184. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  185. var dfd = $.Deferred();
  186. if (dataModel.StartDate() > dataModel.EndDate()) {
  187. return dfd.resolve(false, '시작일은 종료일 이전으로 선택해야 합니다.');
  188. }
  189. if (dataModel.WeldWorkStartTime() > dataModel.WeldWorkEndTime()) {
  190. return dfd.resolve(false, '용접작업시작시간은 용접작업종료시간 이전으로 선택해야 합니다.');
  191. }
  192. if (dataModel.GasWorkStartTime() > dataModel.GasWorkEndTime()) {
  193. return dfd.resolve(false, '가스공사시작시간은 가스공사종료시간 이전으로 선택해야 합니다.');
  194. }
  195. if (dataModel.PaintWorkStartTime() > dataModel.PaintWorkEndTime()) {
  196. return dfd.resolve(false, '도장작업시작시간은 도장작업종료시간 이전으로 선택해야 합니다.');
  197. } else {
  198. var isDuplicated = false;
  199. for (var i = 0; i < ConstructionInfo().length; i++) {
  200. if (dataModel.Name() == ConstructionInfo()[i].Name()) {
  201. isDuplicated = true;
  202. }
  203. }
  204. if (isDuplicated)
  205. return dfd.resolve(false, '이미 동일 이름이 존재합니다.');
  206. else
  207. return dfd.resolve(true);
  208. }
  209. },
  210. beforeUpdateDataViewModel: function () {
  211. var dataModel = viewModel.dataModel;
  212. if (dataModel.StartDate() > dataModel.EndDate()) {
  213. utils.toast.show('시작일은 종료일 이전으로 선택해야 합니다.', 'error');
  214. return 0;
  215. }
  216. if (dataModel.WeldWorkStartTime() > dataModel.WeldWorkEndTime()) {
  217. utils.toast.show('용접작업시작시간은 용접작업종료시간 이전으로 선택해야 합니다.', 'error');
  218. return 0;
  219. }
  220. if (dataModel.GasWorkStartTime() > dataModel.GasWorkEndTime()) {
  221. utils.toast.show('가스공사시작시간은 가스공사종료시간 이전으로 선택해야 합니다.', 'error');
  222. return 0;
  223. }
  224. if (dataModel.PaintWorkStartTime() > dataModel.PaintWorkEndTime()) {
  225. utils.toast.show('도장작업시작시간은 도장작업종료시간 이전으로 선택해야 합니다.', 'error');
  226. return 0;
  227. } else {
  228. if (dataModel.WeldWorkStartTime() != null) {
  229. dataModel.WeldWorkStartTime().setSeconds(0);
  230. }
  231. if (dataModel.WeldWorkEndTime() != null) {
  232. dataModel.WeldWorkEndTime().setSeconds(0);
  233. }
  234. if (dataModel.GasWorkStartTime() != null) {
  235. dataModel.GasWorkStartTime().setSeconds(0);
  236. }
  237. if (dataModel.GasWorkEndTime() != null) {
  238. dataModel.GasWorkEndTime().setSeconds(0);
  239. }
  240. if (dataModel.PaintWorkStartTime() != null) {
  241. dataModel.PaintWorkStartTime().setSeconds(0);
  242. }
  243. if (dataModel.PaintWorkEndTime() != null) {
  244. dataModel.PaintWorkEndTime().setSeconds(0);
  245. }
  246. }
  247. var isDuplicated = false;
  248. for (var i = 0; i < ConstructionInfo().length; i++) {
  249. if (viewModel.dataModel.Name() == ConstructionInfo()[i].Name() && RowName() != ConstructionInfo()[i].Name()) {
  250. isDuplicated = true;
  251. }
  252. }
  253. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
  254. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  255. return 0;
  256. }
  257. else {
  258. if (isDuplicated) {
  259. utils.toast.show('이미 동일 이름이 존재합니다.', 'error');
  260. return 0;
  261. }
  262. else
  263. return 2;
  264. }
  265. },
  266. handleAfterSaveInPopup: function (responseKey, response) {//2019-11-18 변경
  267. viewModel.dataModel.ConstructionId(responseKey.ConstructionId);
  268. },
  269. handleSaveButtonInPopup: function (isInsert) {//2019-11-18 변경
  270. if (isInsert === false) {//추가, 변경 여부
  271. if (_.isNull(dropZone1) === false) {
  272. if (viewModel.dataModel.FileId1() != null) { //변경 - 그림삭제
  273. var temp1 = {
  274. SiteId: BWA.UserInfo.SiteId(),
  275. FileId: viewModel.dataModel.FileId1()
  276. }
  277. BWA.db.CmFile.byKey(temp1).done(function (data) {
  278. dropZone1.removeFile(data);
  279. dropZone1.processQueue();
  280. });
  281. }
  282. else {
  283. dropZone1.processQueue();//변경 - 그림 삭제 필요없음
  284. }
  285. }
  286. }
  287. else {
  288. if (_.isNull(dropZone1) === false) { //추가
  289. if (viewModel.dataModel.FileId1() == null) {
  290. dropZone1.processQueue();
  291. }
  292. }
  293. }
  294. if (isInsert === false) {//추가, 변경 여부
  295. if (_.isNull(dropZone2) === false) {
  296. if (viewModel.dataModel.FileId2() != null) { //변경 - 그림삭제
  297. var temp2 = {
  298. SiteId: BWA.UserInfo.SiteId(),
  299. FileId: viewModel.dataModel.FileId2()
  300. }
  301. BWA.db.CmFile.byKey(temp2).done(function (data) {
  302. dropZone2.removeFile(data);
  303. dropZone2.processQueue();
  304. });
  305. }
  306. else {
  307. dropZone2.processQueue();//변경 - 그림 삭제 필요없음
  308. }
  309. }
  310. }
  311. else {
  312. if (_.isNull(dropZone2) === false) { //추가
  313. if (viewModel.dataModel.FileId2() == null) {
  314. dropZone2.processQueue();
  315. }
  316. }
  317. }
  318. },
  319. handleBeforeDelete: function () {//2019-11-18 변경
  320. var temp1 = {
  321. SiteId: BWA.UserInfo.SiteId(),
  322. FileId: viewModel.dataModel.FileId1()
  323. }
  324. if (temp1.FileId != null) {
  325. BWA.db.CmFile.byKey(temp1).done(function (data) {
  326. if ($('#constructionDropZone3').length) {
  327. if (_.isNull(dropZone1)) {
  328. dropZone1 = BWA.DropZone.create({
  329. id: '#constructionDropZone3',
  330. categoryId: $Code.FileCategory.CONSTRUCTION
  331. });
  332. dropZone1.removeFile(data);
  333. dropZone1 = null;
  334. }
  335. }
  336. });
  337. }
  338. var temp2 = {
  339. SiteId: BWA.UserInfo.SiteId(),
  340. FileId: viewModel.dataModel.FileId2()
  341. }
  342. if (temp2.FileId != null) {
  343. BWA.db.CmFile.byKey(temp2).done(function (data) {
  344. if ($('#constructionDropZone4').length) {
  345. if (_.isNull(dropZone2)) {
  346. dropZone2 = BWA.DropZone.create({
  347. id: '#constructionDropZone4',
  348. categoryId: $Code.FileCategory.CONSTRUCTION
  349. });
  350. dropZone2.removeFile(data);
  351. dropZone2 = null;
  352. }
  353. }
  354. });
  355. }
  356. },
  357. handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
  358. if (isNewInPopup() == false) {
  359. if (_.isNull(dataViewModel.FileId1()) === false) {
  360. imagefileUrl1('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId1()));
  361. }
  362. else {
  363. imagefileUrl1(undefined);
  364. }
  365. if (_.isNull(dataViewModel.FileId2()) === false) {
  366. imagefileUrl2('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId2()));
  367. }
  368. else {
  369. imagefileUrl2(undefined);
  370. }
  371. //var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
  372. //BWA.db.FmsConstruction.update(keys, dataViewModel.toJS());
  373. }
  374. },
  375. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  376. dataGrid.clearSelection();
  377. var data = clickRow.data;
  378. var dataModel = viewModel.dataModel;
  379. RowName = data.Name;
  380. //dataModel.PartnerName = data['CmPartner/Name']();
  381. //dataModel.PartnerPhoneNo = data['CmPartner/PhoneNo']();
  382. dataModel.PartnerName = $KoSet(dataModel.PartnerName, data['CmPartner/Name']());
  383. //dataModel.PartnerPhoneNo = $KoSet(dataModel.PartnerPhoneNo, data['CmPartner/PhoneNo']());
  384. dataModel.ConstructionTypeName = $KoSet(dataModel.ConstructionTypeName, data['FmsConstructionCodeType/Name']());
  385. dataModel.ProgressName = $KoSet(dataModel.ProgressName, data['FmsConstructionCodeProgress/Name']());
  386. if (data['FileId1']() != null)
  387. dataModel.AttachmentFileName1(data['CmFile/Name']());
  388. else dataModel.AttachmentFileName1('');
  389. if (data['FileId2']() != null)
  390. dataModel.AttachmentFileName2(data['CmFile1/Name']());
  391. else dataModel.AttachmentFileName2('');
  392. popupVisible(true);
  393. },
  394. // hcLee 2016 02 01
  395. handlePopupButtonEdit: function (dataModel) {
  396. isEditModeInPopup(true);
  397. },
  398. handleViewShowing: function (dataModel) {
  399. partnerDataSource.filter([
  400. eq('SiteId', BWA.UserInfo.SiteId()), // 공사업체 유형 필터링
  401. 'and',
  402. eq('PartnerTypeId', 1)]);
  403. constructionTypeDataSource.filter([
  404. eq('SiteId', BWA.UserInfo.SiteId()) // 공사업체 유형 필터링
  405. ]);
  406. progressDataSource.filter([
  407. eq('ProgressId', 2),
  408. 'or',
  409. eq('ProgressId', 3),
  410. ]);
  411. $.when(
  412. partnerDataSource.load(),
  413. constructionTypeDataSource.load(),
  414. progressDataSource.load()
  415. )
  416. .done(function (dbPartners, dbConstructions, dbProgress) {
  417. partners(dbPartners[0]);
  418. constructionTypes(dbConstructions[0]);
  419. dbProgresses(dbProgress[0]);
  420. constructionTypesForSearch($SearchView.createArrayOfSelectBox('ConstructionTypeId', constructionTypes()));
  421. partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerId', partners()));
  422. deferredForSearch.resolve();
  423. });
  424. },
  425. handleViewShown: function (dataViewModel, isEditModeInPopup) {
  426. setupDropZone(isEditModeInPopup, dataViewModel);
  427. },
  428. handleCancelInPopup: function () {
  429. isEditModeInPopup(false);
  430. },
  431. handlePopupButtonClose: function () {
  432. isEditModeInPopup(false);
  433. },
  434. handleSaveSuccess: function () {
  435. if (_.isNull(dropZone1) === false) {
  436. dropZone1.resetUploadedFileInfo();
  437. }
  438. if (_.isNull(dropZone2) === false) {
  439. dropZone2.resetUploadedFileInfo();
  440. }
  441. isEditModeInPopup(false);
  442. },
  443. // hcLee 2016 03 23
  444. handlePopupShowing: function (isEditMode, isNew, dataViewModel) {
  445. imagefileUrl1(undefined);
  446. imagefileUrl2(undefined);
  447. if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
  448. if (_.isNull(dropZone2) === false) dropZone2.resetUploadedFileInfo();
  449. if (isNew) { // 신규등록인 경우
  450. dropZone1 = null;
  451. dropZone2 = null;
  452. }
  453. // 이름 중복 방지
  454. FmsConstructionDataSource.filter([
  455. ['SiteId', '=', BWA.UserInfo.SiteId()],
  456. 'and',
  457. [ 'ProgressId', '<', 3]
  458. ]);
  459. FmsConstructionDataSource.load().done(function (result) {
  460. ConstructionInfo(result);
  461. });
  462. },
  463. handlePopupShown: function (isEditMode, isNew, dataViewModel) {
  464. //handlePopupShowing: function (isEditMode, isNew, dataViewModel) {
  465. var partners = viewModel.partners();
  466. var constructionTypes = viewModel.constructionTypes();
  467. /*
  468. imagefileUrl1(undefined);
  469. imagefileUrl2(undefined);
  470. if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
  471. if (_.isNull(dropZone2) === false) dropZone2.resetUploadedFileInfo();
  472. */
  473. isEditModeInPopup(false);
  474. if (isNew) { // 신규등록인 경우
  475. isEditModeInPopup(true);
  476. dataViewModel.ProgressId(2); // 공사계획 상태를 '진행' 단계로 초기화
  477. dataViewModel.AddDate($G.date(new Date()));
  478. dataViewModel.UpdateDate($G.date(new Date()));
  479. if (!_.isEmpty(partners)) {
  480. dataViewModel.PartnerId(partners[0].PartnerId());
  481. }
  482. if (!_.isEmpty(constructionTypes)) {
  483. dataViewModel.ConstructionTypeId(constructionTypes[0].ConstructionTypeId());
  484. }
  485. }
  486. }
  487. });
  488. viewModel.imagefileUrl1 = imagefileUrl1;
  489. viewModel.imagefileUrl2 = imagefileUrl2;
  490. viewModel.isEditModeInPopup = isEditModeInPopup;
  491. viewModel.constructionTypes = constructionTypes;
  492. viewModel.partners = partners;
  493. viewModel.dbProgresses = dbProgresses;
  494. viewModel.dataModel.ConstructionTypeName = ko.observable();
  495. viewModel.dataModel.PartnerName = ko.observable();
  496. //viewModel.dataModel.PartnerPhoneNo = ko.observable();
  497. viewModel.dataModel.ProgressName = ko.observable();
  498. viewModel.dataModel.AttachmentFileName1 = ko.observable();
  499. viewModel.dataModel.AttachmentFileName2 = ko.observable();
  500. viewModel.dataModel.AttachmentFileName3 = ko.observable();
  501. viewModel.dataModel.ProgressId.subscribe(function () {
  502. if (viewModel.dataModel.ProgressId() == 3) {
  503. viewModel.dataModel.EndDate(new Date());
  504. }
  505. });
  506. return viewModel;
  507. };