BemsWebApplication.EnergySavingControl = function (params, viewInfo) {
    "use strict";

    var initialized = false,
        shouldReload = false,
        datagrid = null,
        currentTabIndex = ko.observable(0),
        facilityViewModel = new BWA.CmFacilityViewModel(),
        dataSource;

    var m_Facility;

    var multiViewItems = [
        {
            template: 'mainCharts',
        },
        {
            template: 'subCharts'
        },
    ];
    
    var facilityDataSource = BWA.db.createDataSource('CmFacility'),
        facilitiesForSearch = ko.observableArray(),

        facilityCodeForSearch = ko.observable(0),

        deferredForSearch = new $.Deferred();

    var  visiblePopup = ko.observable(false);

    var dataCalorie = ko.observableArray(),
        dataAtfw = ko.observableArray(),
        dataTemperatureCalorie = ko.observableArray(),
        dataTemperatureElectricity = ko.observableArray()
    ;

    var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
    //var controlPoint = new BWA.Chart.ControlPoint(BWA.UserInfo.SiteId());
    var timeBoxForSearch = BWA.SearchView.createDateTimeBox();

    var chartEnthalpy = BWA.Chart.Instance('chartEnthalpyES', 'dxChart'),
        chartCO2 = BWA.Chart.Instance('chartCO2ES', 'dxChart'),
        chartSet = BWA.Chart.Instance('chartSetES', 'dxChart');

    var chartLayout = new BWA.ChartLayout({
        divs: [{
            id: 'EnergySavingControlDetail'
            }, {
                id: 'Enthalpy',
                chartId: 'chartEnthalpyES'
            },{
                id: 'CO2',
                chartId: 'chartCO2ES'
            },{
                id: 'Set',
                chartId: 'chartSetES'
            }, 
        ],
        multiViewOptions: {
            viewIndex: currentTabIndex,
            viewCount: 1
        }
    });

    var enthalpyOnOff = ko.observable(false);
    var dutyOnOff = ko.observable(false);
    var effiOnOff = ko.observable(false);
    var co2OnOff = ko.observable(false);

    var tempValue = ko.observable(100);

    var m = moment();
    dataCalorie([
        { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
        { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
        { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
        { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
        { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
        { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
        { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
        { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
    ]);
    // 추가 2015 04 20 hcLee ->
    var CODE = $Code,
    FuelType = CODE.FuelType,
    FT = CODE.FacilityType,
    FC = CODE.FacilityCode,
    F = CODE.Formula,
    TIT = CODE.TimeIntervalType;
    // 추가 2015 04 20 hcLee  <-

    //dataMonthForBar(dataDayForBar());

    //dataDayForPie([
    //    { FuelTypeName: '전기', Value: 320 },
    //    { FuelTypeName: '가스', Value: 350 },
    //    { FuelTypeName: '수도', Value: 360 },
    //]);
    //dataMonthForPie(dataDayForPie());

    function handleViewShown() {
        if (initialized === false) {
            var chartOption = BWA.ChartOptions.EnergySavingControl;

            chartEnthalpy = chartEnthalpy(chartOption.getChartControlEnthalpyOptions(timeBoxForSearch.type()));
            chartCO2 = chartCO2(chartOption.getChartControlCO2Options(timeBoxForSearch.type()));
            chartSet = chartSet(chartOption.getChartControlSetOptions(timeBoxForSearch.type()));

            //chartTemperatureCalorie = chartTemperatureCalorie(chartOption.getChartTemperatureCalorieOptions($Code.TimeType.HOUR));
            //chartTemperatureElectricity2 = chartTemperatureElectricity2(chartOption.getTemperatureElectricityOptions(timeBoxForSearch.type()));
            initialized = true;
        }
        var eq = BWA.DataUtil.constructEqualFilter;
        facilityDataSource.filter([
            eq('SiteId', BWA.UserInfo.SiteId()),
            'and',
            eq('FacilityTypeId', $Code.FacilityType.AIR_HANDLING)
        ]);
        facilityDataSource.load().done(function(facilities) {
            facilitiesForSearch(facilities);
            if (_.isEmpty(facilities) === false) {
                var f = facilities[0];
                handleSelectedFacilityInSearchView(f);
                handleSearchInSearchView();

                var datagrid = $('#EnergySavingControlDataGridViewInSearchView').dxDataGrid('instance');
                if (_.has(datagrid, 'selectRows')) {
                    datagrid.selectRows(f);
                }
            }
        });
    }

    if (shouldReload) {
            //shouldReload = false;
            //dataSource.pageIndex(0);
            //dataSource.load();
    }

    function handleViewHidden() {
        var paging = BWA.ChartLayout.Paging;
        paging.sideOverlayVisible(false);
        $SearchView.visibleObservable(false); // hcLee 2015 03 23
        visiblePopup(false);
    }

    function handleViewShowing() {
    }

    function refreshList() {
        //dataSource.pageIndex(0);
        //dataSource.load();
    }

    var searchViewOptions = {
        searchViewItems: [
            { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
        ],
        promiseDataInSearchView: deferredForSearch.promise()
    };

    function handleSelectedFacilityInSearchView(facility) {
        m_Facility = facility;
        return;
    }

    function handleSearchInSearchView(filter, searchViewItems) {
        //console.log(filter);
        //console.log(searchViewItems);
        if (m_Facility == null) return;

        visiblePopup(true);

        var f = m_Facility.toJS();
        facilityViewModel.fromJS(f);

        //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN;
        var timeIntervalType = timeBoxForSearch.type();

        var formula = $Code.Formula[$Code.FacilityType.AIR_HANDLING];
        var formulaIds = _.values(formula);

        var date = timeBoxForSearch.getDate();

        //utils.toast.displayTime=1000000;
        //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
        //        var startDate = moment().
        var promises = [];
        _.each(formulaIds, function (formulaId) {
            var p = formulaGet.apiGet({
                FacilityTypeId: f.FacilityTypeId,
                FacilityCode: f.FacilityCode,
                FormulaId: formulaId,

                TimeIntervalType: timeIntervalType,
                StartDate: date.startDate,
                EndDate: date.endDate
            });
            promises.push(p);
        });

        // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20  ->
        var commonParameters = {
            //TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
            TimeIntervalType: timeIntervalType,
            StartDate: date.startDate,
            EndDate: date.endDate
        };
        var temperatureParameters = {
            FacilityTypeId: FT.OUTDOOR,
            FacilityCode: FC.OUTDOOR,
            FormulaId: F[FT.OUTDOOR].TEMPERATURE,
        };
        var humidityParameters = _.extend({}, temperatureParameters, {
            FormulaId: F[FT.OUTDOOR].HUMIDITY,
        });
        promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
        promises.push(formulaGet.apiGet(_.extend(humidityParameters, commonParameters)));
        // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20  <-
        //promises.push(utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요'));
        $.when.apply(this, promises)
        .done(function (coldWaterCalories, hotWaterCalories, coldWaterAtfws,
            hotWaterAtfws, in_temperatures, out_temperatures, cold_electricities, hot_electricities,
            cold_vopen, hot_vopen,
            cold_in_temperatures, cold_out_temperatures, // 이 2개는 2015 06 15일 추가
            
            f_temp, f_humi, // 2015 07 10 추가
            co2, // 2015 07 10 추가
            enthalpyOnoff, dutyOnoff, effiOnoff, co2Onoff, tempset,
            //2016 03 최종추가
            A21,A22,A23,A24,A25,A26,
            OUTtemperatures, OUThumidities) {

            if (enthalpyOnoff[0].length > 0)
                enthalpyOnOff(enthalpyOnoff[0][enthalpyOnoff[0].length - 1].Value == 0 ? false : true);
            else
                enthalpyOnOff(false);

            if (dutyOnoff[0].length > 0)
                dutyOnOff(dutyOnoff[0][dutyOnoff[0].length - 1].Value == 0 ? false : true);
            else
                dutyOnOff(false);

            if (effiOnoff[0].length > 0)
                effiOnOff(effiOnoff[0][effiOnoff[0].length - 1].Value == 0 ? false : true);
            else
                effiOnOff(false);

            if (co2Onoff[0].length > 0)
                co2OnOff(co2Onoff[0][co2Onoff[0].length - 1].Value == 0 ? false : true);
            else
                co2OnOff(false);

            tempValue(tempset[0].length == 0 ? 0 : tempset[0][tempset[0].length - 1].Value);

            var dataArray = [];
            for (var i = 0; i < OUTtemperatures[0].length; i++) {
                dataArray.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(OUTtemperatures[0][i].DateTime).toDate()),
                    enthalpy: BWA.Bems.refinegetENTHALPY(OUTtemperatures[0][i].Value, OUThumidities[0][i].Value / 100)
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }
            for (var i = 0; i < f_temp[0].length; i++) {
                dataArray.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(f_temp[0][i].DateTime).toDate()),
                    f_enthalpy: BWA.Bems.refinegetENTHALPY(f_temp[0][i].Value, f_humi[0][i].Value / 100)
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }
            var options = BWA.ChartOptions.EnergySavingControl.getChartControlEnthalpyOptions(timeBoxForSearch.type());
            options.dataSource = dataArray;
            chartEnthalpy().option(options);


            var dataCO2 = [];
            for (var i = 0; i < co2[0].length; i++) {
                dataCO2.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(co2[0][i].DateTime).toDate()),
                    co2: co2[0][i].Value
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }

            options = BWA.ChartOptions.EnergySavingControl.getChartControlCO2Options(timeBoxForSearch.type());
            options.dataSource = dataCO2;
            chartCO2().option(options);

            var dataTH = [];
            for (var i = 0; i < f_temp[0].length; i++) {
                dataTH.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(f_temp[0][i].DateTime).toDate()),
                    temp: f_temp[0][i].Value
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }
            for (var i = 0; i < f_humi[0].length; i++) {
                dataTH.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(f_humi[0][i].DateTime).toDate()),
                    humi: f_humi[0][i].Value
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }
            for (var i = 0; i < OUTtemperatures[0].length; i++) {
                dataTH.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(OUTtemperatures[0][i].DateTime).toDate()),
                    out_temp : OUTtemperatures[0][i].Value
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }
            for (var i = 0; i < OUThumidities[0].length; i++) {
                dataTH.push({
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(OUThumidities[0][i].DateTime).toDate()),
                    out_humi: OUThumidities[0][i].Value
                    //enthalpy: getENTHALPY(humi[i].Value / 100, temp[i].Value)
                });
            }

            options = BWA.ChartOptions.EnergySavingControl.getChartControlSetOptions(timeBoxForSearch.type());
            options.dataSource = dataTH;
            chartSet().option(options);

/*
            coldWaterCalories = coldWaterCalories[0];
            hotWaterCalories = hotWaterCalories[0];
            coldWaterAtfws = coldWaterAtfws[0];
            hotWaterAtfws = hotWaterAtfws[0];
            in_temperatures = in_temperatures[0];
            out_temperatures = out_temperatures[0];
            cold_electricities = cold_electricities[0];
            hot_electricities = hot_electricities[0];
            cold_vopen = cold_vopen[0];
            hot_vopen = hot_vopen[0];
            cold_in_temperatures = cold_in_temperatures[0];
            cold_out_temperatures = cold_out_temperatures[0];

            OUTtemperatures = OUTtemperatures[0];

            BWA.Chart.mapWithConvertingDateTime(coldWaterCalories, timeBoxForSearch.type());
            BWA.Chart.mapWithConvertingDateTime(hotWaterCalories, timeBoxForSearch.type());
            //BWA.Chart.mapWithConvertingDateTime(coldWaterAtfws);                     
            //BWA.Chart.mapWithConvertingDateTime(hotWaterAtfws);                     
            BWA.Chart.mapWithConvertingDateTime(OUTtemperatures, timeBoxForSearch.type());

            var coldWaterCalorieDataArray = _.map(coldWaterCalories, function (x) {
                return {
                    DateTime: x.DateTime,
                    //DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), x.DateTime),
                    CV: x.Value
                };
            })
            _.each(cold_in_temperatures, function (x) {
                coldWaterCalorieDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    cold_in_temp: x.Value
                });
            });
            _.each(cold_out_temperatures, function (x) {
                coldWaterCalorieDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    cold_out_temp: x.Value
                });
            });
            var options = BWA.ChartOptions.WaterCoolingAnalysis.getChartCalorieCOptions(timeBoxForSearch.type());
            //chartCalorie().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
            options.dataSource = coldWaterCalorieDataArray;
            chartCalorieC().option(options);


            // chart 2
            var hotWaterCalorieDataArray = _.map(hotWaterCalories, function (x) {
                return {
                    DateTime: x.DateTime,
                    //DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), x.DateTime),
                    HV: x.Value
                };
            })
            //var calories = coldWaterCalorieDataArray.concat(hotWaterCalorieDataArray);
            _.each(in_temperatures, function (x) {
                hotWaterCalorieDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    in_temp: x.Value
                });
            });
            _.each(out_temperatures, function (x) {
                hotWaterCalorieDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    out_temp: x.Value
                });
            });
            //var chartOption = BWA.ChartOptions.WaterCoolingAnalysis;
            //chartOption.getChartCalorieOptions(timeBoxForSearch.type());
            //chartCalorie().option.getChartCalorieOptions(timeBoxForSearch.type())
            var options = BWA.ChartOptions.WaterCoolingAnalysis.getChartCalorieHOptions(timeBoxForSearch.type());
            //chartCalorie().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
            options.dataSource = hotWaterCalorieDataArray;
            chartCalorieH().option(options);

            // chart 2
            var atfwDataArray = [];
            var maxValueCHV = 0;
            _.map(coldWaterAtfws, function (x) {
                atfwDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    CV: x.Value
                });
                if (maxValueCHV < x.Value) maxValueCHV = x.Value;
            })
            _.map(hotWaterAtfws, function (x) {
                atfwDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    HV: x.Value
                });
                if (maxValueCHV < x.Value) maxValueCHV = x.Value;
            })
            options = BWA.ChartOptions.WaterCoolingAnalysis.getChartAtfwOptions(timeBoxForSearch.type());
            //chartAtfw().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
            //maxValueCHV = 30;
            options.valueAxis[0].tickInterval = Math.round(Math.round(maxValueCHV) / 5) + 1;
            options.dataSource = atfwDataArray.concat(OUTtemperatures);
            chartAtfw().option(options); // 냉난방ATF와 외기온도관계


            //chart3
            //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
            //BWA.Chart.mapWithConvertingDateTime(cold_vopen);
            //BWA.Chart.mapWithConvertingDateTime(hot_vopen);
            var vopenDataArray = [];
            maxValueCHV = 0;
            _.map(cold_vopen, function (x) {
                vopenDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    CV: x.Value
                });
                if (maxValueCHV < x.Value) maxValueCHV = x.Value;
            })
            _.map(hot_vopen, function (x) {
                vopenDataArray.push({
                    //DateTime: moment(x.DateTime).toDate(),
                    DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
                    HV: x.Value
                });
                if (maxValueCHV < x.Value) maxValueCHV = x.Value;
            })
            options = BWA.ChartOptions.WaterCoolingAnalysis.getChartVOpenOptions(timeBoxForSearch.type());
            options.valueAxis[0].tickInterval = Math.round(maxValueCHV / 5) + 1;
            //chartVOpen().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
            options.dataSource = vopenDataArray.concat(OUTtemperatures);
            chartVOpen().option(options); // 냉난방ATF와 외기온도관계

*/
            visiblePopup(false);
        })
        .fail(function (error) {
            //alert(error);
            visiblePopup(false);
        });

    }


    var viewModel = $.extend(BWA.CommonView.create(
            params, viewInfo, searchViewOptions, ko.observable(null),
            handleViewShown, null, handleSearchInSearchView, undefined,
            chartLayout), {

                //        facility: facilityViewModel,
        viewHidden: handleViewHidden, // hcLee 2015 06 03
        refreshList: refreshList,
        viewShowing: handleViewShowing,
        scrolling: { mode: 'infinite' },
        EnergySavingControlDataGridOptions : {
            dataSource: facilitiesForSearch,
            columns: [
                { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
            ],
            filterRow: {
                visible: true,
                showOperationChooser: false
            },
            selection: {
                mode: 'single'
            },
            rowClick: function(clickRow) {
                handleSelectedFacilityInSearchView(clickRow.data);
            }
        },
        contentReadyAction: function(e) {
            datagrid = e.component;
        }
    });


    viewModel.timeBoxForSearch = timeBoxForSearch;
    viewModel.currentTabIndex = currentTabIndex;
    viewModel.multiViewItems = [{
            facility: facilityViewModel,
            template: 'mainCharts',

            enthalpyOnOff: enthalpyOnOff,
            dutyOnOff: dutyOnOff,
            effiOnOff: effiOnOff,
            co2OnOff: co2OnOff,
            tempValue: tempValue,

            setEnthalpyOnOff: function () {
                //alert(enthalpyOnOff());
                var f = m_Facility.toJS();
                var param = {
                    SiteId: BWA.UserInfo.SiteId(),
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].ENTHALPY_ONOFF,
                    ControlValue: enthalpyOnOff() ? 1 : 0,
                };
                BWA.api.post('BemsFormula/ControlPoint', null, param).done(function () {
                    utils.toast.show('엔탈피제어 완료');
                });

            },

            setDutyOnOff: function () {
                //alert(dutyOnOff());
                var f = m_Facility.toJS();
                var param = {
                    SiteId: BWA.UserInfo.SiteId(),
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].DUTYCYCLE_ONOFF,
                    ControlValue: dutyOnOff() ? 1 : 0,
                };
                BWA.api.post('BemsFormula/ControlPoint', null, param).done(function () {
                    utils.toast.show('절전제어 완료');
                });

            },

            setEffiOnOff: function () {
                var f = m_Facility.toJS();
                var param = {
                    SiteId: BWA.UserInfo.SiteId(),
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].EFFI_ONOFF,
                    ControlValue: effiOnOff() ? 1 : 0,
                };
                BWA.api.post('BemsFormula/ControlPoint', null, param).done(function () {
                    utils.toast.show('효율제어 완료');
                });
            },

            setCO2OnOff: function () {
                var f = m_Facility.toJS();
                var param = {
                    SiteId: BWA.UserInfo.SiteId(),
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].CO2_ONOFF,
                    ControlValue: co2OnOff() ? 1 : 0,
                };
                BWA.api.post('BemsFormula/ControlPoint', null, param).done(function () {
                    utils.toast.show('CO2제어 완료');
                });

            },

            setTempValue: function () {
                var f = m_Facility.toJS();
                /*
                var p = controlPoint.apiGet({
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    //FormulaId: $Code.FacilityType.AIR_HANDLING.TEMP_SET,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].TEMP_SET,
                    ControlValue: tempValue(),
                });
                promises.push(p);
                $.when.apply(this, promises)
                .done(function () {
                    alert(tempValue());
                })
                .fail(function (error) {
                    //visiblePopup(false);
                    alert('fail');
                });*/
                var param = {
                    SiteId:BWA.UserInfo.SiteId(),
                    FacilityTypeId: f.FacilityTypeId, // 이게 문제다....
                    FacilityCode: f.FacilityCode,
                    FormulaId: $Code.Formula[$Code.FacilityType.AIR_HANDLING].TEMP_SET,
                    ControlValue: tempValue(),
                };
                BWA.api.post('BemsFormula/ControlPoint', null, param).done(function () {
                    utils.toast.show('온도제어 완료');
                });

            }
        },
        {
            template: 'subCharts'
        }
    ];

    $HourGlassPopup(viewModel, visiblePopup);

    return viewModel;
};