1223bc24a63ee90528b2485d0415746863251284.svn-base 18 KB

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