ac29b1318d3d1576117075d1042f228817316d34.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. BemsWebApplication.Announce = function (params, viewInfo) {
  2. 'use strict';
  3. var imagefileUrl1 = ko.observable(),
  4. uploadedFileInfo = {},
  5. dropZone1 = null;
  6. var eq = BWA.DataUtil.constructEqualFilter,
  7. and = BWA.DataUtil.andFilter;
  8. var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, true, true),
  9. partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, true, true),
  10. contractClassDataSource = BemsWebApplication.db.createDataSource('FmsContractClass', true, true, true),
  11. contractMethodDataSource = BemsWebApplication.db.createDataSource('FmsContractMethod', true, true, true),
  12. contractTypeDataSource = BemsWebApplication.db.createDataSource('FmsContractType', true, true, true),
  13. paymentTypeDataSource = BemsWebApplication.db.createDataSource('FmsPaymentType', true, true, true),
  14. businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true);
  15. var businessFieldsForSearch = ko.observableArray();
  16. var partnerTypes = ko.observableArray(),
  17. contractClasses = ko.observableArray(),
  18. contractMethods = ko.observableArray(),
  19. contractTypes = ko.observableArray(),
  20. paymentTypes = ko.observableArray(),
  21. allPartner = ko.observableArray(),
  22. filteredPartner = ko.observableArray(),
  23. businessFields = ko.observableArray();
  24. var partnerTypesForSearch = ko.observableArray(),
  25. contractClassesForSearch = ko.observableArray(),
  26. contractMethodsForSearch = ko.observableArray(),
  27. contractTypesForSearch = ko.observableArray(),
  28. paymentTypesForSearch = ko.observableArray();
  29. var deferredForSearch = new $.Deferred();
  30. var now = new Date();
  31. var endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
  32. var eq = BWA.DataUtil.constructEqualFilter;
  33. var dataSourceOptions = {
  34. select: [
  35. 'SiteId',
  36. 'AnnouncementId',
  37. 'BusinessFieldId',
  38. 'CmBusinessField/Name',
  39. 'Title',
  40. 'Contents',
  41. 'RegisterUserId ',
  42. 'CmUser/Name', // 등록자
  43. 'FileId',
  44. 'CmFile/Name',
  45. 'CmFile/FileSize',
  46. 'AddDate',
  47. 'UpdateDate',
  48. 'IsUse',
  49. 'ReadCount',
  50. ],
  51. expand: [
  52. 'CmBusinessField',
  53. 'CmFile',
  54. 'CmUser'
  55. ],
  56. extendOptions: {
  57. forceOriginalField: true
  58. },
  59. filter: [
  60. ['SiteId', '=', BWA.UserInfo.SiteId()],
  61. 'and',
  62. ['UpdateDate', '>', endDate]
  63. ]
  64. };
  65. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmAnnouncement', {
  66. dataSourceOptions: dataSourceOptions,
  67. columns: [
  68. { dataField: 'AnnouncementId', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false, sortOrder: 'desc' },
  69. { dataField: 'CmBusinessField/Name', caption: '업무분야', width: '10%', alignment: 'center' },
  70. { dataField: 'Title', caption: '제목', width: '40%', alignment: 'center' },
  71. { dataField: 'CmUser/Name', caption: '등록자', width: '20%', alignment: 'center' },
  72. {
  73. dataField: 'AddDate', caption: '등록일', width: '20%', alignment: 'center', dataType: "shortDate", format: "yyyy-MM-dd",
  74. customizeText: function (cellInfo) {
  75. return cellInfo.valueText;
  76. }
  77. },
  78. {
  79. dataField: 'UpdateDate', caption: '만료일', width: '20%', alignment: 'center', dataType: "shortDate", format: "yyyy-MM-dd",
  80. customizeText: function (cellInfo) {
  81. return cellInfo.valueText;
  82. }
  83. },
  84. //utils.datagrid.columnIsUse('20%')
  85. { dataField: 'ReadCount', caption: '조회수', width: '10%', alignment: 'center' },
  86. ],
  87. paging: {
  88. pageSize: 18,
  89. enabled: true
  90. },
  91. pager: {},
  92. // 2019.04.17 엑셀 출력 기능 추가 ~~~
  93. "export": {
  94. enabled: true,
  95. fileName: '공지사항 목록'
  96. },
  97. onExporting: function (e) {
  98. e.component.columnOption('AnnouncementId', "visible", false);
  99. },
  100. onExported: function (e) {
  101. e.component.columnOption('AnnouncementId', "visible", true);
  102. },
  103. // ~~~ 2019.04.17 엑셀 출력 기능 추가
  104. //popupWidth: 580,
  105. searchViewItems: [
  106. { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  107. { id: 'Title' },
  108. { id: 'Contents' },
  109. { id: 'AddDate', type: 'dateRange', isOnlyDate: true },
  110. ],
  111. handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
  112. if (isNewInPopup() == false) {
  113. if (_.isNull(dataViewModel.FileId()) === false) {
  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. viewModel.visibleEditButton(false);
  125. viewModel.visibleDeleteButton(false);
  126. },
  127. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  128. dataGrid.clearSelection();
  129. var data = clickRow.data;
  130. var dataModel = viewModel.dataModel;
  131. if (data['FileId']() != null)
  132. dataModel.AttachmentFileName(data['CmFile/Name']());
  133. else dataModel.AttachmentFileName('');
  134. popupVisible(true);
  135. },
  136. handleViewShowing: function (dataModel) {
  137. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  138. if (useBusinessFiltering) {
  139. dataSourceOptions.filter.push('and');
  140. dataSourceOptions.filter.push([eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  141. businessFieldDataSource.filter([
  142. eq('SiteId', BWA.UserInfo.SiteId()),
  143. and,
  144. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
  145. ]);
  146. }
  147. businessFieldDataSource.load().done(function (dbBusinessFields) {
  148. businessFields(dbBusinessFields);
  149. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  150. });
  151. //$.when(
  152. // partnerTypeDataSource.load(),
  153. // contractClassDataSource.load(),
  154. // contractMethodDataSource.load(),
  155. // contractTypeDataSource.load(),
  156. // paymentTypeDataSource.load(),
  157. // partnerDataSource.load()
  158. //).done(function (partnerTypeDataResult, contractClassDataResult, contractMethodDataResult, contractTypeDataResult, paymentTypeDataResult, partnerDataResult) {
  159. // partnerTypes(partnerTypeDataResult[0]);
  160. // contractClasses(contractClassDataResult[0]);
  161. // contractMethods(contractMethodDataResult[0]);
  162. // contractTypes(contractTypeDataResult[0]);
  163. // paymentTypes(paymentTypeDataResult[0]);
  164. // allPartner(partnerDataResult[0]);
  165. //partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerTypeId', partnerTypeDataResult[0]));
  166. //contractClassesForSearch($SearchView.createArrayOfSelectBox('ContractClassId', contractClassDataResult[0]));
  167. //contractMethodsForSearch($SearchView.createArrayOfSelectBox('ContractMethodId', contractMethodDataResult[0]));
  168. //contractTypesForSearch($SearchView.createArrayOfSelectBox('ContractTypeId', contractTypeDataResult[0]));
  169. //paymentTypesForSearch($SearchView.createArrayOfSelectBox('PaymentTypeId', paymentTypeDataResult[0]));
  170. //deferredForSearch.resolve();
  171. //});
  172. },
  173. handlePopupShowing: function (isNewInPopup, dataViewModel) {
  174. // 신규등록인 경우
  175. if (isNewInPopup()) {
  176. dataViewModel.AddDate(new Date());
  177. dataViewModel.UpdateDate(new Date());
  178. dataViewModel.RegisterUserId(BWA.UserInfo.UserId());
  179. }
  180. },
  181. handlePopupShown: function (isEditMode, isNew, dataViewModel) {
  182. },
  183. handleViewShown: function (dataViewModel, isEditModeInPopup) {
  184. setupDropZone(isEditModeInPopup, dataViewModel);
  185. },
  186. handleSaveSuccess: function () {
  187. if (_.isNull(dropZone1) === false) {
  188. dropZone1.resetUploadedFileInfo();
  189. }
  190. },
  191. });
  192. function processValueChange(e) {
  193. filteredPartner([]);
  194. _.each(allPartner(), function (partner) {
  195. if (e.value === partner.PartnerTypeId()) {
  196. filteredPartner.push(partner);
  197. }
  198. });
  199. if (!_.isEmpty(filteredPartner())) {
  200. viewModel.dataModel.PartnerId(filteredPartner()[0].PartnerId());
  201. }
  202. }
  203. function setupDropZone(isEditModeInPopup, dataViewModel) {
  204. var timer = null;
  205. isEditModeInPopup.subscribe(function (value) {
  206. if (value) {
  207. if (timer) { clearInterval(timer); }
  208. timer = setInterval(function () {
  209. if ($('#announcementDropZone1').length) {
  210. if (_.isNull(dropZone1)) {
  211. dropZone1 = BWA.DropZone.create({
  212. id: '#announcementDropZone1',
  213. categoryId: $Code.FileCategory.ANNOUNCEMENT,
  214. uploadedFileInfo: uploadedFileInfo,
  215. handleRemoveBeforePromise: function () {
  216. var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
  217. return BWA.db.CmAnnouncement.update(keys, { FileId: null });
  218. },
  219. handleSuccess: function (fileInfo) {
  220. dataViewModel.FileId(fileInfo.FileId);
  221. },
  222. handleRemovedFile: function () {
  223. dataViewModel.FileId(null);
  224. },
  225. });
  226. uploadedFileInfo.SiteId = dataViewModel.SiteId();
  227. uploadedFileInfo.FileId = dataViewModel.FileId();
  228. if (uploadedFileInfo.FileId) {
  229. BWA.db.CmFile.byKey(uploadedFileInfo).done(function (data) {
  230. dropZone1.removeAllFiles();
  231. dropZone1.emit('addedfile', {
  232. name: data.Name,
  233. size: data.FileSize
  234. });
  235. //dropZone.options.maxFiles = 0; // 이게 있으면 삭제후 다시 업로드가 안 된다.
  236. });
  237. }
  238. }
  239. }
  240. }, 100);
  241. }
  242. else {
  243. if (timer) { clearInterval(timer); timer = null; }
  244. dropZone1 = null;
  245. }
  246. });
  247. }
  248. viewModel.popupVisible.subscribe(function (value) {
  249. if (!value) {
  250. viewModel.gridView().refresh();
  251. }
  252. });
  253. viewModel.dataModel.AttachmentFileName = ko.observable();
  254. viewModel.imagefileUrl1 = imagefileUrl1;
  255. viewModel.businessFields = businessFields;
  256. viewModel.processValueChange = processValueChange;
  257. viewModel.partnerTypes = partnerTypes;
  258. viewModel.contractClasses = contractClasses;
  259. viewModel.contractMethods = contractMethods;
  260. viewModel.contractTypes = contractTypes;
  261. viewModel.paymentTypes = paymentTypes;
  262. viewModel.allPartner = allPartner;
  263. viewModel.filteredPartner = filteredPartner;
  264. return viewModel;
  265. };