/* * 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/YearlyCadencePicker.html', 'underscore', "bi/schedule/views/DailyIntervalCadencePickerView", 'bi/commons/ui/properties/DropDown', 'bi/commons/ui/properties/RadioButtonGroup' ], function (View, controler, $, t, Q, dot, template, _, DailyIntervalCadencePicker, DropDown, RadioButtonGroup) { 'use strict'; var yearlyCadence = View.extend({ isEditMode: false, showAbsolute: false, /** * @constructor */ init: function(options) { yearlyCadence.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.dayTypeSelector = null; this.daySelector = null; this.dayOfMonthSelector = null; this.monthSelector = null; this.readOnly = false; }, /** * Render the new schedule view month picker section * */ render: function() { var deferred = Q.defer(); this.readOnly = this.isEditMode && this.hasPermission && !this.hasPermission.write && this.hasPermission.read; var htmlGenerator = dot.simpleTemplate(template); var attributes = { schedule_run_on_label: t.translate("schedule_run_on_label"), uniqueid: this.uniqueId }; this.$el.append(htmlGenerator(attributes)); //selectors this._renderSelectors(); this.dayTypeSelector.setValue('relative', true); if (this.isEditMode){ if (this.scheduleInfo.yearlyRelative) { var day = this.scheduleInfo.yearlyRelative.yearlyRelativeDay || "monday"; var week = this.scheduleInfo.yearlyRelative.yearlyRelativeWeek || "first"; this.daySelector.getHTMLControl().val(week + '|' + day); this.monthSelector.getHTMLControl().val(this.scheduleInfo.yearlyRelative.yearlyRelativeMonth||"september"); } else if (this.scheduleInfo.yearlyAbsolute) { this.dayTypeSelector.setValue('absolute', true); this.dayOfMonthSelector.getHTMLControl().val(this.scheduleInfo.yearlyAbsolute.yearlyAbsoluteDay||25); this.monthSelector.getHTMLControl().val(this.scheduleInfo.yearlyAbsolute.yearlyAbsoluteMonth||"september"); } } if(this.objectInformation.showDailyInterval){ this.dailyInterval = new DailyIntervalCadencePicker({ $el: this.$el, objectInformation: { descriptor: this.objectInformation.descriptor, showDailyIntervalCheckbox: true }, glassContext: this.glassContext, readOnly: this.readOnly }); this.dailyInterval.render(); } deferred.resolve(this); return deferred.promise; }, /** 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) { if (this.dayTypeSelector.getValue() === 'absolute') { desc.yearlyAbsolute = { yearlyAbsoluteDay: parseInt(this.dayOfMonthSelector.getHTMLControl().val(), 10), yearlyAbsoluteMonth: this.monthSelector.getHTMLControl().val() }; desc.type = "yearlyAbsolute"; }else { var val = this.daySelector.getHTMLControl().val(); var vals = val.split('|'); desc.yearlyRelative = { yearlyRelativeDay: vals[1], yearlyRelativeWeek: vals[0], yearlyRelativeMonth: this.monthSelector.getHTMLControl().val() }; desc.type = "yearlyRelative"; } /** * For yearly there is no default N period. Set this in the descriptor to make EMF code happy.*/ desc.everyNPeriods = 1; if(this.dailyInterval) { desc = this.dailyInterval.toDescriptor(desc); } return desc; }, validate: function(msgs) { if(this.dailyInterval) { msgs = this.dailyInterval.validate(msgs); } return msgs; }, _renderSelectors: function() { this.dayTypeSelector = new RadioButtonGroup({ 'id': 'schedule_day_type_selector_' + this.uniqueId, 'el': this.$el.find('#schedule_day_type_selector_container_' + this.uniqueId), 'label': t.translate("schedule_run_on_label"), 'ariaLabel': t.translate("schedule_run_on_select_description"), 'name': 'schedule_day_type_selector', 'value': 'relative', 'indent': 2, // * 10 pixels 'separator': false, 'onChange': function(name, value){this._handleSelectors(name, value);}.bind(this), 'controlOnLeft': true, 'items': [{ 'label': t.translate("schedule_relative_absolute_radio_absolute"), 'value': 'absolute' },{ 'label': t.translate("schedule_relative_absolute_radio_relative"), 'value': 'relative' }], 'readOnly': this.readOnly }); this.dayTypeSelector.render(); this.daySelector = new DropDown({ 'id': 'schedule_run_on_the_' + this.uniqueId, 'el': this.$el.find('#schedule_day_selector_container_' + this.uniqueId), 'label': t.translate("schedule_run_on_day_label"), 'ariaDescribedby': t.translate("schedule_run_on_select_description"), 'name' : 'schedule_relative_day_of_month', 'responsive': false, 'readOnly': this.readOnly, 'options': [{ //Monday 'label': t.translate("schedule_run_on_first_monday_label"), 'value': 'first|monday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_monday_label"), 'value': 'second|monday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_monday_label"), 'value': 'third|monday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_monday_label"), 'value': 'fourth|monday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_monday_label"), 'value': 'last|monday', 'selected': false }, { //Tuesday 'label': t.translate("schedule_run_on_first_tuesday_label"), 'value': 'first|tuesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_tuesday_label"), 'value': 'second|tuesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_tuesday_label"), 'value': 'third|tuesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_tuesday_label"), 'value': 'fourth|tuesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_tuesday_label"), 'value': 'last|tuesday', 'selected': false }, { //Wednesday 'label': t.translate("schedule_run_on_first_wednesday_label"), 'value': 'first|wednesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_wednesday_label"), 'value': 'second|wednesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_wednesday_label"), 'value': 'third|wednesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_wednesday_label"), 'value': 'fourth|wednesday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_wednesday_label"), 'value': 'last|wednesday', 'selected': false }, { //Thursday 'label': t.translate("schedule_run_on_first_thursday_label"), 'value': 'first|thursday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_thursday_label"), 'value': 'second|thursday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_thursday_label"), 'value': 'third|thursday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_thursday_label"), 'value': 'fourth|thursday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_thursday_label"), 'value': 'last|thursday', 'selected': false }, { //Friday 'label': t.translate("schedule_run_on_first_friday_label"), 'value': 'first|friday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_friday_label"), 'value': 'second|friday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_friday_label"), 'value': 'third|friday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_friday_label"), 'value': 'fourth|friday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_friday_label"), 'value': 'last|friday', 'selected': false }, { //Saturday 'label': t.translate("schedule_run_on_first_saturday_label"), 'value': 'first|saturday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_saturday_label"), 'value': 'second|saturday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_saturday_label"), 'value': 'third|saturday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_saturday_label"), 'value': 'fourth|saturday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_saturday_label"), 'value': 'last|saturday', 'selected': false }, { //Sunday 'label': t.translate("schedule_run_on_first_sunday_label"), 'value': 'first|sunday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_second_sunday_label"), 'value': 'second|sunday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_third_sunday_label"), 'value': 'third|sunday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_fourth_sunday_label"), 'value': 'fourth|sunday', 'selected': false }, { 'label': t.translate("schedule_run_on_the_last_sunday_label"), 'value': 'last|sunday', 'selected': false }] }); this.daySelector.doRender(); this.dayOfMonthSelector = new DropDown({ 'id': 'schedule_absolute_day_of_month_' + this.uniqueId, 'el': this.$el.find('#schedule_day_selector_container_' + this.uniqueId), 'label': t.translate("schedule_run_on_day_label"), 'ariaDescribedby': t.translate("schedule_run_on_select_description"), 'name' : 'schedule_absolute_day_of_month', 'responsive': false, 'readOnly': this.readOnly, 'options': [{ 'label': '1', 'value': '1', 'selected': false }, { 'label': '2', 'value': '2', 'selected': false }, { 'label': '3', 'value': '3', 'selected': false }, { 'label': '4', 'value': '4', 'selected': false }, { 'label': '5', 'value': '5', 'selected': false }, { 'label': '6', 'value': '6', 'selected': false }, { 'label': '7', 'value': '7', 'selected': false }, { 'label': '8', 'value': '8', 'selected': false }, { 'label': '9', 'value': '9', 'selected': false }, { 'label': '10', 'value': '10', 'selected': false }, { 'label': '11', 'value': '11', 'selected': false }, { 'label': '12', 'value': '12', 'selected': false }, { 'label': '13', 'value': '13', 'selected': false }, { 'label': '14', 'value': '14', 'selected': false }, { 'label': '15', 'value': '15', 'selected': false }, { 'label': '16', 'value': '16', 'selected': false }, { 'label': '17', 'value': '17', 'selected': false }, { 'label': '18', 'value': '18', 'selected': false }, { 'label': '19', 'value': '19', 'selected': false }, { 'label': '20', 'value': '20', 'selected': false }, { 'label': '21', 'value': '21', 'selected': false }, { 'label': '22', 'value': '22', 'selected': false }, { 'label': '23', 'value': '23', 'selected': false }, { 'label': '24', 'value': '24', 'selected': false }, { 'label': '25', 'value': '25', 'selected': false }, { 'label': '26', 'value': '26', 'selected': false }, { 'label': '27', 'value': '27', 'selected': false }, { 'label': '28', 'value': '28', 'selected': false }, { 'label': '29', 'value': '29', 'selected': false }, { 'label': '30', 'value': '30', 'selected': false }, { 'label': '31', 'value': '31', 'selected': false }] }); this.dayOfMonthSelector.doRender(); this.monthSelector = new DropDown({ 'id': 'schedule_run_on_the_month_' + this.uniqueId, 'el': this.$el.find('#schedule_month_selector_container_' + this.uniqueId), 'label': t.translate("schedule_repeat_month_label"), 'name' : 'schedule_month_of_year', 'responsive': false, 'options': [{ 'label': t.translate("schedule_run_on_the_jan_label"), 'value': 'january', 'selected': false }, { 'label': t.translate("schedule_run_on_the_feb_label"), 'value': 'february', 'selected': false }, { 'label': t.translate("schedule_run_on_the_mar_label"), 'value': 'march', 'selected': false }, { 'label': t.translate("schedule_run_on_the_apr_label"), 'value': 'april', 'selected': false }, { 'label': t.translate("schedule_run_on_the_may_label"), 'value': 'may', 'selected': false }, { 'label': t.translate("schedule_run_on_the_jun_label"), 'value': 'june', 'selected': false }, { 'label': t.translate("schedule_run_on_the_jul_label"), 'value': 'july', 'selected': false }, { 'label': t.translate("schedule_run_on_the_aug_label"), 'value': 'august', 'selected': false }, { 'label': t.translate("schedule_run_on_the_sep_label"), 'value': 'september', 'selected': false }, { 'label': t.translate("schedule_run_on_the_oct_label"), 'value': 'october', 'selected': false }, { 'label': t.translate("schedule_run_on_the_nov_label"), 'value': 'november', 'selected': false }, { 'label': t.translate("schedule_run_on_the_dec_label"), 'value': 'december', 'selected': false }], 'readOnly': this.readOnly }); this.monthSelector.doRender(); }, _handleSelectors: function(name, value) { if (value === "absolute") { this.daySelector.hide(); this.dayOfMonthSelector.show(); }else{ this.daySelector.show(); this.dayOfMonthSelector.hide(); } } }); return yearlyCadence; });