01ffb7d6fcac6791b3a8983099c7ff65f4e407b4.svn-base 16 KB

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