123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * (C) Copyright IBM Corp. 2015, 2017
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'bi/schedule/views/CadencePickerView',
- 'bi/schedule/app/appControler',
- 'jquery',
- 'bi/sharecommon/utils/translator',
- 'q',
- 'bi/sharecommon/utils/simpledoT',
- 'text!bi/schedule/templates/DailyCadencePicker.html',
- 'underscore',
- "bi/schedule/views/DailyIntervalCadencePickerView",
- 'bi/commons/ui/properties/DropDown'
- ],
- function (View, controler, $, t, Q, dot, template, _, DailyIntervalCadencePicker, DropDownMenu) {
- 'use strict';
- var dailyCadence = View.extend({
- isEditMode: false,
- /**
- * @constructor
- */
- init: function(options) {
- dailyCadence.inherited('init', this, arguments);
- _.extend(this, options);
- if(typeof(this.objectInformation.descriptor)!=="undefined"){
- this.scheduleInfo = this.objectInformation.descriptor.scheduleInfo;
- this.isEditMode = true;
- }
-
- this.uniqueId = _.uniqueId();
- this.dayFrequencySelector = null;
- this.readOnly = false;
- },
- /**
- * Render the new schedule view month picker section
- *
- */
- render: function() {
- var deferred = Q.defer();
- var htmlGenerator = dot.simpleTemplate(template);
- var defaultPeriod = 1;
- if (this.isEditMode && this.scheduleInfo.everyNPeriods > 1) {
- defaultPeriod = this.scheduleInfo.everyNPeriods;
- }
- this.readOnly = this.isEditMode && this.hasPermission && !this.hasPermission.write && this.hasPermission.read;
- var attributes = {
- schedule_every_label: t.translate("schedule_every_label"),
- schedule_time_dropdown_days_t: t.translate("schedule_time_dropdown_days_t"),
- schedule_time_dropdown_hours_t: t.translate("schedule_time_dropdown_hours_t"),
- schedule_time_dropdown_minutes_t: t.translate("schedule_time_dropdown_minutes_t"),
- defaultPeriod: defaultPeriod,
- uniqueid: this.uniqueId
- };
- this.$el.append(htmlGenerator(attributes));
-
- this._renderSelectors();
-
- if (this.isEditMode){
- if ( this.scheduleInfo.daily ) {
- this.dayFrequencySelector.getHTMLControl().val(this.scheduleInfo.daily.dailyPeriod||"day");
- }
- }
- if(this.objectInformation.showDailyInterval){
- // Handle in edit mode if there is no intra-day recurrence don't render the radio button groups
- var objectInfo = { descriptor: this.objectInformation.descriptor };
- if(this.isEditMode) {
- if( (this.scheduleInfo && this.scheduleInfo.intradayRecurrence) ||
- ( this.scheduleInfo && this.scheduleInfo.type != 'daily') ||
- (this.scheduleInfo && this.scheduleInfo.daily && this.scheduleInfo.daily.dailyPeriod == 'day')) {
- objectInfo.showDailyIntervalCheckbox = true;
- }
- else {
- objectInfo.showDailyIntervalCheckbox = false;
- }
- }
- else {
- objectInfo.showDailyIntervalCheckbox = true;
- }
-
- var $dailyIntervalCadence = this.$el.find('.schedule_daily_interval_container');
- this.dailyInterval = new DailyIntervalCadencePicker({
- $el: $dailyIntervalCadence,
- objectInformation: objectInfo,
- glassContext: this.glassContext,
- readOnly: this.readOnly
- });
-
- this.dailyInterval.render();
- }
- this._setEvents();
-
- deferred.resolve(this);
- return deferred.promise;
- },
- _setEvents: function() {
- $('.schedule_every_days_input').on('input', function (event) {
- this.value = this.value.replace(/[^0-9]/g, '');
- });
- },
- /** All views should overwrite this function.
- * It takes a partially populated json schedule descriptor and adds to it
- * based on the properties of this view.
- * @param desc the partial JSON schedule descriptor
- * @returns the descriptor passed in, with added attributes.
- */
- toDescriptor: function(desc) {
-
- desc.daily = {
- dailyPeriod: this.dayFrequencySelector.getHTMLControl().val()
- };
- desc.type = "daily";
- desc.everyNPeriods = parseInt(this.$el.find('.schedule_every_days_input').val(), 10);
- if(this.dailyInterval) {
- desc = this.dailyInterval.toDescriptor(desc);
- }
- return desc;
- },
- validate: function(msgs) {
- if(this.dailyInterval) {
- msgs = this.dailyInterval.validate(msgs);
- // One warning at a time
- if ( msgs.length > 0) {
- return msgs;
- }
- }
- var parameters = {};
- var $dailyInputDiv = this.$el.find('.schedule_dailyinterval_controls_container');
- $dailyInputDiv.removeAttr('aria-invalid aria-describedby');
- var everyNPeriods = parseInt(this.$el.find('.schedule_every_days_input').val(), 10);
- if ( isNaN(everyNPeriods)) {
- parameters.param = t.translate("schedule_every_label");
- msgs.push(t.translate("schedule_invalid_form_input_every_days_input", parameters));
- $dailyInputDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': msgs[0]
- });
- }
- return msgs;
- },
-
- _renderSelectors: function() {
- var dailyOptions = [];
- // We've come to here to have at least ByDay granted
- dailyOptions.push(
- {
- 'label': t.translate("schedule_time_dropdown_days_t"),
- 'value': 'day',
- 'selected': true
- }
- );
- if (this.glassContext.hasCapability("canUseSchedulingByHour")) {
- dailyOptions.push(
- {
- 'label': t.translate("schedule_time_dropdown_hours_t"),
- 'value': 'hour',
- 'selected': false
- }
- );
- }
- if (this.glassContext.hasCapability("canUseSchedulingByMinute")) {
- dailyOptions.push(
- {
- 'label': t.translate("schedule_time_dropdown_minutes_t"),
- 'value': 'minute',
- 'selected': false
- }
- );
- }
-
- this.dayFrequencySelector = new DropDownMenu({
- 'id': 'schedule_cadence_id_' + this.uniqueId,
- 'el': this.$el.find('#schedule_frequency_container_' + this.uniqueId),
- 'label': '',
- 'name' : 'schedule_daily_period',
- 'responsive': false,
- 'onChange': function(name, value){this._handleSelectors(name, value);}.bind(this),
- 'options': dailyOptions,
- 'readOnly': this.readOnly
- });
-
- this.dayFrequencySelector.doRender();
- },
-
- _handleSelectors: function(name, value) {
- var $dailyIntervalCadence = this.$el.find('.schedule_daily_interval_container');
- var objectInfo = { descriptor: this.objectInformation.descriptor };
- if(name === 'schedule_daily_period') {
- if ((value === "hour") || (value === "minute")) {
- objectInfo.showDailyIntervalCheckbox = false;
- }
- else if (value === "day") {
- objectInfo.showDailyIntervalCheckbox = true;
- }
-
- // Re-render the Interval Picker to not show the button groups
- $dailyIntervalCadence.empty();
- this.dailyInterval = new DailyIntervalCadencePicker({
- $el: $dailyIntervalCadence,
- objectInformation: objectInfo,
- glassContext: this.glassContext
- });
-
- this.dailyInterval.render();
- }
- else {
- // no selector
- return;
- }
- }
- });
- return dailyCadence;
- });
|