961a6b1c9e0c0ad9f9d5413b5bfbc975fbbde9ca.svn-base 19 KB

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