123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- /*
- * 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;
- });
|