123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- BemsWebApplication.RegularCheckSchedule = function (params, viewInfo, legalCheckOptions) {
- "use strict";
- var cycleUnitDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeCycleUnit'),
- holidayWorkTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeHolidayWorkType', true, true),
- businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true),
- agencyDataSource = undefined;
- //var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, false, true);
- //var partnerTypes = ko.observableArray();
- //BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
- var popup;
- var IsUseStatusForSerach = ko.observable(); //추가
- var searchIsuseStatus = $SearchView.createObservableCodeNamesOfSelectBoxForSearch($G.IsUseName);// 추가
- var eq = BWA.DataUtil.constructEqualFilter, and = BWA.DataUtil.andFilter;
- var FmsWorkScheduleDataSource = BemsWebApplication.db.createDataSource('FmsWorkSchedule');
- var workschedule = ko.observableArray();
- var RowName, RowBusinessFieldId;
- var legalCheckViewOptions = undefined, legalCheckPopupOptions = undefined;
- var anyCheckViewOptions = undefined;
- if (legalCheckOptions) {
- legalCheckViewOptions = legalCheckOptions.viewOptions;
- legalCheckPopupOptions = legalCheckOptions.popupOptions;
- }
- var cycleUnits = ko.observableArray(), holidayWorkTypes = ko.observableArray(), businessFields = ko.observableArray(), agencies = undefined,
- businessFieldsForSearch = ko.observableArray(), agenciesForSearch = undefined;
- var deferredForSearch = new $.Deferred();
- var selectedScheduleId;
- var selectedScheduleName = ko.observable();
- var workTypeId = legalCheckViewOptions ? $Code.WorkType.LEGAL_CHECK : (anyCheckViewOptions ? $Code.WorkType.INNER_CHECK : $Code.WorkType.REGULAR_CHECK),
- dataSourceOptions = {
- select: [
- 'SiteId', 'WorkScheduleId', 'WorkTypeId', 'BusinessFieldId', 'Name',
- 'CycleSize', 'IsUse', 'IsAutoOrder', 'WorkDueDate',
- 'CmUser/Name', 'CmBusinessField/Name', 'FmsWorkCodeCycleUnit/Name', 'FmsWorkCodeHolidayWorkType/Name',
- 'CmPartner/Name'
- ],
- filter: [
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('WorkTypeId', workTypeId)
- ],
- expand: ['CmUser', 'CmBusinessField', 'FmsWorkCodeCycleUnit', 'FmsWorkCodeHolidayWorkType', 'CmPartner'],
- extendOptions: {
- forceOriginalField: true
- }
- };
- if (!_.isUndefined(legalCheckViewOptions)) {
- //dataSourceOptions.select.push('FmsWorkCodeLegalInspectionAgency/Name');
- //dataSourceOptions.expand.push('FmsWorkCodeLegalInspectionAgency');
- dataSourceOptions.select.push('CmPartner/Name');
- dataSourceOptions.expand.push('CmPartner');
- //agencyDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeLegalInspectionAgency', true, true);
- agencyDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
- agencyDataSource.filter([
- eq('PartnerTypeId', 3), // 검사기관
- and,
- eq('SiteId', BWA.UserInfo.SiteId())
- ])
- agencies = ko.observableArray();
- agenciesForSearch = ko.observableArray();
- }
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkSchedule', {
- popupWidth: 1200,
- dataSourceOptions: dataSourceOptions,
- columns: _.compact([
- { dataField: 'WorkScheduleId', caption: $G('number'), width: '8%', alignment: 'center', sortOrder: 'desc' },
- { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
- { dataField: 'Name', caption: $G('facilityCheckScheduleName'), width: '34%', alignment: 'center' },
- {
- dataField: 'WorkDueDate', caption: $G('workDueDate'), width: '12%', alignment: 'center',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- { dataField: 'FmsWorkCodeHolidayWorkType/Name', caption: $G('facilityCheckScheduleHolidayName'), width: '10%', alignment: 'center' },
- { dataField: 'FmsWorkCodeCycleUnit/Name', caption: $G('facilityCheckScheduleCycleUnitName'), width: '10%', alignment: 'center' },
- legalCheckViewOptions ? { dataField: 'CmPartner/Name', caption: $G('legalInspectionAgency'), width: '15%', alignment: 'center' } : undefined,
- {
- dataField: 'IsAutoOrder', caption: $G("autoOrder"), alignment: 'center', width: '8%',
- customizeText: function (cellInfo) {
- return $G.isUse(cellInfo.value);
- }
- },
- utils.datagrid.columnIsUse('8%')
- ]),
- promiseDataInSearchView: deferredForSearch.promise(),
- searchViewItems: _.compact([
- { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
- legalCheckViewOptions ? { id: 'InspectionAgencyId', ignoreValue: 0, defaultValue: 0, dataSource: agenciesForSearch } : undefined,
- { id: 'Name' },
- { id: 'WorkDueDate', type: 'dateRange', isOnlyDate: true},
- { id: 'IsUse', ignoreValue: 0, defaultValue: true, value: IsUseStatusForSerach, dataSource: searchIsuseStatus, isChecked: true } //추가 //$SearchView.handleSearchInSearchView();
- ]),//IsUseStatusForSerach
- wordWrapEnabled: true,
- cellPrepared: function (cellElement, cellInfo) {
- if (cellInfo.rowType == 'data') {
- switch (cellInfo.column.dataField) {
- case 'FmsWorkCodeCycleUnit/Name':
- $(cellElement).text(cellInfo.data.CycleSize() + ' ' + cellInfo.value);
- break;
- }
- }
- },
- handleInitializeDataModelValue: function (dataModel) {
- dataModel.IsAutoOrder(false);
- dataModel.WorkTypeId(workTypeId);
- dataModel.BusinessFieldId(BWA.UserInfo.BusinessFieldId());
- },
- // 이름 중복 방지
- handlePopupShowing: function () {
- if (popup && popup.handlePopupShowing) {
- popup.handlePopupShowing.apply(this, arguments);
- }
-
- FmsWorkScheduleDataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- 'and',
- ["WorkTypeId", "=", workTypeId]
- ]);
- FmsWorkScheduleDataSource.load().done(function (result) {
- workschedule(result);
- });
- },
- beforeInsertingDataViewModel: function (dataModel, dbModelId) {
- var dfd = $.Deferred();
- var isDuplicated = false;
- for (var i = 0; i < workschedule().length; i++) {
- if (dataModel.Name() == workschedule()[i].Name() && dataModel.BusinessFieldId() == workschedule()[i].BusinessFieldId()) {
- isDuplicated = true;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
- return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
- else {
- if (isDuplicated)
- return dfd.resolve(false, '이미 동일 정보가 존재합니다.');
- else
- return dfd.resolve(true);
- }
- },
- beforeUpdateDataViewModel: function () {
- var isDuplicated = false;
- for (var i = 0; i < workschedule().length; i++) {
- if (viewModel.dataModel.Name() == workschedule()[i].Name() && viewModel.dataModel.BusinessFieldId() == workschedule()[i].BusinessFieldId()
- && (RowName() != workschedule()[i].Name() || RowBusinessFieldId() != workschedule()[i].BusinessFieldId())) {
- isDuplicated = true;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
- utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
- return 0;
- }
- else {
- if (isDuplicated) {
- utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
- return 0;
- }
- else
- return 2;
- }
- },
- handleViewShowing: function () {
- var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
- if (useBusinessFiltering) {
- dataSourceOptions.filter.push('and');
- dataSourceOptions.filter.push([eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
- businessFieldDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
- ]);
- }
- var loadFromDataSource = BWA.DataUtil.loadFromDataSource;
- //loadFromDataSource(holidayWorkTypeDataSource, holidayWorkTypes);
- $.when.apply($, _.compact([
- cycleUnitDataSource.load(),
- holidayWorkTypeDataSource.load(),
- businessFieldDataSource.load(),
- agencyDataSource ? agencyDataSource.load() : undefined
- ])).done(function (dbCycleUnits, dbHolidayWorkTypes, dbBusinessFields, dbAgencies) {
- cycleUnits(dbCycleUnits[0]);
- holidayWorkTypes(dbHolidayWorkTypes[0]);
- businessFields(dbBusinessFields[0]);
- businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
- if (!_.isUndefined(dbAgencies)) {
- agencies(dbAgencies[0]);
- agenciesForSearch($SearchView.createArrayOfSelectBox('PartnerId', agencies()));
- }
- deferredForSearch.resolve();
- });
- },
- handleAfterLoadingModelByKey: function (data, dataViewModel) {
- var dataModel = viewModel.dataModel;
- dataModel.CycleSizeText(data.CycleSize + ' ' + dataModel.CycleUnitName());
- if (popup && popup.handleAfterLoadingModelByKey) {
- popup.handleAfterLoadingModelByKey(data, dataViewModel);
- }
- },
- handleViewShown: function () { // 추가
- setTimeout(delayplay, 100);
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- var data = clickRow.data;
- var dataModel = viewModel.dataModel;
- if (popup && popup.handleBeforeShowingPopupForEdit) {
- popup.handleBeforeShowingPopupForEdit(data, dataModel);
- }
- RowName = data.Name;
- RowBusinessFieldId = data.BusinessFieldId;
- //selectedScheduleId = data.ScheduleId();
- //selectedScheduleName = $KoSet(selectedScheduleName, data.Name());
- //selectedCheckGroupDataSource.filter([
- // ['SiteId', '=', BWA.UserInfo.SiteId()],
- // 'and',
- // ['WorkScheduleId', '=', selectedScheduleId]
- //]);
- popupVisible(true);
- },
- 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);
- }
- },
- getAddedToolbarItemsInPopup: function (e) {
- var isEditModeInPopup = e.isEditModeInPopup;
- return [{
- 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: function () {
- if (popup && popup.handleDeleteSelectedFacilities) {
- popup.handleDeleteSelectedFacilities();
- }
- }
- }
- }];
- },
- //handlePopupShown: function (editMode, isNewInPopup, dataModel) {
- // if (popup && popup.handlePopupShowing) {
- // popup.handlePopupShown.apply(this, arguments);
- // }
- //}
- });
- //function processValueChange(e) {
- // if ($G.date(viewModel.dataModel.WorkDueDate()) < $G.date(new Date()))
- // {
- // viewModel.dataModel.WorkDueDate(new Date());
- // utils.toast.show('작업예정일은 오늘 혹은 오늘 이후로 설정하시기 바랍니다.', 'error');
- // }
- //}
- function delayplay() {
- BemsWebApplication.app.currentViewInfo = viewInfo;
- BemsWebApplication.app.currentViewInfo.model.handleSearchInSearchView();
- }
- viewModel.dataModel.CycleSizeText = ko.observable();
- viewModel.cycleUnits = cycleUnits;
- viewModel.holidayWorkTypes = holidayWorkTypes;
- viewModel.businessFields = businessFields;
- viewModel.agencies = agencies;
- viewModel.legalCheckOptions = legalCheckOptions;
- popup = viewModel.popup = BWA.Popup.RegularCheckSchedule.create(viewInfo, viewModel, legalCheckPopupOptions);
-
- viewModel.popupVisible.subscribe(function (visible) {
- if (!visible) {
- popup.facilitiesInView([]);
- popup.facilities([]);
- }
- });
- //viewModel.processValueChange = processValueChange;
- return viewModel;
- };
|