aade27cf1a445c7f36ce6e7096a1dbeffaf34321.svn-base 18 KB

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