123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../lib/@waca/core-client/js/core-client/ui/AccessibleView', 'underscore', 'app/nls/StringResources', 'text!./templates/BasePromptView.html', 'text!./templates/DateTimePromptContent.html', '../../lib/@waca/core-client/js/core-client/ui/widgets/DatePicker', '../../lib/@waca/core-client/js/core-client/ui/widgets/TimePicker', 'moment-timezone', 'doT'], function (View, _, stringResources, BasePromptViewTemplate, DateTimePromptContentTemplate, DatePicker, TimePicker, moment, dot) {
- 'use strict';
- var DateTimePromptView = View.extend({
- DATE_TIME_FORMAT: 'YYYY-MM-DDTHH:mm:ss',
- _iHeight: '212',
- startDate: null,
- endDate: null,
- startTime: null,
- endTime: null,
- timezone: null,
- /**
- * @classdesc Date, Time, DateTime prompt view class.
- * @public
- *
- * @param {String} options.columnId - The prompt item column ID.
- * @param {String} options.name - The parameter name.
- * @param {String} options.dataType -The parameter data type.
- * @param {Object} options.capabilities -The capabilities of the prompt.
- * @param {String} options.timezone -The timezone in user preferences.
- */
- init: function init(options) {
- DateTimePromptView.inherited('init', this, arguments);
- _.extend(this, options);
- this._isRangePrompt = options.capabilities.multivalued && !options.capabilities.discreteValue;
- if (options.timezone) {
- this.timezone = options.timezone;
- } else {
- this.timezone = 'America/New_York';
- }
- },
- render: function render() {
- var sBasePromptViewHtml = dot.template(BasePromptViewTemplate)({
- promptModuleName: this.promptModuleName
- });
- this.$el.addClass('popoverDialogContainer promptViewDialog').height(this._iHeight + 'px').width(this._iWidth + 'px').append(sBasePromptViewHtml);
- this.$el.attr('role', 'region');
- this.$el.attr('aria-label', this.viewTitle);
- var dateTitle = stringResources.get('dateTitle');
- var timeTitle = stringResources.get('timeTitle');
- var sPromptContentHtml = dot.template(DateTimePromptContentTemplate)({
- dataType: this.dataType,
- //title: stringResources.get('dateTimeFilterMessage'), //stringResourecs.get('promptControlTitle');
- isRangePrompt: this._isRangePrompt
- });
- this.$('.content').append(sPromptContentHtml);
- return new Promise(function (resolve) {
- switch (this.dataType) {
- case 'xsdDate':
- this._renderDate().then(function () {
- this.$el.find('.dateTitle').text(dateTitle);
- resolve(this);
- }.bind(this));
- break;
- case 'xsdDateTime':
- this._renderDateTime().then(function () {
- this.$el.find('.dateTitle').text(dateTitle);
- this.$el.find('.timeTitle').text(timeTitle);
- resolve(this);
- }.bind(this));
- break;
- case 'xsdTime':
- this._renderTime().then(function () {
- this.$el.find('.timeTitle').text(timeTitle);
- resolve(this);
- }.bind(this));
- break;
- default:
- resolve(this);
- break;
- }
- }.bind(this));
- },
- _getDateTimes: function _getDateTimes() {
- var dates = [];
- if (this.defaultValues) {
- var momentTime = moment.tz(this.defaultValues[0].d, this.DATE_TIME_FORMAT, this.timezone);
- dates.push(momentTime.toDate());
- if (this.defaultValues.length > 1) {
- var momentTime1 = moment.tz(this.defaultValues[1].d, this.DATE_TIME_FORMAT, this.timezone);
- dates.push(momentTime1.toDate());
- }
- } else {
- var currentdate = new Date();
- dates = [currentdate, currentdate];
- }
- return dates;
- },
- _renderDate: function _renderDate() {
- var dates = this._getDateTimes();
- this.$el.find('.dateContainer').css('display', 'inline-flex');
- this.startDate = new DatePicker({
- '$el': this.$el.find('.dateRowStart'),
- 'labelText': '',
- 'ariaLabelText': stringResources.get('dateTitle'),
- 'timezone': this.timezone,
- 'attributes': {
- 'firstDay': 1,
- 'defaultDate': dates[0],
- 'inputFieldDate': dates[0]
- },
- 'setOnSelect': true,
- 'setDiv': this.$el
- });
- var datePickers = [];
- datePickers.push(this.startDate.render());
- if (this._isRangePrompt) {
- this.endDate = new DatePicker({
- '$el': this.$el.find('.dateRowEnd'),
- 'labelText': '',
- 'ariaLabelText': stringResources.get('dateTitle'),
- 'timezone': this.timezone,
- 'attributes': {
- 'firstDay': 1,
- 'defaultDate': dates[1],
- 'inputFieldDate': dates[1]
- },
- 'setOnSelect': false,
- 'setDiv': this.$el
- });
- datePickers.push(this.endDate.render());
- }
- return Promise.all(datePickers);
- },
- _renderTime: function _renderTime() {
- this.$el.find('.timeContainer').css('display', 'inline-flex');
- var times = this._getDateTimes();
- var timepickers = [];
- this.startTime = new TimePicker({
- '$el': this.$el.find('.timeRowStart'),
- 'timezone': this.timezone,
- 'ariaLabel': stringResources.get('timeTitle'),
- 'setDiv': this.$el,
- 'attributes': {
- 'minuteStep': 1,
- 'showMeridian': true,
- 'defaultTime': times[0]
- }
- });
- timepickers.push(this.startTime.render());
- if (this._isRangePrompt) {
- this.endTime = new TimePicker({
- '$el': this.$el.find('.timeRowEnd'),
- 'timezone': this.timezone,
- 'ariaLabel': stringResources.get('timeTitle'),
- 'setDiv': this.$el,
- 'attributes': {
- 'minuteStep': 1,
- 'showMeridian': true,
- 'defaultTime': times[1]
- }
- });
- timepickers.push(this.endTime.render());
- }
- return Promise.all(timepickers);
- },
- _renderDateTime: function _renderDateTime() {
- return this._renderDate().then(this._renderTime.bind(this)).then(function () {
- this.$el.find('.timeContainer').css('display', 'inline-flex');
- this.$el.find('.dateContainer').css('display', 'inline-flex');
- this._iWidth = 500;
- this.$el.width(this._iWidth + 'px');
- this.$el.find('.flexFifty').css('flex', '2 33%');
- }.bind(this));
- },
- setFocus: function setFocus() {
- var element = this.startDate ? this.startDate.$el.find('input') : this.startTime.$el.find('input');
- element.focus();
- },
- /**
- * @public
- * Get prompt values from dialog.
- *
- */
- getPromptValues: function getPromptValues() {
- var values;
- switch (this.dataType) {
- case 'xsdDate':
- values = this._getDateValues();
- break;
- case 'xsdDateTime':
- values = [];
- var timeValues = this._getTimeValues();
- var dateValues = this._getDateValues();
- for (var i = 0; i < dateValues.length; i++) {
- values.push(dateValues[i] + 'T' + timeValues[i]);
- }
- break;
- case 'xsdTime':
- values = this._getTimeValues();
- break;
- default:
- break;
- }
- return values;
- },
- _getDateValues: function _getDateValues() {
- var values = [];
- if (this.startDate.isValidDate()) {
- values.push(this.startDate.getDateVal());
- }
- if (this._isRangePrompt && this.endDate.isValidDate()) {
- values.push(this.endDate.getDateVal());
- }
- return values;
- },
- _getTimeValues: function _getTimeValues() {
- var values = [];
- if (this.startTime.isValidTime()) {
- values.push(this.startTime.getTime24HShort());
- }
- if (this._isRangePrompt && this.endTime.isValidTime()) {
- values.push(this.endTime.getTime24HShort());
- }
- return values;
- }
- });
- return DateTimePromptView;
- });
- //# sourceMappingURL=DateTimePromptView.js.map
|