062d1fd927d2d256309b1f40b14ca3d1ff9bf0fc.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. $(function () {
  2. "use strict";
  3. var TEXTAREA_HEIGHT_MAX = 420,
  4. TEXTAREA_HEIGHT_MIN = 240;
  5. BWA.Popup = BWA.Popup || {};
  6. BWA.Popup.UserLicense = {
  7. create: function (viewModel, params) {
  8. // 다운로드 기능은 다른 창으로 url를 열면 될 듯하다.
  9. var userDataModel = viewModel.dataModel,
  10. popupVisible = ko.observable(false),
  11. position = ko.observable(),
  12. isNewData = ko.observable(false),
  13. isVisibleDeleteButton = ko.observable(true),
  14. isVisibleSaveButton = ko.observable(false),
  15. timerObj = { timer: null },
  16. mainPopupElement = params.mainPopupElement
  17. ;
  18. BWA.db.FmsDrawingHistory.modified.add(function () {
  19. reloadDrawingHistory(drawingId());
  20. historyGridView.refresh();
  21. });
  22. function handleButtonSave() {
  23. historyViewModel.SiteId(BWA.UserInfo.SiteId());
  24. historyViewModel.DrawingId(drawingId());
  25. if (isNewData()) {
  26. if (_.isUndefined(historyViewModel.FileId())) {
  27. utils.toast.show('도면 파일을 업로드하여 주십시오.', 'error');
  28. return;
  29. }
  30. historyViewModel.UpdatedDate(new Date());
  31. historyViewModel.UpdatedUserId(BWA.UserInfo.UserId());
  32. BWA.db.FmsDrawingHistory.insert(historyViewModel.toJS()).done(function (res) {
  33. utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
  34. dropZone.resetUploadedFileInfo();
  35. popupVisible(false);
  36. });
  37. }
  38. else {
  39. historyViewModel.RevisionNo(undefined);
  40. historyViewModel.FileId(undefined);
  41. historyViewModel.UpdatedDate(undefined);
  42. historyViewModel.UpdatedUserId(undefined);
  43. var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
  44. BWA.db.FmsDrawingHistory.update(keys, historyViewModel.toJS()).done(function (res) {
  45. utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
  46. popupVisible(false);
  47. });
  48. }
  49. }
  50. function handleButtonDelete() {
  51. var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
  52. BWA.db.FmsDrawingHistory.remove(keys).done(function () {
  53. BWA.db.CmFile.remove({
  54. SiteId: historyViewModel.SiteId(),
  55. FileId: historyViewModel.FileId()
  56. }).done(function () {
  57. utils.toast.show('도면 이력 항목 삭제 처리가 성공하였습니다.');
  58. popupVisible(false);
  59. });
  60. });
  61. }
  62. function setupDropzone() {
  63. if (_.isNull(dropZone)) {
  64. dropZone = BWA.DropZone.create({
  65. id: '#drawingHistoryFileUpload',
  66. categoryId: $Code.FileCategory.DRAWING,
  67. uploadedFileInfo: uploadedFileInfo,
  68. handleSuccess: function (fileInfo) {
  69. historyViewModel.FileId(fileInfo.FileId);
  70. },
  71. handleRemovedFile: function () {
  72. historyViewModel.FileId(null);
  73. },
  74. });
  75. }
  76. }
  77. popupVisible.subscribe(utils.popup.getAttachFunc('#popupDetail', timerObj, position));
  78. position.subscribe(function (value) {
  79. console.log(value);
  80. });
  81. isNewData.subscribe(function (isNew) {
  82. // isVisibleDeleteButton(isNew === false);
  83. textAreaHistoryNoteHeight(isNew ? TEXTAREA_HEIGHT_MIN : TEXTAREA_HEIGHT_MAX);
  84. if (isNew && popupVisible()) {
  85. isVisibleDropZone('visible');
  86. }
  87. else {
  88. isVisibleDropZone('hidden');
  89. }
  90. });
  91. viewModel.popupVisible.subscribe(function (value) {
  92. if (value === false) {
  93. popupVisible(false);
  94. }
  95. });
  96. viewModel.isEditModeInPopup.subscribe(function (value) {
  97. if (value === false && isNewData()) {
  98. popupVisible(false);
  99. }
  100. isVisibleSaveButton(value);
  101. isVisibleDeleteButton(!value);
  102. });
  103. return {
  104. visible: popupVisible,
  105. isNewData: isNewData,
  106. show: function () {
  107. popupVisible(true);
  108. },
  109. hide: function () {
  110. popupVisible(false);
  111. },
  112. popupOptions: {
  113. width: '480px',
  114. height: '616px',
  115. dragEnabled: false,
  116. position: position,
  117. visible: popupVisible,
  118. showingAction: function () { },
  119. closeOnOutsideClick: false,
  120. shading: false,
  121. animation: {
  122. show: { type: "slide", duration: 150, from: { left: '-=10', opacity: 0 }, to: { opacity: 1 } },
  123. hide: { type: "slide", duration: 150, from: { left: '-=10', opacity: 1 }, to: { opacity: 0 } }
  124. },
  125. shownAction: function () {
  126. if (isNewData()) {
  127. isVisibleDropZone('visible');
  128. }
  129. else {
  130. isVisibleDropZone('hidden');
  131. }
  132. setupDropzone();
  133. },
  134. hidingAction: function () {
  135. dropZone.dispose(uploadedFileInfo);
  136. }
  137. },
  138. toolbarItems: [
  139. { location: 'before', text: $G('drawingHistoryDetailInfo') },
  140. {
  141. location: 'after', widget: 'button', options: {
  142. text: $G('save'),
  143. icon: 'save',
  144. visible: isVisibleSaveButton,
  145. disabled: viewModel.hasnotModificationPermission,
  146. clickAction: handleButtonSave
  147. }
  148. },
  149. {
  150. location: 'after', widget: 'button', options: {
  151. text: $G('delete'),
  152. icon: 'remove',
  153. type: 'danger',
  154. visible: isVisibleDeleteButton,
  155. disabled: viewModel.hasnotModificationPermission,
  156. clickAction: handleButtonDelete
  157. }
  158. },
  159. {
  160. location: 'after', widget: 'button', options: {
  161. text: $G('close'),
  162. icon: 'close',
  163. clickAction: function () { popupVisible(false); }
  164. }
  165. }
  166. ],
  167. setDrawingHistoryGridViewInstance: function (instance) {
  168. historyGridView = instance;
  169. },
  170. setSelectedDrawingHistory: function (history) {
  171. isNewData(false);
  172. BWA.DataUtil.copyViewModel(history, historyViewModel);
  173. historyViewModel.FileName(history['CmFile/Name']());
  174. historyViewModel.UpdatedUserName(history['CmUser/Name']());
  175. console.log(historyViewModel.toJS());
  176. },
  177. handleInsertDrawingHistory: function () {
  178. isNewData(true);
  179. BWA.DataUtil.resetDataModel(_.omit(historyViewModel, 'DrawingId'));
  180. var maxHistory = _.max(drawingHistories(), function (x) {
  181. return x.RevisionNo();
  182. });
  183. historyViewModel.RevisionNo(maxHistory.RevisionNo() + 1);
  184. historyViewModel.UpdatedUserName(BWA.UserInfo.Name());
  185. popupVisible(true);
  186. }
  187. };
  188. }
  189. }
  190. });