123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- $(function() {
- 'use strict';
- var searchView = BWA.SearchView = BWA.SearchView || {};
- var day = 'day',
- days = 'days',
- month = 'month',
- months = 'months',
- year = 'year',
- years = 'years';
-
- 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();
- }
-
- 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.timeChange = function () {
- alert('1');
- }.bind(this);
- this.set24hours = function () {
-
- this.startDate(dateBySubtract2(this.endDate(), 1, days));
- this.startTime(this.endTime());
-
-
- }.bind(this);
- this.set3days = function() {
-
- this.startDate(dateBySubtract2(this.endDate(), 3, days));
-
- this.startTime(dateStartOf(day));
-
-
- }.bind(this);
- this.setToday = function() {
- this.startDate(now());
- this.startTime(dateStartOf(day));
- this.endDate(now());
- this.endTime(now());
- }.bind(this);
- this.getStartDate = function () {
-
- this.startTime(BWA.DataUtil.getDateTimeZeroMin(
- this.startDate(),
- this.startTime()));
- return BWA.DataUtil.getDateTimeFromDateAndTime(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());
- }.bind(this);
- this.setToday();
- }
- function HourBox1() {
- this.startDate = ko.observable();
- this.startTime = ko.observable();
- this.endDate = ko.observable();
- this.endTime = ko.observable();
-
- this.timeChange = function () {
- alert('1');
- }.bind(this);
- this.set24hours = function () {
-
- this.startDate(dateBySubtract2(this.endDate(), 1, days));
- this.startTime(this.endTime());
-
-
- }.bind(this);
- this.set3days = function () {
-
- this.startDate(dateBySubtract2(this.endDate(), 3, days));
-
- this.startTime(dateStartOf(day));
-
-
- }.bind(this);
- this.setToday = function () {
- this.startDate(now());
- this.startTime(dateStartOf(day));
- this.endDate(now());
- this.endTime(now());
- }.bind(this);
- this.getStartDate = function () {
-
- this.startTime(BWA.DataUtil.getDateTimeZeroSecond(
- this.startDate(),
- this.startTime()));
- return BWA.DataUtil.getDateTimeFromDateAndTime(this.startDate(), this.startTime());
-
- }.bind(this);
- this.getEndDate = function () {
-
- 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.setToday = function () {
- this.startDate(now());
- this.endDate(now());
- }.bind(this);
- this.set3days = function() {
-
- this.startDate(dateBySubtract2(this.endDate(), 3, days));
- this.endDate(now());
- }.bind(this);
- this.set1week = function() {
-
- this.startDate(dateBySubtract2(this.endDate(), 7, days));
-
- }.bind(this);
- this.set1month = function() {
-
- this.startDate(dateBySubtract2(this.endDate(), 1, months));
-
- }.bind(this);
- this.setThisMonth = function() {
- this.startDate(dateStartOf(month));
-
- this.endDate(now());
- }.bind(this);
- this.getStartDate = function () {
- this.startDate(BWA.DataUtil.getDateTimeZeroHour(this.startDate()));
- return 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(dateBySubtract2(this.endDate(), 2, months));
-
- }.bind(this);
- this.set6months = function() {
-
- this.startDate(dateBySubtract2(this.endDate(), 5, months));
-
- }.bind(this);
- this.set1year = function() {
-
- 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() {
-
- 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();
- else
- this.setThisYear();
- }
- 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;
-
- 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);
- type.subscribe(function(type) {
- isHour(type === HOUR);
- isDay(type === DAY);
- isMonth(type === MONTH);
- isYear(type === YEAR);
- });
-
-
- if (dataSource == null)
- type(HOUR);
- else type(dataSource[0].TimeTypeId);
- var dateTimeBox = {
- type: type,
- typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource,
-
- isHour: isHour,
- isDay: isDay,
- isMonth: isMonth,
- isYear: isYear,
- isReadOnly: readonly,
- hour: new HourBox(),
- day: new DayBox(),
- month: new MonthBox(startthisyear),
- year: new YearBox(),
- };
-
- dateTimeBox.setDefaultDate = function () {
- type(HOUR);
- this.hour.endTime(now());
- this.hour.set24hours();
- },
-
- dateTimeBox.setDefaultDateToday = function () {
- type(DAY);
- this.day.setToday();
- },
-
- 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);
- type.subscribe(function (type) {
- isHour(type === HOUR);
- isDay(type === DAY);
- isMonth(type === MONTH);
- isYear(type === YEAR);
- });
-
-
- if (dataSource == null)
- type(HOUR);
- else type(dataSource[0].TimeTypeId);
- var dateTimeBox = {
- type: type,
- typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource,
-
- isHour: isHour,
- isDay: isDay,
- isMonth: isMonth,
- isYear: isYear,
- isReadOnly: readonly,
- hour: new HourBox1(),
- day: new DayBox(),
- month: new MonthBox(startthisyear),
- year: new YearBox(),
- };
-
- 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;
- }
- });
|