BemsWebApplication.SetChart = function (params, viewInfo) { "use strict"; var facilityTypeDataSource = BemsWebApplication.db.createDataSource('BemsFacilityType', true); var ChartInfoDataSource = BemsWebApplication.db.createDataSource('BemsChartInfo', true); var facilityTypes = ko.observableArray(); var ChartInfo = ko.observableArray(); var searchfacilityTypes = ko.observableArray(); var facilityTypeDeferred = new $.Deferred(); var BemsFormulaBaseDataSource = BemsWebApplication.db.createDataSource('BemsFormulaBase', true, true); var formulaListByFacilityType = ko.observableArray(); var palettes = ['Default', 'Soft Pastel', 'Harmony Light', 'Pastel', 'Bright', 'Soft', 'Ocean', 'Vintage', 'Violet']; var chartTypes = ['bar', 'line', 'spline', 'area', 'scatter', 'splinearea', 'stepline', 'steparea']; var dataSourceOptions = { select: [ 'SiteId', 'FacilityTypeId', 'BemsFacilityType/Name', 'ChartId', 'Palette', 'Title', 'LAxTitle', 'UseLAxMinMax', 'LAxMin', 'LAxMax', 'RAxTitle', 'UseRAxMinMax', 'RAxMin', 'RAxMax', 'UseX', 'XAxTitle', 'XSFmId', 'XSType', 'UseXAxMinMax', 'XAxMin', 'XAxMax', 'LSFmId1', 'LSName1', 'LSType1', 'LSFmId2', 'LSName2', 'LSType2', 'LSFmId3', 'LSName3', 'LSType3', 'LSFmId4', 'LSName4', 'LSType4', 'RSFmId1', 'RSName1', 'RSType1', 'RSFmId2', 'RSName2', 'RSType2', 'RSFmId3', 'RSName3', 'RSType3', 'RSFmId4', 'RSName4', 'RSType4', 'UseChart', 'UseLCTLine', 'LCTLineTitle', 'LCTLineValue', 'UseRCTLine', 'RCTLineTitle', 'RCTLineValue', ], filter: [ ['SiteId', '=', BWA.UserInfo.SiteId()] ], expand: [ 'BemsFacilityType', ], extendOptions: { forceOriginalField: true }, }; var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'BemsChartInfo', { dataSourceOptions: dataSourceOptions, columns: [ { dataField: 'SiteId', caption: '번호', width: '8%', alignment: 'center', sortOder: 'desc' }, { dataField: 'BemsFacilityType/Name', caption: '설비타입', width: '15%', alignment: 'center' }, { dataField: 'ChartId', caption: '차트ID', width: '10%', alignment: 'center' }, { dataField: 'Title', caption: '차트타이틀', width: '15%', alignment: 'center' }, { dataField: 'Palette', caption: '차트 색상', width: '15%', alignment: 'center' }, { dataField: 'LAxTitle', caption: '좌Y축 타이틀', width: '20%', alignment: 'center' }, { dataField: 'LSName1', caption: '좌Y축 항목1 타이틀', width: '20%', alignment: 'center' }, /*{ dataField: 'UseLAxMinMax', caption: '좌Y축 최대최소값 사용', width: '5%', alignment: 'center', customizeText: function (cellInfo) { return $G.isUse(cellInfo.value); } },*/ { dataField: 'RAxTitle', caption: '우Y축 타이틀', width: '20%', alignment: 'center' }, /*{ dataField: 'UseRAxMinMax', caption: '우Y축 최대최소값 사용', width: '5%', alignment: 'center', customizeText: function (cellInfo) { return $G.isUse(cellInfo.value); } },*/ { dataField: 'RSName1', caption: '우Y축 항목1 타이틀', width: '20%', alignment: 'center' }, //{ dataField: 'Palette', caption: $G('phoneNo'), width: '20%', alignment: 'center' }, /* { dataField: 'IsControlSchedule', caption: '제어스케줄', width: '15%', alignment: 'center', customizeText: function (cellInfo) { return $G.isUse(cellInfo.value); } },*/ { dataField: 'UseChart', caption: '차트 사용', width: '15%', alignment: 'center', customizeText: function (cellInfo) { return $G.isUse(cellInfo.value); //return $G.isYes(cellInfo.value); } } //utils.datagrid.columnIsUse('10%'), ], // 2019.04.17 엑셀 출력 기능 추가 ~~~ "export": { enabled: true, fileName: '성능분석 차트 설정 내용' }, onExporting: function (e) { e.component.columnOption("SiteId", "visible", false); }, onExported: function (e) { e.component.columnOption("SiteId", "visible", true); }, // ~~~ 2019.04.17 엑셀 출력 기능 추가 paging: { pageSize: 18, enabled: true }, pager: { //showPageSizeSelector: false, //allowedPageSizes: 18, //showInfo: false }, promiseDataInSearchView: facilityTypeDeferred.promise(), searchViewItems: [{ id: 'FacilityTypeId', ignoreValue: 0, defaultValue: 0, dataSource: searchfacilityTypes }, { id: 'Name' }], handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) { dataGrid.clearSelection(); viewModel.isNewInPopup(false); var data = clickRow.data; viewModel.handleSelectBoxChangeFacilityType({ value: data.FacilityTypeId() }); //var dataModel = viewModel.dataModel; /* dataModel.CompanyName = $KoSet(dataModel.CompanyName, data['CmCompany/Name']); dataModel.DepartmentName = $KoSet(dataModel.DepartmentName, data['CmDepartment/Name']); dataModel.BusinessFieldName = $KoSet(dataModel.BusinessFieldName, data['CmBusinessField/Name']); dataModel.UserGroupName = $KoSet(dataModel.UserGroupName, data['CmUserGroup/Name']); dataModel.IsScheduleUser = $KoSet(dataModel.IsScheduleUser, data.IsScheduleUser()); dataModel.IsSI = $KoSet(dataModel.IsSI, data.IsSI()); dataModel.IsMobile = $KoSet(dataModel.IsMobile, data.IsMobile());*/ popupVisible(true); }, handleViewShowing: function () { facilityTypeDataSource.filter([ ['FacilityTypeId', '<', 50]/*, 'and', ['FacilityTypeId', '<>', 1], 'and', ['FacilityTypeId', '<>', 2], 'and', ['FacilityTypeId', '<>', 8],*/ ]); facilityTypeDataSource.load().done(function (result) { facilityTypes(result); //searchfacilityTypes([{ facilityTypeId: 0, Name: $G('selectAll') }].concat(result)); searchfacilityTypes(result); facilityTypeDeferred.resolve(); }); ChartInfoDataSource.load().done(function (result) { ChartInfo(result); }); }, handlePopupShowing: function (isNewInPopup, dataViewModel) { if (isNewInPopup()) { dataViewModel.ChartId(1); dataViewModel.UseChart(true); dataViewModel.UseX(false); dataViewModel.UseXAxMinMax(false); dataViewModel.UseLAxMinMax(false); dataViewModel.UseRAxMinMax(false); dataViewModel.Palette('Default'); dataViewModel.UseLCTLine(false); dataViewModel.UseRCTLine(false); } }, popupWidth: 1000, handleViewShown: function () { }, //2015 12 21 hcLee isUseSiteId: (BWA.UserInfo.isAdmin() == false) ? true : false, beforeInsertingDataViewModel: function (dataModel, dbModelId) { var dfd = $.Deferred(); var result; for (var i = 0; i < ChartInfo().length; i++) { if (viewModel.dataModel.ChartId() == ChartInfo()[i].ChartId()) { result = false; break; } else { result = true; } } if (result) { dfd.resolve(true); } else { dfd.resolve(false, '차트 ID가 중복되었습니다.'); } return dfd.promise(); }, /* beforeInsertingDataViewModel: function (dataModel, dbModelId) { var dfd = $.Deferred(); $.when(BWA.api.post('BemsMonitoringPoint/GetMaxSiteId', null)) .done(function (newPid) { if (newPid > 0) { dataModel.SiteId(newPid); dfd.resolve(true); // hcLee OK good, (true, false 또는 객체로 리턴가능함) 2015 11 19 } else dfd.resolve(false, 'SiteId 자동 생성에 실패하였습니다!'); // hcLee OK good, (true, false 또는 객체로 리턴가능함) 2015 11 19 }); return dfd.promise(); },*/ handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) { // 사이트정보는 생성 후 삭제할 수 없음 viewModel.visibleDeleteButton(true); } }); viewModel.isEditModeInPopup.subscribe(function (value) { viewModel.visibleDeleteButton(true); }); { viewModel.popupInsertButtonOptions.visible = true; } viewModel.facilityTypes = facilityTypes; viewModel.palettes = palettes; viewModel.chartTypes = chartTypes; viewModel.formulaListByFacilityType = formulaListByFacilityType; viewModel.handleSelectBoxChangeFacilityType = function (e) { // hcLee 2018 03 02 //기존 setArrayDataSourceFilter 를 확장하여 추가한 함수이다. // 동기화 Deferred 때문에 이 함수 동기화 내부에서 formulaListByFacilityType에 외기온도,습도 를 강제로 추가하는 코드가 존재 해야만 // 팝업 콤보에 정상으로 추가된 항목(외기온도,습도)이 보이게 된다. BWA.DataUtil.setArrayDataSourceFilterForChartSet(BemsFormulaBaseDataSource, 'FacilityTypeId', e.value, formulaListByFacilityType); var i = 0; } return viewModel; };