4b28ad66dd166e73aa27891b8b1eb6f6e5903037.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. BemsWebApplication.AnnounceManagement = function (params, viewInfo) {
  2. 'use strict';
  3. var imagefileUrl1 = ko.observable(),
  4. uploadedFileInfo = {},
  5. dropZone1 = null;
  6. var isEditModeInPopup = ko.observable(false);
  7. var eq = BWA.DataUtil.constructEqualFilter,
  8. and = BWA.DataUtil.andFilter;
  9. var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, true, true),
  10. partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, true, true),
  11. contractClassDataSource = BemsWebApplication.db.createDataSource('FmsContractClass', true, true, true),
  12. contractMethodDataSource = BemsWebApplication.db.createDataSource('FmsContractMethod', true, true, true),
  13. contractTypeDataSource = BemsWebApplication.db.createDataSource('FmsContractType', true, true, true),
  14. paymentTypeDataSource = BemsWebApplication.db.createDataSource('FmsPaymentType', true, true, true),
  15. businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true);
  16. var businessFieldsForSearch = ko.observableArray();
  17. var endpointSelector = "";
  18. if (BemsWebApplication.config.mode == "production") {
  19. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  20. } else {
  21. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  22. }
  23. var partnerTypes = ko.observableArray(),
  24. contractClasses = ko.observableArray(),
  25. contractMethods = ko.observableArray(),
  26. contractTypes = ko.observableArray(),
  27. paymentTypes = ko.observableArray(),
  28. allPartner = ko.observableArray(),
  29. filteredPartner = ko.observableArray(),
  30. businessFields = ko.observableArray();
  31. var partnerTypesForSearch = ko.observableArray(),
  32. contractClassesForSearch = ko.observableArray(),
  33. contractMethodsForSearch = ko.observableArray(),
  34. contractTypesForSearch = ko.observableArray(),
  35. paymentTypesForSearch = ko.observableArray();
  36. var deferredForSearch = new $.Deferred();
  37. var dataSourceOptions = {
  38. select: [
  39. 'SiteId',
  40. 'AnnouncementId',
  41. 'BusinessFieldId',
  42. 'CmBusinessField/Name',
  43. 'Title',
  44. 'Contents',
  45. 'RegisterUserId ',
  46. 'CmUser/Name', // 등록자
  47. 'FileId',
  48. 'CmFile/Name',
  49. 'CmFile/FileSize',
  50. 'AddDate',
  51. 'UpdateDate',
  52. 'IsUse',
  53. ],
  54. expand: [
  55. 'CmBusinessField',
  56. 'CmFile',
  57. 'CmUser'
  58. ],
  59. extendOptions: {
  60. forceOriginalField: true
  61. },
  62. filter: [
  63. ['SiteId', '=', BWA.UserInfo.SiteId()],
  64. ]
  65. };
  66. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmAnnouncement', {
  67. dataSourceOptions: dataSourceOptions,
  68. columns: [
  69. { dataField: 'AnnouncementId', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false, sortOrder: 'desc' },
  70. { dataField: 'CmBusinessField/Name', caption: '업무분야', width: '10%', alignment: 'center' },
  71. { dataField: 'Title', caption: '제목', width: '40%', alignment: 'center' },
  72. { dataField: 'CmUser/Name', caption: '등록자', width: '40%', alignment: 'center' },
  73. {
  74. dataField: 'AddDate', caption: '등록일', width: '20%', alignment: 'center',
  75. customizeText: function (cellInfo) {
  76. return $G.date(cellInfo.value);
  77. }
  78. },
  79. {
  80. dataField: 'UpdateDate', caption: '만료일', width: '20%', alignment: 'center',
  81. customizeText: function (cellInfo) {
  82. return $G.date(cellInfo.value);
  83. }
  84. },
  85. //utils.datagrid.columnIsUse('20%') hcLee 2015 12 23
  86. ],
  87. /*
  88. toolbarItems: [
  89. { location: 'before', text: '공지사항 입력' },
  90. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
  91. { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: _.isBoolean(isModifiable) ? isModifiable : visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
  92. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  93. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
  94. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  95. ], */
  96. //popupWidth: 580,
  97. searchViewItems: [
  98. { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  99. { id: 'Title' },
  100. { id: 'Contents' },
  101. { id: 'AddDate', type: 'dateRange', isOnlyDate: true },
  102. ],
  103. mandatoryFields: [
  104. { dataField: 'Title', name: '제목' },
  105. { dataField: 'Contents', name: '내용' }
  106. ],
  107. handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
  108. if (isNewInPopup() == false) {
  109. if (_.isNull(dataViewModel.FileId()) === false) {
  110. //alert('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId()));
  111. imagefileUrl1('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId()));
  112. }
  113. else {
  114. imagefileUrl1(undefined);
  115. }
  116. var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
  117. dataViewModel.ReadCount(dataViewModel.ReadCount() + 1);
  118. BWA.db.CmAnnouncement.update(keys, dataViewModel.toJS());
  119. }
  120. },
  121. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  122. dataGrid.clearSelection();
  123. var data = clickRow.data;
  124. var dataModel = viewModel.dataModel;
  125. if (dataModel.AnnouncementId() == data.AnnouncementId()) {
  126. setTimeout(function(){
  127. var dataSource = new DevExpress.data.DataSource({
  128. store: {
  129. type: "odata",
  130. url: endpointSelector + "/CmFile",
  131. },
  132. requireTotalCount: true
  133. });
  134. dataSource.filter([
  135. ["SiteId", "=", BWA.UserInfo.SiteId()],
  136. "and",
  137. ["FileId", "=", viewModel.dataModel.FileId()]
  138. ]);
  139. dataSource.load()
  140. .done(function (result) {
  141. dataModel.AttachmentFileName(result[0].Name);
  142. });
  143. }, 100)
  144. }
  145. else {
  146. if (data['FileId']() != null) {
  147. dataModel.AttachmentFileName(data['CmFile/Name']());
  148. }
  149. else {
  150. dataModel.AttachmentFileName('');
  151. }
  152. }
  153. //alert(dataModel.AttachmentFileName());
  154. popupVisible(true);
  155. },
  156. handleViewShowing: function (dataModel) {
  157. businessFieldDataSource.load().done(function (dbBusinessFields) {
  158. businessFields(dbBusinessFields);
  159. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  160. });
  161. //$.when(
  162. // partnerTypeDataSource.load(),
  163. // contractClassDataSource.load(),
  164. // contractMethodDataSource.load(),
  165. // contractTypeDataSource.load(),
  166. // paymentTypeDataSource.load(),
  167. // partnerDataSource.load()
  168. //).done(function (partnerTypeDataResult, contractClassDataResult, contractMethodDataResult, contractTypeDataResult, paymentTypeDataResult, partnerDataResult) {
  169. // partnerTypes(partnerTypeDataResult[0]);
  170. // contractClasses(contractClassDataResult[0]);
  171. // contractMethods(contractMethodDataResult[0]);
  172. // contractTypes(contractTypeDataResult[0]);
  173. // paymentTypes(paymentTypeDataResult[0]);
  174. // allPartner(partnerDataResult[0]);
  175. //partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerTypeId', partnerTypeDataResult[0]));
  176. //contractClassesForSearch($SearchView.createArrayOfSelectBox('ContractClassId', contractClassDataResult[0]));
  177. //contractMethodsForSearch($SearchView.createArrayOfSelectBox('ContractMethodId', contractMethodDataResult[0]));
  178. //contractTypesForSearch($SearchView.createArrayOfSelectBox('ContractTypeId', contractTypeDataResult[0]));
  179. //paymentTypesForSearch($SearchView.createArrayOfSelectBox('PaymentTypeId', paymentTypeDataResult[0]));
  180. //deferredForSearch.resolve();
  181. //});
  182. },
  183. handlePopupShowing: function (isNewInPopup, dataViewModel) {
  184. // 신규등록인 경우
  185. //imagefileUrl1(undefined);
  186. //dropZone1.removeAllFiles();
  187. //if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
  188. if (isNewInPopup()) {
  189. // hcLee 2016 01 04 추가
  190. dropZone1 = null;
  191. imagefileUrl1(undefined);
  192. dataViewModel.AddDate(new Date());
  193. dataViewModel.UpdateDate(new Date());
  194. dataViewModel.RegisterUserId(BWA.UserInfo.UserId());
  195. dataViewModel.ReadCount(0);
  196. }
  197. },
  198. handlePopupShown: function (isEditMode, isNew, dataViewModel) {
  199. imagefileUrl1(undefined);
  200. if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
  201. isEditModeInPopup(false);
  202. if (isNew) { // 신규등록인 경우
  203. isEditModeInPopup(true);
  204. dropZone1 = null;
  205. }
  206. },
  207. handleCancelInPopup: function () {
  208. isEditModeInPopup(false);
  209. },
  210. handlePopupButtonEdit: function (dataModel) {
  211. isEditModeInPopup(true);
  212. },
  213. handlePopupButtonClose: function () {
  214. isEditModeInPopup(false);
  215. },
  216. handleViewShown: function (dataViewModel, isEditModeInPopup) {
  217. setupDropZone(isEditModeInPopup, dataViewModel);
  218. $("#gridContainer").dxDataGrid({
  219. paging: {
  220. pageSize: 20,
  221. enabled: true
  222. }
  223. });
  224. },
  225. handleSaveSuccess: function () {
  226. if (_.isNull(dropZone1) === false) {
  227. dropZone1.resetUploadedFileInfo();
  228. }
  229. isEditModeInPopup(false);
  230. },
  231. handleAfterSaveInPopup: function (responseKey, response) {//2019-10-14 변경
  232. viewModel.dataModel.AnnouncementId(responseKey.AnnouncementId);
  233. setTimeout(function(){
  234. var dataSource = new DevExpress.data.DataSource({
  235. store: {
  236. type: "odata",
  237. url: endpointSelector + "/CmAnnouncement",
  238. },
  239. requireTotalCount: true
  240. });
  241. dataSource.filter([
  242. ["SiteId", "=", BWA.UserInfo.SiteId()],
  243. "and",
  244. ["AnnouncementId", "=", viewModel.dataModel.AnnouncementId()]
  245. ]);
  246. dataSource.load()
  247. .done(function (result) {
  248. viewModel.dataModel.FileId(result[0].FileId);
  249. });
  250. }, 100)
  251. },
  252. handleSaveButtonInPopup: function (isInsert) {//2019-10-14 변경
  253. if (isInsert === false) {//추가, 변경 여부
  254. if (_.isNull(dropZone1) === false) {
  255. if (viewModel.dataModel.FileId() != null) { //변경 - 그림삭제
  256. var temp = {
  257. SiteId: BWA.UserInfo.SiteId(),
  258. FileId: viewModel.dataModel.FileId()
  259. }
  260. BWA.db.CmFile.byKey(temp).done(function (data) {
  261. dropZone1.removeFile(data);
  262. dropZone1.processQueue();
  263. });
  264. }
  265. else {
  266. dropZone1.processQueue();//변경 - 그림 삭제 필요없음
  267. }
  268. }
  269. }
  270. else {
  271. if (_.isNull(dropZone1) === false) { //추가
  272. if (viewModel.dataModel.FileId() == null) {
  273. dropZone1.processQueue();
  274. }
  275. }
  276. }
  277. },
  278. handleBeforeDelete: function () {//2019-10-14 변경
  279. if (viewModel.dataModel.FileId() != null) {
  280. var temp = {
  281. SiteId: BWA.UserInfo.SiteId(),
  282. FileId: viewModel.dataModel.FileId()
  283. }
  284. BWA.db.CmFile.byKey(temp).done(function (data) {
  285. if ($('#announceDropZone1').length) {
  286. if (_.isNull(dropZone1)) {
  287. dropZone1 = BWA.DropZone.create({
  288. id: '#announceDropZone1',
  289. categoryId: $Code.FileCategory.ANNOUNCEMENT
  290. });
  291. dropZone1.removeFile(data);
  292. dropZone1 = null;
  293. }
  294. }
  295. });
  296. }
  297. },
  298. handleAfterDelete: function () {
  299. },
  300. });
  301. function processValueChange(e) {
  302. filteredPartner([]);
  303. _.each(allPartner(), function (partner) {
  304. if (e.value === partner.PartnerTypeId()) {
  305. filteredPartner.push(partner);
  306. }
  307. });
  308. if (!_.isEmpty(filteredPartner())) {
  309. viewModel.dataModel.PartnerId(filteredPartner()[0].PartnerId());
  310. }
  311. }
  312. function setupDropZone(isEditModeInPopup, dataViewModel) {
  313. var timer = null;
  314. isEditModeInPopup.subscribe(function (value) {
  315. if (value) {
  316. if (timer) { clearInterval(timer); }
  317. timer = setInterval(function () {
  318. if ($('#announcementDropZone1').length) {
  319. if (_.isNull(dropZone1)) {
  320. dropZone1 = BWA.DropZone.create({
  321. id: '#announcementDropZone1',
  322. previewTemplate: "...",
  323. categoryId: $Code.FileCategory.ANNOUNCEMENT,
  324. uploadedFileInfo: uploadedFileInfo,
  325. handleRemoveBeforePromise: function () {
  326. var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
  327. return BWA.db.CmAnnouncement.update(keys, { FileId: null });
  328. },
  329. handleSuccess: function (fileInfo) {
  330. dataViewModel.FileId(fileInfo.FileId);
  331. dropZone1.options.startLoadFileCount = 1;
  332. if (uploadedFileInfo.FileId) {
  333. dataViewModel.FileId(uploadedFileInfo.FileId);
  334. var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
  335. if (keys.AnnouncementId != null) {
  336. return BWA.db.CmAnnouncement.update(keys, { FileId: uploadedFileInfo.FileId });
  337. }
  338. }
  339. },
  340. handleRemovedFile: function () {
  341. dataViewModel.FileId(null);
  342. if (dropZone1 != null)
  343. dropZone1.options.startLoadFileCount = 0;
  344. },
  345. });
  346. }
  347. }
  348. }, 100);
  349. }
  350. else {
  351. if (timer) { clearInterval(timer); timer = null; }
  352. dropZone1 = null;
  353. }
  354. });
  355. }
  356. /*
  357. var toolbarItems = [
  358. { location: 'before', text: '공지사항 입력' },
  359. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
  360. { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: _.isBoolean(isModifiable) ? isModifiable : visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
  361. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  362. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
  363. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
  364. ]; */
  365. viewModel.popupVisible.subscribe(function (value) {
  366. if (!value) {
  367. viewModel.gridView().refresh();
  368. }
  369. });
  370. viewModel.dataModel.AttachmentFileName = ko.observable();
  371. viewModel.imagefileUrl1 = imagefileUrl1;
  372. viewModel.businessFields = businessFields;
  373. viewModel.processValueChange = processValueChange;
  374. viewModel.partnerTypes = partnerTypes;
  375. viewModel.contractClasses = contractClasses;
  376. viewModel.contractMethods = contractMethods;
  377. viewModel.contractTypes = contractTypes;
  378. viewModel.paymentTypes = paymentTypes;
  379. viewModel.allPartner = allPartner;
  380. viewModel.filteredPartner = filteredPartner;
  381. viewModel.isEditModeInPopup = isEditModeInPopup;
  382. //viewModel.toolbarItems = toolbarItems;
  383. return viewModel;
  384. };