123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- BemsWebApplication.AnnounceManagement = function (params, viewInfo) {
- 'use strict';
- var imagefileUrl1 = ko.observable(),
- uploadedFileInfo = {},
- dropZone1 = null;
- var isEditModeInPopup = ko.observable(false);
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter;
- var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, true, true),
- partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, true, true),
- contractClassDataSource = BemsWebApplication.db.createDataSource('FmsContractClass', true, true, true),
- contractMethodDataSource = BemsWebApplication.db.createDataSource('FmsContractMethod', true, true, true),
- contractTypeDataSource = BemsWebApplication.db.createDataSource('FmsContractType', true, true, true),
- paymentTypeDataSource = BemsWebApplication.db.createDataSource('FmsPaymentType', true, true, true),
- businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true);
- var businessFieldsForSearch = ko.observableArray();
- var endpointSelector = "";
- if (BemsWebApplication.config.mode == "production") {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
- } else {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
- }
- var partnerTypes = ko.observableArray(),
- contractClasses = ko.observableArray(),
- contractMethods = ko.observableArray(),
- contractTypes = ko.observableArray(),
- paymentTypes = ko.observableArray(),
- allPartner = ko.observableArray(),
- filteredPartner = ko.observableArray(),
- businessFields = ko.observableArray();
- var partnerTypesForSearch = ko.observableArray(),
- contractClassesForSearch = ko.observableArray(),
- contractMethodsForSearch = ko.observableArray(),
- contractTypesForSearch = ko.observableArray(),
- paymentTypesForSearch = ko.observableArray();
- var deferredForSearch = new $.Deferred();
- var dataSourceOptions = {
- select: [
- 'SiteId',
- 'AnnouncementId',
- 'BusinessFieldId',
- 'CmBusinessField/Name',
- 'Title',
- 'Contents',
- 'RegisterUserId ',
- 'CmUser/Name', // 등록자
- 'FileId',
- 'CmFile/Name',
- 'CmFile/FileSize',
- 'AddDate',
- 'UpdateDate',
- 'IsUse',
- ],
- expand: [
- 'CmBusinessField',
- 'CmFile',
- 'CmUser'
- ],
- extendOptions: {
- forceOriginalField: true
- },
- filter: [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- ]
- };
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmAnnouncement', {
- dataSourceOptions: dataSourceOptions,
- columns: [
- { dataField: 'AnnouncementId', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false, sortOrder: 'desc' },
- { dataField: 'CmBusinessField/Name', caption: '업무분야', width: '10%', alignment: 'center' },
- { dataField: 'Title', caption: '제목', width: '40%', alignment: 'center' },
- { dataField: 'CmUser/Name', caption: '등록자', width: '40%', alignment: 'center' },
- {
- dataField: 'AddDate', caption: '등록일', width: '20%', alignment: 'center',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- {
- dataField: 'UpdateDate', caption: '만료일', width: '20%', alignment: 'center',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- //utils.datagrid.columnIsUse('20%') hcLee 2015 12 23
- ],
- /*
- toolbarItems: [
- { location: 'before', text: '공지사항 입력' },
- { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
- { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: _.isBoolean(isModifiable) ? isModifiable : visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
- { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
- ], */
- //popupWidth: 580,
- searchViewItems: [
- { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
- { id: 'Title' },
- { id: 'Contents' },
- { id: 'AddDate', type: 'dateRange', isOnlyDate: true },
- ],
- mandatoryFields: [
- { dataField: 'Title', name: '제목' },
- { dataField: 'Contents', name: '내용' }
- ],
- handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
- if (isNewInPopup() == false) {
- if (_.isNull(dataViewModel.FileId()) === false) {
- //alert('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId()));
- imagefileUrl1('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId()));
- }
- else {
- imagefileUrl1(undefined);
- }
- var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
- dataViewModel.ReadCount(dataViewModel.ReadCount() + 1);
- BWA.db.CmAnnouncement.update(keys, dataViewModel.toJS());
- }
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- var data = clickRow.data;
- var dataModel = viewModel.dataModel;
- if (dataModel.AnnouncementId() == data.AnnouncementId()) {
- setTimeout(function(){
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/CmFile",
- },
- requireTotalCount: true
- });
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["FileId", "=", viewModel.dataModel.FileId()]
- ]);
- dataSource.load()
- .done(function (result) {
- dataModel.AttachmentFileName(result[0].Name);
- });
- }, 100)
- }
- else {
- if (data['FileId']() != null) {
- dataModel.AttachmentFileName(data['CmFile/Name']());
- }
- else {
- dataModel.AttachmentFileName('');
- }
- }
- //alert(dataModel.AttachmentFileName());
- popupVisible(true);
- },
- handleViewShowing: function (dataModel) {
- businessFieldDataSource.load().done(function (dbBusinessFields) {
- businessFields(dbBusinessFields);
- businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
- });
- //$.when(
- // partnerTypeDataSource.load(),
- // contractClassDataSource.load(),
- // contractMethodDataSource.load(),
- // contractTypeDataSource.load(),
- // paymentTypeDataSource.load(),
- // partnerDataSource.load()
- //).done(function (partnerTypeDataResult, contractClassDataResult, contractMethodDataResult, contractTypeDataResult, paymentTypeDataResult, partnerDataResult) {
- // partnerTypes(partnerTypeDataResult[0]);
- // contractClasses(contractClassDataResult[0]);
- // contractMethods(contractMethodDataResult[0]);
- // contractTypes(contractTypeDataResult[0]);
- // paymentTypes(paymentTypeDataResult[0]);
- // allPartner(partnerDataResult[0]);
- //partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerTypeId', partnerTypeDataResult[0]));
- //contractClassesForSearch($SearchView.createArrayOfSelectBox('ContractClassId', contractClassDataResult[0]));
- //contractMethodsForSearch($SearchView.createArrayOfSelectBox('ContractMethodId', contractMethodDataResult[0]));
- //contractTypesForSearch($SearchView.createArrayOfSelectBox('ContractTypeId', contractTypeDataResult[0]));
- //paymentTypesForSearch($SearchView.createArrayOfSelectBox('PaymentTypeId', paymentTypeDataResult[0]));
- //deferredForSearch.resolve();
- //});
- },
- handlePopupShowing: function (isNewInPopup, dataViewModel) {
- // 신규등록인 경우
- //imagefileUrl1(undefined);
- //dropZone1.removeAllFiles();
- //if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
- if (isNewInPopup()) {
- // hcLee 2016 01 04 추가
- dropZone1 = null;
- imagefileUrl1(undefined);
- dataViewModel.AddDate(new Date());
- dataViewModel.UpdateDate(new Date());
- dataViewModel.RegisterUserId(BWA.UserInfo.UserId());
- dataViewModel.ReadCount(0);
- }
- },
- handlePopupShown: function (isEditMode, isNew, dataViewModel) {
- imagefileUrl1(undefined);
- if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
- isEditModeInPopup(false);
- if (isNew) { // 신규등록인 경우
- isEditModeInPopup(true);
- dropZone1 = null;
- }
- },
- handleCancelInPopup: function () {
- isEditModeInPopup(false);
- },
- handlePopupButtonEdit: function (dataModel) {
- isEditModeInPopup(true);
- },
- handlePopupButtonClose: function () {
- isEditModeInPopup(false);
- },
- handleViewShown: function (dataViewModel, isEditModeInPopup) {
- setupDropZone(isEditModeInPopup, dataViewModel);
-
- $("#gridContainer").dxDataGrid({
- paging: {
- pageSize: 20,
- enabled: true
- }
- });
- },
- handleSaveSuccess: function () {
- if (_.isNull(dropZone1) === false) {
- dropZone1.resetUploadedFileInfo();
- }
- isEditModeInPopup(false);
- },
- handleAfterSaveInPopup: function (responseKey, response) {//2019-10-14 변경
- viewModel.dataModel.AnnouncementId(responseKey.AnnouncementId);
- setTimeout(function(){
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/CmAnnouncement",
- },
- requireTotalCount: true
- });
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["AnnouncementId", "=", viewModel.dataModel.AnnouncementId()]
- ]);
- dataSource.load()
- .done(function (result) {
- viewModel.dataModel.FileId(result[0].FileId);
- });
- }, 100)
- },
- handleSaveButtonInPopup: function (isInsert) {//2019-10-14 변경
- if (isInsert === false) {//추가, 변경 여부
- if (_.isNull(dropZone1) === false) {
- if (viewModel.dataModel.FileId() != null) { //변경 - 그림삭제
- var temp = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId()
- }
- BWA.db.CmFile.byKey(temp).done(function (data) {
- dropZone1.removeFile(data);
- dropZone1.processQueue();
- });
- }
- else {
- dropZone1.processQueue();//변경 - 그림 삭제 필요없음
- }
- }
- }
- else {
- if (_.isNull(dropZone1) === false) { //추가
- if (viewModel.dataModel.FileId() == null) {
- dropZone1.processQueue();
- }
- }
- }
- },
- handleBeforeDelete: function () {//2019-10-14 변경
- if (viewModel.dataModel.FileId() != null) {
- var temp = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId()
- }
- BWA.db.CmFile.byKey(temp).done(function (data) {
- if ($('#announceDropZone1').length) {
- if (_.isNull(dropZone1)) {
- dropZone1 = BWA.DropZone.create({
- id: '#announceDropZone1',
- categoryId: $Code.FileCategory.ANNOUNCEMENT
- });
- dropZone1.removeFile(data);
- dropZone1 = null;
- }
- }
- });
- }
- },
- handleAfterDelete: function () {
- },
- });
- function processValueChange(e) {
- filteredPartner([]);
- _.each(allPartner(), function (partner) {
- if (e.value === partner.PartnerTypeId()) {
- filteredPartner.push(partner);
- }
- });
- if (!_.isEmpty(filteredPartner())) {
- viewModel.dataModel.PartnerId(filteredPartner()[0].PartnerId());
- }
- }
- function setupDropZone(isEditModeInPopup, dataViewModel) {
- var timer = null;
- isEditModeInPopup.subscribe(function (value) {
- if (value) {
- if (timer) { clearInterval(timer); }
- timer = setInterval(function () {
- if ($('#announcementDropZone1').length) {
- if (_.isNull(dropZone1)) {
- dropZone1 = BWA.DropZone.create({
- id: '#announcementDropZone1',
- previewTemplate: "...",
- categoryId: $Code.FileCategory.ANNOUNCEMENT,
- uploadedFileInfo: uploadedFileInfo,
- handleRemoveBeforePromise: function () {
- var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
- return BWA.db.CmAnnouncement.update(keys, { FileId: null });
- },
- handleSuccess: function (fileInfo) {
- dataViewModel.FileId(fileInfo.FileId);
- dropZone1.options.startLoadFileCount = 1;
- if (uploadedFileInfo.FileId) {
- dataViewModel.FileId(uploadedFileInfo.FileId);
- var keys = BWA.db.extractKeysObject('CmAnnouncement', dataViewModel);
- if (keys.AnnouncementId != null) {
- return BWA.db.CmAnnouncement.update(keys, { FileId: uploadedFileInfo.FileId });
- }
- }
- },
- handleRemovedFile: function () {
- dataViewModel.FileId(null);
- if (dropZone1 != null)
- dropZone1.options.startLoadFileCount = 0;
- },
- });
- }
- }
- }, 100);
- }
- else {
- if (timer) { clearInterval(timer); timer = null; }
- dropZone1 = null;
- }
- });
- }
- /*
- var toolbarItems = [
- { location: 'before', text: '공지사항 입력' },
- { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: _.isBoolean(isModifiable) ? isModifiable : visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
- { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: _.isBoolean(isModifiable) ? isModifiable : visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
- { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: handlePopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
- ]; */
- viewModel.popupVisible.subscribe(function (value) {
- if (!value) {
- viewModel.gridView().refresh();
- }
- });
- viewModel.dataModel.AttachmentFileName = ko.observable();
- viewModel.imagefileUrl1 = imagefileUrl1;
- viewModel.businessFields = businessFields;
- viewModel.processValueChange = processValueChange;
- viewModel.partnerTypes = partnerTypes;
- viewModel.contractClasses = contractClasses;
- viewModel.contractMethods = contractMethods;
- viewModel.contractTypes = contractTypes;
- viewModel.paymentTypes = paymentTypes;
- viewModel.allPartner = allPartner;
- viewModel.filteredPartner = filteredPartner;
- viewModel.isEditModeInPopup = isEditModeInPopup;
- //viewModel.toolbarItems = toolbarItems;
- return viewModel;
- };
|