| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 | $(function() {    'use strict';    var searchView = BWA.SearchView = BWA.SearchView || {};    var day = 'day',        days = 'days',        month = 'month',        months = 'months',        year = 'year',        years = 'years';    // hcLee 2016 04 04    function dateBySubtract2(date, number, unit) {        return moment(date).subtract(number, unit).toDate();    }    function dateBySubtract(number, unit) {        return moment().subtract(number, unit).toDate();    }    function dateStartOf(unit) {        return moment().startOf(unit).toDate();    }    // hcLee 2016 04 04    function dateStartOf2(date, unit) {        return moment(date).startOf(unit).toDate();    }    function now() {        return new Date();    }    function HourBox() {        this.startDate = ko.observable();        this.startTime = ko.observable();        this.endDate = ko.observable();        this.endTime = ko.observable();        /*        this.startDate = new Date();        this.startTime = new Date();        this.endDate = new Date();        this.endTime = new Date();*/        this.timeChange = function () {            alert('1');        }.bind(this);        this.set24hours = function () {            //this.startDate(dateBySubtract(1, days));            this.startDate(dateBySubtract2(this.endDate(), 1, days));            this.startTime(this.endTime());            //this.endDate();            //this.endTime();        }.bind(this);        this.set3days = function() {            //this.startDate(dateBySubtract(3, days));            this.startDate(dateBySubtract2(this.endDate(), 3, days));            //this.startTime(now());            this.startTime(dateStartOf(day));            //this.endDate(now());            //this.endTime(now());        }.bind(this);        this.setToday = function() {            this.startDate(now());            this.startTime(dateStartOf(day));            this.endDate(now());            this.endTime(now());        }.bind(this);        this.getStartDate = function () {            /*this.startDate(BWA.DataUtil.getDateTimeZeroMin(                this.startDate(),                this.startTime()));*/            this.startTime(BWA.DataUtil.getDateTimeZeroMin(  //getDateTimeZeroSecond                this.startDate(),                this.startTime()));            return BWA.DataUtil.getDateTimeFromDateAndTime(this.startDate(), this.startTime());/*            return BWA.DataUtil.getDateTimeZeroMin(                this.startDate(),                this.startTime());*/        }.bind(this);        this.getEndDate = function () {/*            this.endTime(BWA.DataUtil.getDateTimeZeroMin(                this.endDate(),                this.endTime()));            return BWA.DataUtil.getDateTimeFromDateAndTime(                this.endDate(),                this.endTime()); */            this.endTime(BWA.DataUtil.getDateTimeZeroMin(                this.endDate(),                this.endTime()));            return BWA.DataUtil.getDateTimeFromDateAndTime(this.endDate(), this.endTime());        }.bind(this);        this.setToday();    }    function HourBox1() {        this.startDate = ko.observable();        this.startTime = ko.observable();        this.endDate = ko.observable();        this.endTime = ko.observable();        /*        this.startDate = new Date();        this.startTime = new Date();        this.endDate = new Date();        this.endTime = new Date();*/        this.timeChange = function () {            alert('1');        }.bind(this);        this.set24hours = function () {            //this.startDate(dateBySubtract(1, days));            this.startDate(dateBySubtract2(this.endDate(), 1, days));            this.startTime(this.endTime());            //this.endDate();            //this.endTime();        }.bind(this);        this.set3days = function () {            //this.startDate(dateBySubtract(3, days));            this.startDate(dateBySubtract2(this.endDate(), 3, days));            //this.startTime(now());            this.startTime(dateStartOf(day));            //this.endDate(now());            //this.endTime(now());        }.bind(this);        this.setToday = function () {            this.startDate(now());            this.startTime(dateStartOf(day));            this.endDate(now());            this.endTime(now());        }.bind(this);        this.getStartDate = function () {            /*this.startDate(BWA.DataUtil.getDateTimeZeroMin(                this.startDate(),                this.startTime()));*/            this.startTime(BWA.DataUtil.getDateTimeZeroSecond(  //getDateTimeZeroSecond                this.startDate(),                this.startTime()));            return BWA.DataUtil.getDateTimeFromDateAndTime(this.startDate(), this.startTime());            /*                        return BWA.DataUtil.getDateTimeZeroMin(                            this.startDate(),                            this.startTime());*/        }.bind(this);        this.getEndDate = function () {            /*                        this.endTime(BWA.DataUtil.getDateTimeZeroMin(                            this.endDate(),                            this.endTime()));                                    return BWA.DataUtil.getDateTimeFromDateAndTime(                            this.endDate(),                            this.endTime()); */            this.endTime(BWA.DataUtil.getDateTimeZeroSecond(                this.endDate(),                this.endTime()));            return BWA.DataUtil.getDateTimeFromDateAndTime(this.endDate(), this.endTime());        }.bind(this);        this.setToday();    }    function DayBox() {        this.startDate = ko.observable();        this.endDate = ko.observable();        this.set3days = function() {            //this.startDate(dateBySubtract(3, days));            this.startDate(dateBySubtract2(this.endDate(), 3, days));            this.endDate(now());        }.bind(this);        this.set1week = function() {            //this.startDate(dateBySubtract(7, days));            this.startDate(dateBySubtract2(this.endDate(), 7, days));            //this.endDate(now());        }.bind(this);        this.set1month = function() {            //this.startDate(dateBySubtract(1, months));            this.startDate(dateBySubtract2(this.endDate(), 1, months));            //this.endDate(now());        }.bind(this);        this.setThisMonth = function() {            this.startDate(dateStartOf(month));            //this.startTime(dateStartOf(day)); // hcLee            this.endDate(now());        }.bind(this);        this.getStartDate = function () {            this.startDate(BWA.DataUtil.getDateTimeZeroHour(this.startDate()));            return this.startDate();            //return BWA.DataUtil.getDateTimeZeroHour(this.startDate());        }.bind(this);        this.getEndDate = function () {            this.endDate(BWA.DataUtil.getDateTimeMaxHour(this.endDate()));            return this.endDate();        }.bind(this);        this.setThisMonth();    }    function MonthBox(startthisyear) {        this.startDate = ko.observable();        this.endDate = ko.observable();        this.set3months = function() {            //this.startDate(dateBySubtract(2, months));            this.startDate(dateBySubtract2(this.endDate(), 2, months));            //this.endDate(now());        }.bind(this);        this.set6months = function() {            //this.startDate(dateBySubtract(5, months));            this.startDate(dateBySubtract2(this.endDate(), 5, months));            //this.endDate(now());        }.bind(this);        this.set1year = function() {            //this.startDate(dateBySubtract(11, months));            this.startDate(dateBySubtract2(this.endDate(), 11, months));            this.endDate(now());        }.bind(this);        this.setThisYear = function() {            this.startDate(dateStartOf(year));            this.endDate(now());        }.bind(this);        this.getStartDate = function() {            //return this.startDate();            this.startDate(BWA.DataUtil.getDateTimeStartDay(this.startDate()));            return this.startDate();        }.bind(this);        this.getEndDate = function () {            this.endDate(BWA.DataUtil.getDateTimeEndDay(this.endDate()));            return this.endDate();        }.bind(this);                if (startthisyear == null)            this.set1year(); // hcLee 2016 02 26 월별 조회가 기본인 화면들을 위하여 스타트 검색조건을 최근12개월로 변경한다.        else            this.setThisYear(); // // hcLee 2016 04 26 가동시간 비용 속도문제때문에    }    function YearBox() {        this.startYear = ko.observable();        this.endYear = ko.observable();        this.set3years = function() {            this.startYear(dateBySubtract(3, years).getFullYear());            this.endYear(now().getFullYear());        }.bind(this);        this.set5years = function() {            this.startYear(dateBySubtract(5, years).getFullYear());            this.endYear(now().getFullYear());        }.bind(this);        this.set10years = function() {            this.startYear(dateBySubtract(10, years).getFullYear());            this.endYear(now().getFullYear());        }.bind(this);        this.getStartDate = function() {            var year = this.startYear();            return moment([year, 1, 1]).toDate();        }.bind(this);        this.getEndDate = function() {            var year = this.startEnd();            return moment([year, 1, 1]).toDate();        }.bind(this);        this.set3years();    }    var HOUR = $Code.TimeType.HOUR;    var DAY = $Code.TimeType.DAY;    var MONTH = $Code.TimeType.MONTH;    var YEAR = $Code.TimeType.YEAR;    // cyim 2016.08.22 : 생성자에 읽기전용인지 구분자 포함    searchView.createDateTimeBox = function(dataSource, startthisyear, readonly) {        var type = ko.observable();        var isHour = ko.observable();        var isDay = ko.observable();        var isMonth = ko.observable();        var isYear = ko.observable();        var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다        type.subscribe(function(type) {            isHour(type === HOUR);            isDay(type === DAY);            isMonth(type === MONTH);            isYear(type === YEAR);        });        // type(HOUR); 원래코드         // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여        if (dataSource == null)            type(HOUR);        else type(dataSource[0].TimeTypeId);        var dateTimeBox = {            type: type,            typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25            //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25            isHour: isHour,            isDay: isDay,            isMonth: isMonth,            isYear: isYear,            isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다            hour: new HourBox(),            day: new DayBox(),            month: new MonthBox(startthisyear),            year: new YearBox(),        };        //2016 07 21 hcLee        dateTimeBox.setDefaultDate = function () {            type(HOUR);            this.hour.endTime(now());            this.hour.set24hours();        },        dateTimeBox.getDate = function() {            var timeObject = null;            switch (this.type()) {                case HOUR:                    timeObject = this.hour;                    break;                case DAY:                    timeObject = this.day;                    break;                case MONTH:                    timeObject = this.month;                    break;                case YEAR:                    timeObject = this.year;                    break;            }                        return {                startDate: timeObject.getStartDate(),                endDate: timeObject.getEndDate()            };        }.bind(dateTimeBox);        return dateTimeBox;    }    searchView.createDateTimeBox1 = function (dataSource, startthisyear, readonly) {        var type = ko.observable();        var isHour = ko.observable();        var isDay = ko.observable();        var isMonth = ko.observable();        var isYear = ko.observable();        var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다        type.subscribe(function (type) {            isHour(type === HOUR);            isDay(type === DAY);            isMonth(type === MONTH);            isYear(type === YEAR);        });        // type(HOUR); 원래코드         // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여        if (dataSource == null)            type(HOUR);        else type(dataSource[0].TimeTypeId);        var dateTimeBox = {            type: type,            typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25            //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25            isHour: isHour,            isDay: isDay,            isMonth: isMonth,            isYear: isYear,            isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다            hour: new HourBox1(),            day: new DayBox(),            month: new MonthBox(startthisyear),            year: new YearBox(),        };        //2016 07 21 hcLee        dateTimeBox.setDefaultDate = function () {            type(HOUR);            this.hour.endTime(now());            this.hour.set24hours();        },        dateTimeBox.getDate = function () {            var timeObject = null;            switch (this.type()) {                case HOUR:                    timeObject = this.hour;                    break;                case DAY:                    timeObject = this.day;                    break;                case MONTH:                    timeObject = this.month;                    break;                case YEAR:                    timeObject = this.year;                    break;            }            return {                startDate: timeObject.getStartDate(),                endDate: timeObject.getEndDate()            };        }.bind(dateTimeBox);        return dateTimeBox;    }});
 |