BemsWebApplication.WorkHistory = function (params, viewInfo) { "use strict"; //권한설정 var hasnotModificationPermission = ko.observable(true); 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 FmsMaterialExdataSource = new DevExpress.data.DataSource({ store: BemsWebApplication.odata.FmsMaterialEx, requireTotalCount: true, pageSize: 100 }); var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName); var businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true), workTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeType'), progressDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeProgress'), businessFields = ko.observableArray(), workTypes = ko.observableArray(), progresses = ko.observableArray(); var WORK_PLAN = $Code.WorkProgress.WORK_PLAN; var isVisibleExecutionButton = ko.observable(true); var isVisibleApproalButton = ko.observable(true); var isEditModeInPopup = ko.observable(true); var isEditHistoryButton = ko.observable(false); var isAddHistoryButton = ko.observable(false); var isWorkDone = ko.observable(false); var isWorkHold = ko.observable(false); var popup, addWorkResultCheckItemPopup = null; var workResultCheckItemMaterialPopup = null; var WorkResultCheckItemFacilityPopup = null; //var workApprovalMaterialPopup = null; //var workExecutionRegisterPopup = null; // hcLee 2018 01 29 --> var imagefileUrl1 = ko.observable(), imagefileUrl2 = ko.observable(), dropZone1 = null, dropZone2 = null, uploadedFileInfo = {}, uploadedFileInfo2 = {}; // <-- hcLee 2018 01 29 var deferredForSearch = new $.Deferred(); var SiteId = BWA.UserInfo.SiteId(); var workTypesForSearch = ko.observableArray(), businessFieldsForSearch = ko.observableArray(), progressesForSearch = ko.observableArray(); var eq = BWA.DataUtil.constructEqualFilter, or = BWA.DataUtil.orFilter, and = BWA.DataUtil.andFilter, noteq = BWA.DataUtil.constructNotEqualFilter; var selectedFacilityData = ko.observable(), selectedUserData = params.selectedUserData || ko.observable(); var dataSourceOptions = { select: [ 'SiteId', 'WorkRequestId', 'BusinessFieldId', 'FmsWorkResult/StartDate', 'FmsWorkResult/EndDate', 'FmsWorkResult/ConfirmedDate', 'FmsWorkResult/ConfirmedUserId', 'FmsWorkResult/IsConfirmed', 'FmsWorkResult/CauseClassId', 'FmsWorkResult/Content', 'FmsWorkResult/ConfirmDesc',//추가 'WorkTypeId', 'StartWorkDate', 'FmsWorkOrder/CmBusinessField', 'CmUser/Name', // 신청자 'Title', // 제목 'Content', // 내용 'FmsWorkOrder/OrderDate', 'WorkProgressId', 'FmsWorkResult/CmUser/Name', // 작업자 'FmsWorkResult/CmUser1/Name', // 승인자 'FmsWorkCodeType/Name', 'CmBusinessField/Name', 'FmsWorkCodeProgress/Name', 'CmUser1/Name', // 반려자 'RejectDate', 'RejectReason', 'FmsWorkOrder/Content' ], expand: [ 'FmsWorkResult', 'FmsWorkOrder', 'FmsWorkCodeType', 'FmsWorkCodeProgress', 'CmBusinessField', 'FmsWorkOrder/CmBusinessField', 'CmUser', 'CmUser1', 'FmsWorkResult/CmUser', 'FmsWorkResult/CmUser1'], extendOptions: { forceOriginalField: true } }; if (!useBusinessFiltering) { dataSourceOptions.filter = [ eq('SiteId', SiteId), and, ['WorkProgressId', '>', WORK_PLAN], ]; } else { dataSourceOptions.filter = [ eq('SiteId', SiteId), and, ['WorkProgressId', '>', WORK_PLAN], and, [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]]; } //var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkResult', { var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkRequest', { popupWidth: 890, dataSourceOptions: dataSourceOptions, columns: [ { dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center' }, { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' }, //{ dataField: 'FmsWorkOrder/CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' }, { dataField: 'FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '10%', alignment: 'center' }, { dataField: 'FmsWorkOrder/OrderDate', caption: $G('orderedDate'), width: '12%', alignment: 'center', visible: false // , sortOrder: 'desc' ,customizeText: function (cellInfo) { return $G.date(cellInfo.value); } }, { dataField: 'FmsWorkResult/StartDate', caption: $G('startDate'), width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd', customizeText: function (cellInfo) { return cellInfo.valueText; } }, { dataField: 'FmsWorkResult/EndDate', caption: '종료일', width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd', sortOrder: 'desc', customizeText: function (cellInfo) { return cellInfo.valueText; } }, { dataField: 'FmsWorkResult/ConfirmedDate', caption: '승인일', width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd', customizeText: function (cellInfo) { return cellInfo.valueText; } }, { dataField: 'Title', caption: '작업명', width: '50%', alignment: 'center' }, { dataField: 'FmsWorkCodeProgress/Name', caption: $G('workProgressName'), width: '10%', alignment: 'center' }, { dataField: 'CmUser/Name', caption: '신청자', width: '12%', alignment: 'center' }, { dataField: 'CmUser1/Name', caption: '반려자', width: '12%', alignment: 'center', visible: false }, { dataField: 'FmsWorkResult/CmUser/Name', caption: '작업자', width: '12%', alignment: 'center' }, { dataField: 'FmsWorkResult/CmUser1/Name', caption: '승인자', width: '12%', alignment: 'center' }, { dataField: 'FmsWorkOrder/Content', caption: '오더내용', width: '0%', alignment: 'center' } ], "export": { enabled: true, fileName: '작업 이력 목록', }, onExporting: function (e) { e.component.columnOption("WorkRequestId", "visible", false); }, onExported: function (e) { e.component.columnOption("WorkRequestId", "visible", true); }, promiseDataInSearchView: deferredForSearch.promise(), searchViewItems: _.compact([ //{ id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch }, { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch }, { id: 'WorkTypeId', ignoreValue: 0, defaultValue: 0, dataSource: workTypesForSearch }, { id: 'CmUser/Name' }, { id: 'CmUser1/Name' }, { id: 'FmsWorkResult/CmUser/Name' }, { id: 'FmsWorkResult/CmUser1/Name' }, { id: 'Title' }, { id: 'WorkProgressId', ignoreValue: 0, defaultValue: 0, dataSource: progressesForSearch }, { id: 'FmsWorkResult/StartDate', type: 'dateRange', isOnlyDate: true }, { id: 'FmsWorkResult/EndDate', type: 'dateRange', isOnlyDate: true }, { id: 'FmsWorkResult/ConfirmedDate', type: 'dateRange', isOnlyDate: true } ]), getAddedToolbarItemsInPopup: function (e) { //var isEditModeInPopup = e.isEditModeInPopup; //var isVisibleApproalButton = e.dataViewModel.IsConfirmed; return [ { location: 'after', widget: 'button', options: { text: '승인', icon: 'add', type: 'success', visible: isVisibleApproalButton, disabled: hasnotModificationPermission, clickAction: approvalWorkResult } }, { location: 'after', widget: 'button', options: { text: "삭제", icon: 'remove', type: 'danger', visible: isEditModeInPopup, disabled: hasnotModificationPermission, clickAction: removeWorkResult } } ]; //{ // location: 'after', widget: 'button', options: { // text: '작업이력수정', icon: 'save', // clickAction: function () { // if (popup && popup.modifyWorkItem) { // popup.modifyWorkItem(); // } // } // } //}, //{ // location: 'after', widget: 'button', options: { // text: $G('facilityInsertion'), icon: 'search', visible: isEditModeInPopup, // clickAction: function () { // popup.facilitySearchPopup.show(); // } // } //}, //{ // location: 'after', widget: 'button', options: { // text: $G('facilityDeletion'), icon: 'remove', type: 'danger', visible: isEditModeInPopup, // clickAction: removeWorkResult // } //} }, beforeInsertingDataViewModel: function (dataModel) { return true; // hcLee }, handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) { //추가 dataGrid.clearSelection(); var data = clickRow.data; var dataModel = viewModel.dataModel; //viewModel.dataModel.StartDate = ko.observable(); //viewModel.dataModel.EndDate = ko.observable(); //if (data['FmsWorkResult/StartDate'] !== undefined) { // viewModel.dataModel.StartDate(data['FmsWorkResult/StartDate']()); // viewModel.dataModel.EndDate(data['FmsWorkResult/EndDate']()); //} // hcLee 2016 04 04 if (data['WorkProgressId']() >= $Code.WorkProgress.WORK_COMPLETE) isWorkDone(true); else isWorkDone(false); if (data['WorkProgressId']() == $Code.WorkProgress.WORK_HOLD) { isWorkHold(true); isWorkDone(false); } else { isWorkHold(false); } isVisibleApproalButton(false); if (popup && popup.handleBeforeShowingPopupForEdit) { popup.handleBeforeShowingPopupForEdit(data, dataModel); } //popup.show(); popupVisible(true); if (dataModel.WorkProgressId() >= $Code.WorkProgress.WORKING) { workResultCheckItemMaterialPopup.visible(true); //workApprovalMaterialPopup.visible(true); } }, handleBeforePopupShowingPromise: function () { if (popup && popup.handleBeforePopupShowingPromise) { popup.handleBeforePopupShowingPromise.apply(popup, arguments); } }, handleAfterLoadingModelByKey: function () { if (popup && popup.handleAfterLoadingModelByKey) { popup.handleAfterLoadingModelByKey.apply(popup, arguments); } }, handlePopupShowing: function () { if (popup && popup.handlePopupShowing) { popup.handlePopupShowing.apply(this, arguments); } }, handlePopupShown: function (editMode, isNewInPopup, dataModel) { if (popup && popup.handlePopupShowing) { popup.handlePopupShown.apply(this, arguments); } }, handleSaveButtonInPopup: function (isInsert) { if (isInsert === false) { if (popup && popup.handleAfterSave) { popup.handleAfterSave(undefined); } } }, handleAfterSaveInPopup: function (responseKey, response) { if (popup && popup.handleAfterSave) { popup.handleAfterSave(responseKey, response); } }, handleViewShowing: function (dataModel) { //권한설정 hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName)); FmsMaterialExdataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()] ]); FmsMaterialExdataSource.load().done(function (result) { if (result != null) { viewModel.dataModel.MaterialExdataSource(result); } }).fail(function (error) { utils.toast.show(error); }); if (useBusinessFiltering) { businessFieldDataSource.filter([ eq('SiteId', SiteId), and, [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)] ]); } $.when( businessFieldDataSource.load(), workTypeDataSource.load(), progressDataSource.load() ).done(function (businessFieldResult, workTypeResult, progressResult) { businessFields(businessFieldResult[0]); workTypes(workTypeResult[0]); //progressResult[0].items.Remove[0]; progresses(progressResult[0]); progresses.shift(); businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields())); workTypesForSearch($SearchView.createArrayOfSelectBox('WorkTypeId', workTypes())); //progressesForSearch($SearchView.createArrayOfSelectBox('ProgressId', progresses())); hcLee 2016 02 01 'ProgressId' -> 'WorkProgressId' progressesForSearch($SearchView.createArrayOfSelectBox('WorkProgressId', progresses())); deferredForSearch.resolve(); }); }, handleViewShown: function () { $("#gridContainer").dxDataGrid({ paging: { pageSize: 18, enabled: true } }); } }); viewModel.isEditHistoryButton = isEditHistoryButton; viewModel.isAddHistoryButton = isAddHistoryButton; viewModel.isWorkDone = isWorkDone; viewModel.isWorkHold = isWorkHold; viewModel.dataModel.MaterialExdataSource = ko.observable(); // hcLee 2018 01 29 --> viewModel.imagefileUrl1 = imagefileUrl1; viewModel.imagefileUrl2 = imagefileUrl2; // <-- hcLee 2018 01 29 viewModel.businessFields = businessFields; viewModel.workTypes = workTypes; viewModel.isAddPopup = ko.observable(false); viewModel.isApprovalMode = ko.observable(false); // 작업이력 화면인지 여부 viewModel.isWorkHistory = ko.observable(true); addWorkResultCheckItemPopup = viewModel.addWorkResultCheckItemPopup = BWA.Popup.AddWorkResultCheckItem.create(viewInfo, viewModel); popup = viewModel.popup = BWA.Popup.WorkHistory.create(viewInfo, viewModel); workResultCheckItemMaterialPopup = viewModel.workResultCheckItemMaterialPopup = BWA.Popup.WorkResultCheckItemMaterial.create(viewInfo, viewModel); WorkResultCheckItemFacilityPopup = viewModel.WorkResultCheckItemFacilityPopup = BWA.Popup.WorkResultCheckItemFacility.create(viewInfo, viewModel); //workApprovalMaterialPopup = viewModel.workApprovalMaterialPopup = BWA.Popup.WorkApprovalMaterial.create(viewInfo, viewModel); function approvalWorkResult() { viewModel.dataModel.ConfirmedDate(new Date()); viewModel.dataModel.IsConfirmed(true); viewModel.dataModel.ConfirmedUserId(BWA.UserInfo.UserId()); var keys = BWA.db.extractKeysObject('FmsWorkResult', viewModel.dataModel); BWA.db.FmsWorkResult.update(keys, viewModel.dataModel.toJS()).done(function (res) { var parameters = { SiteId: SiteId, WorkRequestId: viewModel.dataModel.WorkRequestId(), WorkProgressId: $Code.WorkProgress.WORK_CONFIRM }; // FmsWorkRequest 업데이트: WorkProgressId(6) BWA.api.post('FmsWorkRequest', null, parameters); utils.toast.show($G('successDatabaseUpdateMsg')); //popup.popupVisible(false); viewModel.popupOptions.visible(false); viewModel.gridView().refresh(); }); utils.toast.show('Approval Clicked!'); } function removeWorkResult() { var WorkRequestId = viewModel.dataModel.WorkRequestId(); var WorkProgressId = viewModel.dataModel.WorkScheduleId(); BWA.api.post('FmsWorkHistory/Remove', { SiteId: SiteId, WorkRequestId: WorkRequestId, }).done(function () { utils.toast.show("데이터를 삭제하였습니다."); $('#gridContainer').dxDataGrid('instance').refresh(); viewModel.popupOptions.visible(false); }).fail(function (error) { utils.toast.show("데이터 삭제를 실패하였습니다.", 'error'); }); } viewModel.popupOptions.position = { offset: '-200 0' }; viewModel.popupOptions.height = '930px'; return viewModel; };