34e74eabab0a6e450d61cea7f2f1076cb8d63977.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. $(function () {
  2. "use strict";
  3. var TEXTAREA_HEIGHT_MAX = 420,
  4. TEXTAREA_HEIGHT_MIN = 240;
  5. var dropZone = null;
  6. var historyViewModel = new BemsWebApplication.FmsDrawingHistoryViewModel();
  7. var uploadedFileInfo = {};
  8. //2019-11-25 변경
  9. var backUpFileId = null;
  10. var eq = BWA.DataUtil.constructEqualFilter;
  11. var and = BWA.DataUtil.andFilter;
  12. var 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. //2019-11-25 변경
  26. BWA.Popup = BWA.Popup || {};
  27. BWA.Popup.DrawingHistory = {
  28. create: function (viewModel, params, drawingHistories, reloadDrawingHistory) {
  29. // 다운로드 기능은 다른 창으로 url를 열면 될 듯하다.
  30. var drawingId = viewModel.dataModel.DrawingId,
  31. // hcLee 2016 03 28
  32. // textAreaHeightInPopup = ko.observable(),
  33. popupVisible = ko.observable(false),
  34. position = ko.observable(),
  35. isNewData = ko.observable(false),
  36. IsPrevImg = ko.observable(false),
  37. RowHistoryId = null,
  38. // textAreaHistoryNoteHeight = ko.observable(TEXTAREA_HEIGHT_MAX),
  39. uploadedFileInfo = {},
  40. isVisibleDropZone = ko.observable('hidden'),
  41. isEditMode = ko.observable(false),
  42. //isVisibleDeleteButton = ko.observable(true),
  43. isVisibleSaveButton = ko.observable(false),
  44. isVisibleCancelButton = ko.observable(true),
  45. isVisibleEditButton = ko.observable(true),
  46. selectedHistory = null,
  47. historyGridView = null,
  48. timerObj = { timer: null },
  49. mainPopupElement = params.mainPopupElement;
  50. historyViewModel.UpdatedUserName = ko.observable();
  51. historyViewModel.FileName = ko.observable();
  52. //hcLee 2016 03 28
  53. historyViewModel.FildIdBackUp = ko.observable();
  54. BWA.db.FmsDrawingHistory.modified.add(function () {
  55. reloadDrawingHistory(drawingId());
  56. $('#gridContainer').dxDataGrid('instance').refresh();
  57. });
  58. function handleButtonSave() {
  59. historyViewModel.SiteId(BWA.UserInfo.SiteId());
  60. historyViewModel.DrawingId(drawingId());
  61. if (isNewData()) {
  62. if (drawingHistoryFileUpload.dropzone.files.length == 0) {
  63. utils.toast.show('도면 파일을 업로드하여 주십시오.', 'error');
  64. return;
  65. }
  66. //2019-11-25 변경
  67. if (_.isNull(dropZone) === false) { //추가
  68. if (historyViewModel.FileId() == null) {
  69. dropZone.processQueue();
  70. }
  71. }
  72. //2019-11-25 변경
  73. historyViewModel.UpdatedDate(new Date());
  74. historyViewModel.UpdatedUserId(BWA.UserInfo.UserId());
  75. BWA.db.FmsDrawingHistory.insert(historyViewModel.toJS()).done(function (res) {
  76. utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
  77. dropZone.resetUploadedFileInfo();
  78. // 2016 03 28
  79. reloadDrawingHistory(drawingId());
  80. $('#gridContainer').dxDataGrid('instance').refresh();
  81. isNewData(false);
  82. ChangeMode(false);
  83. popupVisible(false);
  84. IsPrevImg(false);
  85. });
  86. }
  87. else {
  88. // hcLee 2016 03 27
  89. if (_.isUndefined(historyViewModel.FileId()) || historyViewModel.FileId() == null) {
  90. utils.toast.show('도면 파일을 업로드하여 주십시오.', 'error');
  91. return;
  92. }
  93. historyViewModel.RevisionNo(undefined);
  94. //historyViewModel.FileId(undefined); // hcLee 2016 03 28
  95. historyViewModel.UpdatedDate(new Date());
  96. historyViewModel.UpdatedUserId(BWA.UserInfo.UserId());
  97. //2019-11-25 변경
  98. backUpFileId = historyViewModel.FileId();
  99. if (_.isNull(dropZone) === false) {
  100. dropZone.processQueue();
  101. }
  102. //2019-11-25 변경
  103. var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
  104. BWA.db.FmsDrawingHistory.update(keys, historyViewModel.toJS()).done(function (res) {
  105. utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
  106. dropZone.resetUploadedFileInfo();
  107. reloadDrawingHistory(drawingId());
  108. $('#gridContainer').dxDataGrid('instance').refresh();
  109. ChangeMode(false);
  110. popupVisible(false);
  111. IsPrevImg(true);
  112. });
  113. }
  114. }
  115. /*
  116. function handleButtonDelete() {
  117. var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
  118. BWA.db.FmsDrawingHistory.remove(keys).done(function() {
  119. BWA.db.CmFile.remove({
  120. SiteId: historyViewModel.SiteId(),
  121. FileId: historyViewModel.FileId()
  122. }).done(function() {
  123. utils.toast.show('도면 이력 항목 삭제 처리가 성공하였습니다.');
  124. popupVisible(false);
  125. });
  126. });
  127. }*/
  128. function ChangeMode(bEdit) {
  129. if (bEdit) {
  130. setupDropzone(bEdit); // 업로드된 파일을 지운후 저장하지 않고 취소만 하고 다시 수정을 시작한 경우를 위하여 hcLee 2016 03 25
  131. isEditMode(true);
  132. isVisibleEditButton(false);
  133. isVisibleSaveButton(true);
  134. isVisibleCancelButton(true);
  135. }
  136. else {
  137. setupDropzone(false); // 업로드된 파일을 지운후 저장하지 않고 취소만 하고 다시 수정을 시작한 경우를 위하여 hcLee 2016 03 25
  138. isEditMode(false);
  139. isVisibleEditButton(true);
  140. isVisibleSaveButton(false);
  141. isVisibleCancelButton(false);
  142. }
  143. }
  144. function handleEditDrawingHistory() {
  145. ChangeMode(true);
  146. }
  147. function setupDropzone(bEdit) {
  148. //var clone2 = $("div.dz-preview").clone(); // making zeh' clones!
  149. if (bEdit) {
  150. if (dropZone) {
  151. dropZone.removeAllFiles();
  152. dropZone.options.startLoadFileCount = 0;
  153. $('div.dz-preview').remove();
  154. }
  155. historyViewModel.FileId(historyViewModel.FildIdBackUp()); // hcLee 2016 03 25
  156. if (_.isNull(dropZone)) {
  157. dropZone = BWA.DropZone.create({
  158. id: '#drawingHistoryFileUpload',
  159. categoryId: $Code.FileCategory.DRAWING,
  160. uploadedFileInfo: uploadedFileInfo,
  161. previewTemplate: "...",
  162. handleSuccess: function (fileInfo) {
  163. //2019-11-25 변경
  164. historyViewModel.FileId(fileInfo.FileId);
  165. var tempFileID = fileInfo.FileId;
  166. if (uploadedFileInfo.FileId) {
  167. drawingHistoryDataSource.filter([
  168. eq('SiteId', BWA.UserInfo.SiteId()),
  169. and,
  170. eq('DrawingId', historyViewModel.DrawingId())
  171. ]);
  172. drawingHistoryDataSource.load().done(function (histories) {
  173. drawingHistories(histories);
  174. var len = drawingHistories().length;
  175. if (RowHistoryId != null)
  176. historyViewModel.HistoryId(RowHistoryId);
  177. else
  178. historyViewModel.HistoryId(drawingHistories()[len - 1].HistoryId());
  179. var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
  180. if (keys.HistoryId != null) {
  181. return BWA.db.FmsDrawingHistory.update(keys, { FileId: tempFileID })
  182. .done(function (res) {
  183. $('#gridContainer').dxDataGrid('instance').refresh();
  184. if (IsPrevImg() == true) { // 그림삭제
  185. var temp = {
  186. SiteId: BWA.UserInfo.SiteId(),
  187. FileId: backUpFileId
  188. }
  189. BWA.db.CmFile.byKey(temp).done(function (data) {
  190. dropZone.removeFile(data);
  191. });
  192. }
  193. });
  194. if (fileInfo.FileId != null)
  195. IsPrevImg(true);
  196. else
  197. IsPrevImg(false);
  198. }
  199. });
  200. }
  201. },
  202. handleRemovedFile: function () {
  203. historyViewModel.FileId(null);
  204. },
  205. });
  206. }
  207. }
  208. }
  209. popupVisible.subscribe(utils.popup.getAttachFunc('#popupDetail', timerObj, position));
  210. position.subscribe(function (value) {
  211. });
  212. isNewData.subscribe(function (isNew) {
  213. if (isNew && popupVisible()) {
  214. isVisibleDropZone('visible');
  215. }
  216. else {
  217. isVisibleDropZone('hidden');
  218. }
  219. });
  220. viewModel.popupVisible.subscribe(function (value) {
  221. if (value === false) {
  222. popupVisible(false);
  223. }
  224. });
  225. viewModel.isEditModeInPopup.subscribe(function (value) {
  226. });
  227. return {
  228. visible: popupVisible,
  229. isNewData: isNewData,
  230. dataModel: historyViewModel,
  231. isVisibleDropZone: isVisibleDropZone,
  232. isEditMode: isEditMode,
  233. show: function () {
  234. popupVisible(true);
  235. },
  236. hide: function () {
  237. popupVisible(false);
  238. },
  239. popupOptions: {
  240. width: '480px',
  241. height: '616px',
  242. dragEnabled: false,
  243. position: position,
  244. visible: popupVisible,
  245. showingAction: function () { },
  246. closeOnOutsideClick: false,
  247. shading: false,
  248. animation: {
  249. show: { type: "slide", duration: 150, from: { left: '-=10', opacity: 0 }, to: { opacity: 1 } },
  250. hide: { type: "slide", duration: 150, from: { left: '-=10', opacity: 1 }, to: { opacity: 0 } }
  251. },
  252. shownAction: function () {
  253. if (isNewData()) {
  254. isVisibleDropZone('visible');
  255. }
  256. else {
  257. isVisibleDropZone('hidden');
  258. }
  259. setupDropzone();
  260. },
  261. hidingAction: function () {
  262. //dropZone.dispose(uploadedFileInfo); // 2016 03 29
  263. }
  264. },
  265. toolbarItems: [
  266. { location: 'before', text: $G('drawingHistoryDetailInfo') },
  267. {
  268. location: 'after',
  269. widget: 'button',
  270. options: {
  271. text: '수정',
  272. icon: 'edit',
  273. visible: isVisibleEditButton,
  274. disabled: viewModel.hasnotModificationPermission,
  275. clickAction: handleEditDrawingHistory
  276. }
  277. },
  278. {
  279. location: 'after',
  280. widget: 'button',
  281. options: {
  282. text: '취소',
  283. icon: 'cancel',
  284. visible: isVisibleCancelButton,
  285. disabled: viewModel.hasnotModificationPermission,
  286. clickAction: function () {
  287. // 파일 id를 다시 설정해야 한다. hcLee 2016 03 25
  288. historyViewModel.FileId(historyViewModel.FildIdBackUp()); // hcLee 2016 03 25
  289. ChangeMode(false);
  290. }
  291. }
  292. },
  293. {
  294. location: 'after', widget: 'button', options: {
  295. text: $G('save'),
  296. icon: 'save',
  297. visible: isVisibleSaveButton,
  298. disabled: viewModel.hasnotModificationPermission,
  299. clickAction: handleButtonSave
  300. }
  301. },
  302. {
  303. location: 'after', widget: 'button', options: {
  304. text: $G('close'),
  305. icon: 'close',
  306. clickAction: function () {
  307. isNewData(false);
  308. ChangeMode(false);
  309. popupVisible(false);
  310. }
  311. }
  312. }
  313. ],
  314. setDrawingHistoryGridViewInstance: function (instance) {
  315. historyGridView = instance;
  316. },
  317. setSelectedDrawingHistory: function (history) {
  318. isNewData(false);
  319. BWA.DataUtil.copyViewModel(history, historyViewModel);
  320. RowHistoryId = history.HistoryId();
  321. historyViewModel.FildIdBackUp(history.FileId()); // hcLee 2016 03 28
  322. historyViewModel.FileName(history['CmFile/Name']());
  323. historyViewModel.UpdatedUserName(history['CmUser/Name']());
  324. historyViewModel.Description(history['Description']());
  325. ChangeMode(false);
  326. },
  327. handleInsertDrawingHistory: function () {
  328. ChangeMode(false);
  329. popupVisible(false);
  330. isNewData(true);
  331. BWA.DataUtil.resetDataModel(_.omit(historyViewModel, 'DrawingId'));
  332. var maxHistory = _.max(drawingHistories(), function (x) {
  333. return x.RevisionNo();
  334. });
  335. historyViewModel.RevisionNo(maxHistory.RevisionNo() + 1);
  336. historyViewModel.UpdatedUserName(BWA.UserInfo.Name());
  337. popupVisible(true);
  338. ChangeMode(true);
  339. isVisibleCancelButton(false);
  340. }
  341. };
  342. }
  343. }
  344. });