1125ad78f31ffd9aedaac9ebbad4592d3494bc63.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. BemsWebApplication.Manual = function (params, viewInfo) {
  2. "use strict";
  3. //2019-11-25 변경
  4. var dropZone = null;
  5. var eq = BWA.DataUtil.constructEqualFilter;
  6. var and = BWA.DataUtil.andFilter;
  7. var drawingHistory;
  8. var historyViewModel = new BemsWebApplication.FmsManualHistoryViewModel();
  9. var endpointSelector = "";
  10. if (BemsWebApplication.config.mode == "production") {
  11. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  12. } else {
  13. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  14. }
  15. var ManualInfo = ko.observableArray();
  16. var FmsManualDataSource = BemsWebApplication.db.createDataSource('FmsManual');
  17. var RowName, RowTypeId;
  18. //2019-11-25 변경
  19. //drawingGroupDataSource = BemsWebApplication.db.createDataSource('FmsDrawingCodeGroup', true),
  20. var drawingTypeDataSource = BemsWebApplication.db.createDataSource('FmsManualType', true),
  21. drawingHistoryDataSource = BemsWebApplication.DataUtil.createDataSource({
  22. dataSourceOptions: {
  23. select: [
  24. 'SiteId', 'ManualId', 'HistoryId', 'FileId', 'Description', 'RevisionNo',
  25. 'UpdatedDate', 'UpdatedUserId',
  26. 'CmFile/Name', 'CmFile/FileSize', 'CmUser/Name'
  27. ],
  28. expand: ['CmFile', 'CmUser'],
  29. extendOptions: {
  30. forceOriginalField: true
  31. }
  32. }
  33. }, 'FmsManualHistory');
  34. var drawingHistories = ko.observableArray(),
  35. //drawingGroups = ko.observableArray(),
  36. drawingTypes = ko.observableArray(),
  37. //drawingGroupsForSearch = ko.observableArray(),
  38. drawingTypesForSearch = ko.observableArray(),
  39. tabsVisible = ko.observable(false),
  40. textAreaNoteHeightInPopup = ko.observable(),
  41. isVisibleHistoryInsertButton = ko.observable(false),
  42. uploadedFileInfo = {},
  43. drawingHistoryPopup,
  44. deferredForSearch = new $.Deferred();
  45. params.popupPosition = { offset: '-200 0' };
  46. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsManual', {
  47. popupWidth: 720,
  48. dataSourceOptions: {
  49. select: [
  50. 'SiteId', 'ManualId', 'ManualNo', 'Name', 'ManualTypeId',
  51. 'FmsManualType/Name', 'Description'
  52. ],
  53. expand: ['FmsManualType'],
  54. extendOptions: {
  55. forceOriginalField: true
  56. }
  57. },
  58. columns: [
  59. { dataField: 'ManualId', caption: '번호', width: '10%', alignment: 'center', sortOrder: 'desc' },
  60. { dataField: 'FmsManualType/Name', caption: '매뉴얼 유형', width: '15%', alignment: 'center' },
  61. { dataField: 'ManualNo', caption: '매뉴얼 번호', width: '25%', alignment: 'center' },
  62. { dataField: 'Name', caption: '매뉴얼 명', width: '35%', alignment: 'center' }
  63. ],
  64. searchViewItems: [
  65. { id: 'ManualTypeId', ignoreValue: 0, defaultValue: 0, dataSource: drawingTypesForSearch },
  66. { id: 'Name' }
  67. ],
  68. getAddedToolbarItemsInPopup: function (e) {
  69. var isEditModeInPopup = e.isEditModeInPopup,
  70. hasnotModificationPermission = e.hasnotModificationPermission;
  71. isEditModeInPopup.subscribe(function (isEditMode) {
  72. tabIndex(0); // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 24추가
  73. //isVisibleHistoryInsertButton(tabIndex() === 1 && isEditMode);
  74. });
  75. return [
  76. {
  77. location: 'after',
  78. widget: 'button',
  79. options: {
  80. text: '매뉴얼이력추가',
  81. icon: 'plus',
  82. visible: isVisibleHistoryInsertButton,
  83. disabled: hasnotModificationPermission,
  84. clickAction: function () {
  85. drawingHistoryPopup.handleInsertDrawingHistory();
  86. }
  87. }
  88. },
  89. ]
  90. },
  91. promiseDataInSearchView: deferredForSearch.promise(),
  92. handlePopupShowing: function (isNewInPopup) {
  93. FmsManualDataSource.filter([
  94. ["SiteId", "=", BWA.UserInfo.SiteId()]
  95. ]);
  96. FmsManualDataSource.load().done(function (result) {
  97. ManualInfo(result);
  98. });
  99. tabIndex(0);
  100. tabsVisible(isNewInPopup() == false);
  101. },
  102. // hcLee 2016 03 28
  103. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  104. var dfd = $.Deferred();
  105. if (BWA.DataUtil.isValidInputValue(dataModel.ManualTypeId()) == false ||
  106. BWA.DataUtil.isValidInputValue(dataModel.ManualNo()) == false ||
  107. BWA.DataUtil.isValidInputValue(dataModel.Name()) == false ||
  108. manualFileUpload.dropzone.files.length == 0)//2019-11-25 변경
  109. dfd.resolve(false, '(*) 표시 항목은 필수 입력 사항 입니다.');
  110. var isDuplicated = false;
  111. for (var i = 0; i < ManualInfo().length; i++) {
  112. if (dataModel.Name() == ManualInfo()[i].Name() && dataModel.ManualTypeId() == ManualInfo()[i].ManualTypeId()) {
  113. isDuplicated = true;
  114. }
  115. }
  116. if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
  117. return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
  118. else {
  119. if (isDuplicated)
  120. return dfd.resolve(false, '이미 동일 정보가 존재합니다 (매뉴얼분류, 매뉴얼명 확인 필요)');
  121. else
  122. return dfd.resolve(true);
  123. }
  124. },
  125. beforeUpdateDataViewModel: function () {
  126. var dataModel = viewModel.dataModel;
  127. if (BWA.DataUtil.isValidInputValue(dataModel.ManualTypeId()) == false ||
  128. BWA.DataUtil.isValidInputValue(dataModel.ManualNo()) == false ||
  129. BWA.DataUtil.isValidInputValue(dataModel.Name()) == false) {
  130. utils.toast.show('(*) 표시 항목은 필수 입력 사항 입니다!', 'error');
  131. return 0;
  132. }
  133. var isDuplicated = false;
  134. for (var i = 0; i < ManualInfo().length; i++) {
  135. if (viewModel.dataModel.Name() == ManualInfo()[i].Name() && viewModel.dataModel.ManualTypeId() == ManualInfo()[i].ManualTypeId()
  136. && (RowName() != ManualInfo()[i].Name() || RowManualTypeId() != ManualInfo()[i].ManualTypeId())) {
  137. isDuplicated = true;
  138. }
  139. }
  140. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
  141. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  142. return 0;
  143. }
  144. else {
  145. if (isDuplicated) {
  146. utils.toast.show('이미 동일 정보가 존재합니다 (매뉴얼분류, 매뉴얼명 확인 필요)', 'error');
  147. return 0;
  148. }
  149. else
  150. return 2;
  151. }
  152. },
  153. handleAfterSaveInPopup: function (responseKey) {
  154. var fileId = uploadedFileInfo.FileId;
  155. if (_.isUndefined(fileId)) return;
  156. var dataViewModel = viewModel.dataModel;//2019-11-25 변경
  157. drawingHistory = new BWA.FmsManualHistoryViewModel();
  158. drawingHistory.SiteId(responseKey.SiteId);
  159. drawingHistory.ManualId(responseKey.ManualId);
  160. drawingHistory.FileId(fileId);
  161. drawingHistory.RevisionNo(0); // 2016 03 28 hcLee 추가
  162. drawingHistory.UpdatedDate(new Date());
  163. drawingHistory.UpdatedUserId(BWA.UserInfo.UserId());
  164. //2019-11-25 변경
  165. if (viewModel.isNewInPopup() === false) {//추가, 변경 여부
  166. if (_.isNull(dropZone) === false) {
  167. if (drawingHistory.FileId() != null) { //변경 - 그림삭제
  168. var temp = {
  169. SiteId: BWA.UserInfo.SiteId(),
  170. FileId: drawingHistory.FileId()
  171. }
  172. BWA.db.CmFile.byKey(temp).done(function (data) {
  173. dropZone.removeFile(data);
  174. dropZone.processQueue();
  175. });
  176. }
  177. else {
  178. dropZone.processQueue();//변경 - 그림 삭제 필요없음
  179. }
  180. }
  181. }
  182. else {
  183. if (_.isNull(dropZone) === false) { //추가
  184. if (drawingHistory.FileId() == null) {
  185. dropZone.processQueue();
  186. }
  187. }
  188. }
  189. BWA.db.FmsManualHistory.insert(drawingHistory.toJS()).done(function () {
  190. // utils.toast.show('데이터베이스 항목 등록 작업이 성공하였습니다.');
  191. });
  192. },
  193. //2019-11-25 변경
  194. handleBeforeDelete: function () {
  195. for (var i = 0; i < drawingHistories().length; i++) {
  196. var temp1 = {
  197. SiteId: BWA.UserInfo.SiteId(),
  198. FileId: drawingHistories()[i].FileId()
  199. }
  200. if (temp1.FileId != null) {
  201. BWA.db.CmFile.byKey(temp1).done(function (data) {
  202. if (_.isNull(dropZone)) {
  203. dropZone = BWA.DropZone.create({
  204. id: '#manualFileUpload1',
  205. categoryId: $Code.FileCategory.MANUAL
  206. });
  207. }
  208. dropZone.removeFile(data);
  209. });
  210. }
  211. var store = new DevExpress.data.ODataStore({
  212. url: endpointSelector + "/FmsManualHistory",
  213. key: ["SiteId", "ManualId", "HistoryId"],
  214. keyType: {
  215. SiteId: "Int32",
  216. ManualId: "Int32",
  217. HistoryId: "Int32"
  218. }
  219. });
  220. var removeData = {
  221. SiteId: BWA.UserInfo.SiteId(), ManualId: drawingHistories()[i].ManualId(), HistoryId: drawingHistories()[i].HistoryId(),
  222. RevisionNo: drawingHistories()[i].RevisionNo(), FileId: drawingHistories()[i].FileId(),
  223. Description: drawingHistories()[i].Description(), UpdatedDate: drawingHistories()[i].UpdatedDate(), UpdatedUserId: drawingHistories()[i].UpdatedUserId
  224. };
  225. store.remove(removeData).done(function (values, key) {
  226. utils.toast.show("삭제 되었습니다.");
  227. })
  228. .fail(function (error) {
  229. utils.toast.show(error);
  230. });
  231. if (i == drawingHistories().length) {
  232. dropZone = null;
  233. }
  234. }
  235. },
  236. //handleInitializedInPopup: function() {
  237. handlePopupShown: function (isEditModeInPopup, isNewInPopup, dataViewModel) {
  238. if (isNewInPopup) {
  239. uploadedFileInfo.FileId = null;
  240. textAreaNoteHeightInPopup(170);
  241. dropZone = BWA.DropZone.create({
  242. categoryId: $Code.FileCategory.MANUAL,
  243. id: '#manualFileUpload',
  244. uploadedFileInfo: uploadedFileInfo,
  245. maxFiles: 1,
  246. handleSuccess: function (fileInfo) {
  247. if (uploadedFileInfo.FileId) {
  248. historyViewModel.FileId(fileInfo.FileId);
  249. drawingHistoryDataSource.filter([
  250. eq('SiteId', BWA.UserInfo.SiteId()),
  251. and,
  252. eq('ManualId', drawingHistory.ManualId())
  253. ]);
  254. drawingHistoryDataSource.load().done(function (histories) {
  255. drawingHistories(histories);
  256. if (drawingHistories()[0].HistoryId() != null) {
  257. return BWA.db.FmsManualHistory.update({ SiteId: drawingHistories()[0].SiteId(), HistoryId: drawingHistories()[0].HistoryId(), ManualId: drawingHistories()[0].ManualId() }, { FileId: fileInfo.FileId })
  258. .done(function (res) {
  259. $('#gridContainer').dxDataGrid('instance').refresh();
  260. });
  261. }
  262. });
  263. }
  264. },
  265. handleRemovedFile: function () {
  266. historyViewModel.FileId(null);
  267. }
  268. });
  269. }
  270. else {
  271. textAreaNoteHeightInPopup(340);
  272. reloadDrawingHistory(dataViewModel.ManualId());
  273. }
  274. },
  275. handleViewShowing: function (that) {
  276. $.when(
  277. //drawingGroupDataSource.load(),
  278. drawingTypeDataSource.load())
  279. //.done(function(dbGroups, dbTypes) {
  280. .done(function (dbTypes) {
  281. //drawingGroups(dbGroups[0]);
  282. //drawingTypes(dbTypes[0]);
  283. drawingTypes(dbTypes);
  284. //drawingGroupsForSearch($SearchView.createDefaultArray('DrawingGroupId').concat(dbGroups[0]));
  285. drawingTypesForSearch($SearchView.createDefaultArray('ManualTypeId').concat(dbTypes));
  286. deferredForSearch.resolve();
  287. });
  288. },
  289. //2016 03 24 hcLee 추가
  290. handleCancelInPopup: function () {
  291. //tabIndex(1);
  292. tabIndex(0);
  293. tabIndex(0);
  294. },
  295. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  296. dataGrid.clearSelection();
  297. var data = clickRow.data;
  298. var dataModel = viewModel.dataModel;
  299. // dataModel.DrawingGroupName = $KoSet(dataModel.DrawingGroupName, data['FmsDrawingCodeGroup/Name']);
  300. dataModel.ManualTypeName = $KoSet(dataModel.ManualTypeName, data['FmsManualType/Name']);
  301. var data = clickRow.data;
  302. RowName = data.Name;
  303. RowTypeId = data.ManualTypeId;
  304. popupVisible(true);
  305. },
  306. handleViewShown: function () {
  307. }
  308. });
  309. function reloadDrawingHistory(drawingId) {
  310. drawingHistoryDataSource.filter([
  311. eq('SiteId', BWA.UserInfo.SiteId()),
  312. and,
  313. eq('ManualId', drawingId)
  314. ]);
  315. drawingHistoryDataSource.load().done(function (histories) {
  316. drawingHistories(histories);
  317. });
  318. }
  319. drawingHistoryPopup = BWA.Popup.ManualHistory.create(viewModel, params, drawingHistories, reloadDrawingHistory);
  320. //viewModel.drawingGroups = drawingGroups;
  321. viewModel.drawingTypes = drawingTypes;
  322. //viewModel.drawingGroupsForSearch = drawingGroupsForSearch;
  323. viewModel.drawingTypesForSearch = drawingTypesForSearch;
  324. var tabIndex = ko.observable(0);
  325. viewModel.tabsOptions = {
  326. visible: tabsVisible,
  327. selectedIndex: tabIndex,
  328. dataSource: [
  329. { text: '매뉴얼정보' },
  330. { text: '매뉴얼이력' }
  331. ]
  332. };
  333. tabIndex.subscribe(function (index) {
  334. // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 24추가
  335. //if (viewModel.isEditModeInPopup()) return;
  336. if (viewModel.isEditModeInPopup() == false) {
  337. isVisibleHistoryInsertButton(index === 1);
  338. viewModel.visibleEditButton(index === 0);
  339. viewModel.visibleDeleteButton(index === 0);
  340. }
  341. if (index == 0) drawingHistoryPopup.hide();
  342. //if (index == 0 && tabIndex() == 0) return;
  343. // hcLee 2016 03 24
  344. if (viewModel.isEditModeInPopup()) {
  345. tabIndex(0);
  346. return;
  347. }
  348. });
  349. viewModel.multiViewOptions = {
  350. dataSource: [
  351. {
  352. template: 'drawing',
  353. viewModel: viewModel,
  354. dataModel: viewModel.dataModel,
  355. },
  356. {
  357. template: 'drawingHistory',
  358. viewModel: viewModel,
  359. dataGridOptions: {
  360. dataSource: drawingHistories,
  361. columns: [
  362. { dataField: 'RevisionNo', caption: $G('revisionNo'), width: '13%' },
  363. { dataField: 'UpdatedDate', caption: $G('updatedDate'), width: '30%', dataType: 'date', format: 'yyyy-MM-dd HH:mm:ss' },
  364. { dataField: 'CmUser/Name', caption: $G('modifier'), width: '22%' },
  365. {
  366. dataField: 'CmFile/Name', caption: $G('fileName'), alignment: 'center', width: '45%',
  367. cellTemplate: function (cellElement, cellInfo) {
  368. var data = cellInfo.data;
  369. var url = [
  370. BWA.db._url,
  371. '/CmFile(SiteId={0},FileId={1})/$value'.formati(data.SiteId(), data.FileId())
  372. ].join('');
  373. $('<a>')
  374. .prop('href', url)
  375. .prop('download', cellInfo.value)
  376. .attr('style', 'color: {0} !important; text-decoration: underline;'.formati('purple'))
  377. //.style('color', '#333 !important')
  378. .attr('target', '_blank')
  379. .text(cellInfo.value)
  380. .appendTo(cellElement);
  381. }
  382. }
  383. ],
  384. paging: {
  385. pageSize: 10,
  386. enabled: true
  387. },
  388. pager: { visible: true },
  389. hoverStateEnabled: true,
  390. contentReadyAction: function (e) {
  391. drawingHistoryPopup.setDrawingHistoryGridViewInstance(e.component);
  392. },
  393. selection: { mode: 'single' },
  394. rowClick: function (clickRow) {
  395. if (drawingHistoryPopup.isNewData()) {
  396. utils.toast.show('매뉴얼이력추가 중 입니다.'); // hcLee 2016 03 28
  397. return;
  398. }
  399. drawingHistoryPopup.setSelectedDrawingHistory(clickRow.data);
  400. //drawingHistoryPopup.hide();
  401. drawingHistoryPopup.show();
  402. },
  403. height: 405
  404. }
  405. }
  406. ],
  407. swipeEnabled: false,
  408. selectedIndex: tabIndex,
  409. height: '520px'
  410. };
  411. viewModel.dataModel.ManualTypeName = $KoSet(viewModel.dataModel.ManualTypeName, '');
  412. viewModel.isEditModeInPopup.subscribe(function (isEditMode) {
  413. tabIndex(0); // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 24추가
  414. //isVisibleHistoryInsertButton(tabIndex() === 1 && isEditMode);
  415. });
  416. viewModel.textAreaNoteHeightInPopup = textAreaNoteHeightInPopup;
  417. viewModel.drawingHistoryPopup = drawingHistoryPopup;
  418. return viewModel;
  419. };