1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * (C) Copyright IBM Corp. 2015, 2020
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'bi/glass/app/ContentView',
- 'bi/schedule/app/appControler',
- 'jquery',
- 'bi/commons/utils/Utils',
- 'bi/sharecommon/utils/translator',
- 'q',
- 'bi/sharecommon/utils/simpledoT',
- 'text!bi/schedule/templates/ScheduleView.html',
- 'underscore',
- 'moment-timezone',
- 'bi/schedule/views/DateTimeRangeCadencePickerView',
- 'bi/schedule/views/DailyCadencePickerView',
- 'bi/schedule/views/WeeklyCadencePickerView',
- 'bi/schedule/views/MonthlyCadencePickerView',
- 'bi/schedule/views/YearlyCadencePickerView',
- 'bi/schedule/views/TriggerCadencePickerView',
- 'bi/schedule/views/FormatPickerView',
- 'bi/schedule/views/ScheduleDeliveryPickerView',
- 'bi/commons/ui/properties/DropDown',
- 'bi/commons/ui/properties/CheckBox',
- 'ca_portal/features/mypreferences/MyPreferences',
- 'bi/schedule/views/PdfOptionsView',
- 'bi/commons/ui/properties/PropertyUIControl',
- 'bi/content_apps/utils/ContentStoreObject',
- 'bi/commons/ui/dialogs/ConfirmationDialog',
- 'bi/content_apps/utils/C10Utils',
- 'caglass/ajax/CAAuthentication',
- 'bi/content_apps/authoring/AuthoringHelper'
- ],
- function(View,
- controler,
- $,
- Utils,
- t,
- Q,
- dot,
- template,
- _,
- moment,
- DateTimeRangeCadencePicker,
- DailyCadencePicker,
- WeeklyCadencePicker,
- MonthlyCadencePicker,
- YearlyCadencePicker,
- TriggerCadencePicker,
- FormatPicker,
- ScheduleDeliveryPicker,
- DropDown,
- CheckBox,
- MyPreferences,
- PdfOptionsView,
- PropertyUIControl,
- ContentStoreObject,
- ConfirmationDialog,
- C10Utils, CAAuthentication, AuthoringHelper) {
- 'use strict';
- var __CHILD_SLIDEOUT_STANDARD_WIDTH = '350px';
- var scheduleView = View.extend({
- /**
- * @constructor options can contain:
- *
- * objectInformation: The CM object being scheduled,
- * onCreateOrUpdateCallback: callback to call once a schedule is created or updated
- * canBurst: whether this report is burstable,
- * glassContext: the glass context
- */
- init: function(options) {
- scheduleView.inherited('init', this, arguments);
- this.showOptions = true;
- this.defaultLocale = options.glassContext.services.userProfile.preferences.contentLocale || 'en-us';
- this.options = {
- delivery: {
- save: {
- notify: false
- }
- },
- outputLocale: [this.defaultLocale],
- pdf:{},
- burst:false,
- outputFormat: []
- };
- this.options.outputFormat.push( this._getDefaultOutputFormat());
- _.extend(this, options);
- // set defaults
- this.currentRenderedCadenceType = 'weekly';
- this.outputLocale = [this.defaultLocale];
- this.msgs = [];
- this.warningMessage = null;
- this.parameterValues = [];
- //Place holder for parameter values set on the report properties
- this.reportParameterValues = [];
- this.scheduleTypeSelector = null;
- this.uniqueId = _.uniqueId('id_');
- this.readOnly = false;
- this.deliveryPicker = null;
- this.outputFormatPicker = null;
- this.pdfOptionsView = null;
- this.timezone = this.glassContext.services.userProfile.preferences.timeZoneID;
- this.canBurst = this.canBurst && this.glassContext.hasCapability('canUseBursting');
- this.showPDFOption = this.glassContext.hasCapability('canGeneratePDFOutput') &&
- this.objectInformation.type !== 'interactiveReport' &&
- this.objectInformation.type !== 'powerPlay8Report' &&
- this.objectInformation.type !== 'powerPlay8ReportView';
- // Predefine this to cache data of the existing schedule on the initial render
- this.initScheduleDescriptor = {
- reportId: null,
- reportType: null,
- scheduleInfo: {
- active: null,
- startDate: null,
- endDate: null,
- endType: null,
- timezone: null,
- weekly: null,
- everyNPeriods: null,
- type: null
- },
- options: {
- outputFormat: null,
- delivery: null,
- outputLocale: null,
- pdf: null,
- burst: null
- },
- parameters: null
- };
- this.showOptions = this._supportsOptions();
- },
- _supportsOptions: function() {
- var objWithNoOptions = ['dataSet2','agentDefinition', 'agentDefinitionView', 'jobDefinition', 'jupyterNotebook'];
- return objWithNoOptions.indexOf(this.objectInformation.type) === -1;
- },
- _openClassicView:function(){
- var scheduleDescriptor = this._prepareScheduleDescriptor();
- this._confirmChanges(function() {
- if (_.isEqual(scheduleDescriptor, this.initDesc)){
- this.setDone();
- this.slideout.hide();
- if (this.slideout.parent) {
- this.slideout.parent.hide();
- }
- C10Utils.openC10Morphlet('portal/schedule/report.xts', this.objectInfo.type, this.objectInfo.id);
- } else {
- this._createOrUpdateScheduleRoutine(scheduleDescriptor).then(
- function(){
- this.slideout.hide();
- if (this.slideout.parent) {
- this.slideout.parent.hide();
- }
- C10Utils.openC10Morphlet('portal/schedule/report.xts', this.objectInfo.type, this.objectInfo.id);
- }.bind(this)
- );
- }
- }.bind(this), function(){}, t.translate('schedule_update_confirm'), t.translate('schedule_update_save_before_classicview'), scheduleDescriptor);
- },
- setFocus: function() {
- this.$el.focus();
- },
- _confirmChanges: function(okFunc, cancelFunc, messageTitle, messageText, scheduleDescriptor) {
- if ((scheduleDescriptor) && (_.isEqual(scheduleDescriptor, this.initDesc))) {
- okFunc();
- return;
- }
- var updateDialog = new ConfirmationDialog('warning', messageTitle, messageText);
- updateDialog.confirm(okFunc, cancelFunc);
- },
- _hasRestrictedFormats: function () {
- var formats = this.outputFormatPicker && this.outputFormatPicker.getOutputFormats() || [];
- for(var index=0; index < formats.length;index += 1) {
- if (!AuthoringHelper.userCanGenerateFormat(this.glassContext, formats[index])){
- return true;
- }
- }
- return false;
- },
- _resetRestrictedFormats: function(scheduleDescriptor) {
- var updatedList = _.reject(scheduleDescriptor.options.outputFormat, function(aFormat) {return !AuthoringHelper.userCanGenerateFormat(this.glassContext, aFormat);}.bind(this));
- if (updatedList.length === 0) {
- updatedList.push('HTML');
- }
- scheduleDescriptor.options.outputFormat = updatedList;
- },
- _handleUpdate: function() {
- return this._closeOpenChildren()
- .then(function() {
- this.setWorking();
- this.hideWarningMessage();
- var scheduleDescriptor = this._prepareScheduleDescriptor();
- this.initDesc = scheduleDescriptor;
- if ( this.validate(scheduleDescriptor) ) {
- // Create a new schedule
- if (!this.descriptor) {
- return this._createOrUpdateScheduleRoutine(scheduleDescriptor);
- // Update an existing schedule
- } else {
- var timeZoneChanged = this._hasOnlyTimezoneBeenChanged(this.initScheduleDescriptor, scheduleDescriptor);
- var hasResctictedFormats = this._hasRestrictedFormats();
- var message = '';
- if (timeZoneChanged && hasResctictedFormats) {
- message = t.translate('schedule_update_restricted_formats_timezone_confirm_message');
- } else if (timeZoneChanged){
- message = t.translate('schedule_update_timezone_difference_confirm_message');
- } else if (hasResctictedFormats) {
- message = t.translate('schedule_update_restricted_formats_confirm_message');
- }
- if (message.length > 0) {
- return this._confirmChanges(function() {
- if (hasResctictedFormats) {
- this._resetRestrictedFormats(scheduleDescriptor);
- }
- this._createOrUpdateScheduleRoutine(scheduleDescriptor);
- }.bind(this), this.setDone.bind(this), t.translate('schedule_update_confirm'), message);
- } else {
- return this._createOrUpdateScheduleRoutine(scheduleDescriptor);
- }
- }
- } else {
- this.showWarningMessage();
- this.setDone();
- return Promise.resolve();
- }
- }.bind(this));
- //.done(function(){return Promise.resolve()});
- },
- _setEvents: function () {
- this.$el.find('.classicViewLink').on('primaryaction', this._openClassicView.bind(this));
- this.$el.find('.schedule_primary_button').on('clicktap', this._handleUpdate.bind(this));
- this.$el.find('.schedule_language_picker').on('clicktap', function() {
- this._closeOpenChildren().then(function() {
- this.glassContext.appController.showSlideOut({
- 'parent': this.slideout,
- 'overlay': false,
- 'width': __CHILD_SLIDEOUT_STANDARD_WIDTH,
- 'label': t.translate('schedule_language_picker_name'),
- 'content': {
- 'module': 'bi/content_apps/common/ui/LanguagePickerView',
- 'glassContext': this.glassContext,
- 'supportedContentLocales': this.supportedContentLocales,
- 'enabledLanguages': this.outputLocale,
- 'closeCallback': function(data) {
- this.outputLocale = data;
- var languageLabel = t.translate('schedule_no_languages_label');
- var labelArray = [];
- for(var i = 0; i < this.outputLocale.length; i++) {
- labelArray.push(this.supportedContentLocales[this.outputLocale[i]]);
- }
- languageLabel = labelArray.join(', ');
- this.$el.find('.output_language_list').text(languageLabel);
- this.$el.find('.output_language_list').attr('title', languageLabel);
- }.bind(this)
- }
- });
- }.bind(this)).done();
- }.bind(this));
- var cancelChanges = function() {
- this.close();
- }.bind(this);
- this.$el.find('.schedule_secondary_button').on('clicktap', cancelChanges);
- },
- _prepareScheduleDescriptor: function() {
- var reportId = this.objectInformation.id;
- var reportType = this.objectInformation.type;
- var active = this.isEditMode? this.objectInformation.descriptor.scheduleInfo.active : true;
- var outputFormats = this.options.outputFormat;
- if(this.outputFormatPicker !== null) {
- outputFormats = this.outputFormatPicker.getOutputFormats();
- }
- var scheduleInfo = {
- active: active,
- timezone: this.timezone
- };
- // grab datetimerangecadencePicker schedinfo
- scheduleInfo = this.datetimeRangeCadencePicker.toDescriptor(scheduleInfo);
- // grab cadencePicker info
- scheduleInfo = this.cadencePicker.toDescriptor(scheduleInfo);
- // DELIVERY
- var deliveryOptions = this.options.delivery;
- if(this.deliveryPicker !== null) {
- deliveryOptions = this.deliveryPicker.getDeliveryOptions();
- }
- // Languages/ Output Locale
- var outputLocale = this.outputLocale || this.options.outputLocale;
- // PDF Options
- var pdfOptions = this.pdfOptionsView ? this.pdfOptionsView.getOptions() : this.options.pdf;
- // Burst
- var burst = this._getBurstValue();
- // note: do not send a schedule name. Causes problems with triggers.
- var scheduleDescriptor = _.extend({}, {
- reportId: reportId,
- reportType: reportType,
- scheduleInfo: scheduleInfo,
- options: {
- outputFormat: outputFormats,
- delivery: deliveryOptions,
- outputLocale: outputLocale,
- pdf: pdfOptions,
- burst: burst
- },
- parameters: this.parameterValues
- });
- if ((this.objectInformation.type === 'agentDefinition') || (this.objectInformation.type === 'agentDefinitionView')) {
- delete scheduleDescriptor.options ;
- }
- return scheduleDescriptor;
- },
- _hasOnlyTimezoneBeenChanged: function(scheduleDescriptorOld, scheduleDescriptorNew) {
- var status = false;
- var oldCopy = $.extend(true, {}, scheduleDescriptorOld);
- var newCopy = $.extend(true, {}, scheduleDescriptorNew);
- var oldTimezone = oldCopy.scheduleInfo.timezone;
- var newTimezone = newCopy.scheduleInfo.timezone;
- if (oldTimezone !== newTimezone) {
- // Undefine these properties in order to compare schedule descriptors
- delete oldCopy.scheduleInfo.timezone;
- delete newCopy.scheduleInfo.timezone;
- // remove endDate if indefinite
- if(oldCopy.scheduleInfo.endType === 'indefinite') {
- delete oldCopy.scheduleInfo.endDate;
- }
- if(newCopy.scheduleInfo.endType === 'indefinite') {
- delete newCopy.scheduleInfo.endDate;
- }
- status = _.isEqual(oldCopy, newCopy);
- }
- return status;
- },
- _closeOpenChildren: function() {
- var deferred = Q.defer();
- // Close any open open child slideouts
- if (this.slideout && this.slideout.hasOpenChild()) {
- var openChild = this.slideout.child;
- openChild.hide().then(function() {
- deferred.resolve();
- }).done();
- } else {
- deferred.resolve();
- }
- return deferred.promise;
- },
- _getOutputFormat: function(options) {
- var outputFormat = '';
- try {
- for (var i = 0; i < options.length; i++) {
- if (options[i].name === 'outputFormat') {
- // expect output format option value to be a MobX ObservableArray
- outputFormat = options[i].value.join(',');
- break;
- }
- }
- } catch(e) {
- // return outputFormat as empty string
- }
- return outputFormat;
- },
- _createOrUpdateSchedule: function(scheduleDescriptor) {
- var _self = this;
- // scheduleDescriptor should not include options when scheduling a job
- if (_self.objectInformation && _self.objectInformation.type && _self.objectInformation.type === 'jobDefinition' && scheduleDescriptor.options )
- delete scheduleDescriptor.options;
- return controler.createSchedule(scheduleDescriptor, _self.glassContext).then(function(resp) {
- // Not all schedulable objects have delivery options
- var cloudOpts = this.deliveryPicker === null ? {} : this.deliveryPicker.getCloudOptions();
- if (!resp) {
- resp = {};
- }
- return controler.updateSaveToCloudOptions(resp.id, cloudOpts, this.glassContext).then(function(){
- // call callback if specified
- if(_self.onCreateOrUpdateCallback && typeof(_self.onCreateOrUpdateCallback)==='function') {
- _self.onCreateOrUpdateCallback();
- }
- var message;
- var trackingOpts = {
- objectType: this.objectInformation.type,
- object: this.objectInformation.id,
- 'custom.outputFormat': this._getOutputFormat(this.objectInformation.outputFormat)
- };
- if(_self.isEditMode) {
- trackingOpts.type = 'Updated Object';
- trackingOpts.action = 'scheduleEdited';
- trackingOpts.milestoneName = 'scheduleEdited_' + this.objectInformation.type;
- message = t.translate('sch_update_success_msg');
- } else {
- trackingOpts.type = 'Created Object';
- trackingOpts.action = 'scheduleCreated';
- trackingOpts.milestoneName = 'scheduleCreated_' + this.objectInformation.type;
- message = t.translate('sch_create_success_msg');
- }
- var instrumentor = this.glassContext.getCoreSvc('.Instrumentation');
- if ((instrumentor) && (instrumentor.track)) {
- instrumentor.track(trackingOpts);
- }
- _self.glassContext.appController.showToast(message, {
- 'newestOnTop' : true,
- 'preventDuplicates' : false,
- 'timeOut': 6000,
- 'extendedTimeOut': 1000
- });
- _self.setDone();
- _self.close();
- return Promise.resolve();
- }.bind(this));
- }.bind(this)).fail(function () {
- _self.setDone();
- });
- },
- _getFormatFromObject: function() {
- if ((this.objectInformation) && (this.objectInformation.options)) {
- var formatOpt = _.find(this.objectInformation.options, function(opt){return opt.name === 'outputFormat';});
- if (formatOpt) {
- var objectDefaultFormat;
- if ((typeof formatOpt.value).toLocaleLowerCase() === 'string') {
- objectDefaultFormat = formatOpt.value;
- } else {
- objectDefaultFormat = formatOpt.value[0];
- }
- if (!AuthoringHelper.userCanGenerateFormat(this.glassContext, objectDefaultFormat)) {
- objectDefaultFormat = 'HTML';
- }
- return objectDefaultFormat;
- } else {
- return undefined;
- }
- }
- return undefined;
- },
- _getDefaultOutputFormat: function() {
- var formatFromObject = this._getFormatFromObject();
- var formatFromPreferences = this.glassContext.services.userProfile.preferences.format;
- if (formatFromObject) {
- return formatFromObject;
- }
- if ((formatFromPreferences) && (AuthoringHelper.userCanGenerateFormat(this.glassContext, formatFromPreferences)) ){
- return formatFromPreferences;
- }
- return 'HTML';
- },
- _createOrUpdateScheduleRoutine: function(scheduleDescriptor) {
- return controler.getUserCredential(this.glassContext).then(function () {
- return this._createOrUpdateSchedule(scheduleDescriptor);
- }.bind(this)).fail(function () {
- // Credentials need to be renewed
- this.glassContext.appController.showToast(t.translate('sub_credentials_expired_msg'), {
- 'type': 'warning',
- 'preventDuplicates': true,
- 'btnLabel': t.translate('sub_renew_credentials_button'),
- 'callback': function () {
- this._caAuthentication = new CAAuthentication();
- return this._caAuthentication.storeCredentials(this.glassContext).then(function () {
- this._createOrUpdateSchedule(scheduleDescriptor);
- }.bind(this)).fail(function (error) {
- if (error && error.displayObjects) {
- this._myPreferences = new MyPreferences({ glassContext: this.glassContext });
- return this._myPreferences.openCreateCredentialDialog(error.displayObjects).then(function () {
- this._createOrUpdateSchedule(scheduleDescriptor);
- }.bind(this)).fail(function () {
- this.setDone();
- }.bind(this));
- }
- }.bind(this)).fail(function () {
- this.setDone();
- }.bind(this));
- }.bind(this)
- });
- }.bind(this));
- },
- /**
- * Render the new schedule view
- *
- */
- render: function() {
- var deferred = Q.defer();
- this.descriptor = this.objectInformation.descriptor;
- this.isEditMode = typeof(this.descriptor) !== 'undefined';
- this.readOnly = this.isEditMode && this.objectInformation.hasPermission && !this.objectInformation.hasPermission.write && this.objectInformation.hasPermission.read;
- var htmlGenerator = dot.simpleTemplate(template);
- var objectInformation = this.objectInformation || {};
- var canBurst = this.canBurst || false;
- var showPDFOption = this.showPDFOption;
- objectInformation.defaultName = this.objectInformation.defaultName || '';
- this.canShowPrompt = !(C10Utils.isPowerPlay(this.objectInformation.type));
- if (this.canShowPrompt){
- // For display render the prompt picker
- // to indicate there are parameter values from report properties available for this schedule but will not be part of the schedule unless user set values by editing
- this.reportParameterValues = this.objectInformation.parameters || [];
- }
- var capableSchedType = this.getScheduleType();
- var title = this.isEditMode ? t.translate('schedule_panel_title_update_text') : t.translate('schedule_panel_title_text');
- var attributes = {
- canShowClassic: this._supportsOptions(),
- asset_name: _.escape(objectInformation.defaultName),
- schedule_panel_back: t.translate('schedule_panel_back_text'),
- schedule_panel_title: title,
- schedule_type_label: t.translate('schedule_type_label'),
- schedule_output_label: t.translate('schedule_output_label'),
- schedule_delivery_label: t.translate('schedule_delivery_label'),
- schedule_prompts_label: t.translate('schedule_prompts_label'),
- schedule_select_text: t.translate('schedule_select_text'),
- schedule_create_btn: this.isEditMode ? t.translate('schedule_update_btn_label') : t.translate('schedule_create_btn_label'),
- schedule_cancel_btn: t.translate('schedule_cancel_btn_label'),
- schedule_period: t.translate('schedule_period'),
- uniqueid: this.uniqueId,
- output_format_select_text: t.translate('output_format_select_text'),
- showOptions: this.showOptions,
- showPDFOption: showPDFOption,
- canBurst: canBurst,
- schedule_languages_label: t.translate('schedule_languages_label'),
- schedule_pdf_options_label: t.translate('schedule_pdf_options_label'),
- schedule_classic_view_label: t.translate('classicViewLink'),
- canShowPrompt: this.canShowPrompt
- };
- attributes.schedule_controls_description = t.translate('schedule_controls_description', {
- action1: attributes.schedule_create_btn,
- action2: attributes.schedule_cancel_btn
- });
- var items = [{
- 'type': 'Banner',
- 'centerLabel': true,
- 'backButton': this.slideout.overlay,
- 'value': title
- },
- {
- 'type': 'SectionLabel',
- 'label': t.translate('schedule_period')
- }];
- if(this.showOptions) {
- items.push({
- 'type': 'SectionLabel',
- 'label': t.translate('schedule_options')
- });
- }
- this._propertyUIControl = new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el,
- 'closeCallback': this.close.bind(this),
- 'items': items
- });
- this._propertyUIControl.render().then(function() {
- // load the complete template
- var $content = $(htmlGenerator(attributes));
- // point this.$el to the content section of the slideout, below the header
- this.$el = this.$el.find('.propertiesUIControlPageView');
- // add each of the three sections, to the correct place
- // add type section to above the first divider ('Period')
- this.$el.prepend($content.find('.schedule_type_section'));
- // add period section to below the first divider ('Period')
- $content.find('.schedule_period_section').insertAfter(this.$el.find('.sectionLabel:first'));
- // add options section to below the second divider ('Options')
- this.$el.append($content.find('.schedule_options_section'));
- // add the progress overlay div
- this.$el.append($content.find('.progress-overlay'));
- this.$el.addClass('new_schedule_slideout');
- return this.renderDateTimeRangeCadencePicker();
- }.bind(this)).then(function() {
- this.renderCadencePicker(capableSchedType);
- if(this.showOptions) {
- this.renderOutputFormatPicker();
- this.renderPromptRow();
- this.renderDeliveryPicker();
- if (showPDFOption) {
- this.renderPdfOptionsView();
- }
- this.setLanguageLabel();
- // checkbox for burst
- if(canBurst) {
- this.renderBurstCheckBox();
- }
- }
- //selector
- this._renderTypeSelector(capableSchedType);
- if ( this.isEditMode ) {
- this.currentRenderedCadenceType = capableSchedType;
- this.scheduleTypeSelector.getHTMLControl().val(this.currentRenderedCadenceType);
- }
- this._setIcons();
- // in update mode the permissions are passed
- if ( this.readOnly ) {
- // Update buttons
- this.$el.find('.schedule_primary_button').prop('disabled', true);
- this.$el.find('.schedule_secondary_button').prop('disabled', true);
- // Language picker
- this.$el.find('.schedule_language_option_toggler').prop('disabled', true);
- // Pdf option picker
- this.$el.find('.schedule_pdf_option_toggler').prop('disabled', true);
- // All input fields including all pickers
- this.$el.find('input').prop('disabled', true);
- }
- // Cache data of the existing schedule
- this._saveExistingScheduleInitialState();
- this._setEvents();
- this.initDesc = this._prepareScheduleDescriptor();
- deferred.resolve();
- }.bind(this));
- return deferred.promise;
- },
- setLanguageLabel: function() {
- if ((this.objectInformation.descriptor) && (this.objectInformation.descriptor.options.outputLocale)) {
- this.outputLocale = this.objectInformation.descriptor.options.outputLocale;
- }
- this.glassContext.services.config.getContentLocales().then(function(contentLocales) {
- this.supportedContentLocales = contentLocales;
- if ((this.objectInformation.descriptor) && (this.objectInformation.descriptor.options.outputLocale) ){
- this.outputLocale = this.objectInformation.descriptor.options.outputLocale;
- }
- var languageLabel = t.translate('schedule_no_languages_label');
- if(this.isEditMode) {
- if((this.objectInformation.descriptor) && (this.objectInformation.descriptor.options.outputLocale) ){
- var languageList = [];
- for(var i = 0; i < this.outputLocale.length; i++) {
- languageList.push(contentLocales[this.outputLocale[i]]);
- }
- if(languageList.length > 0) {
- languageLabel = languageList.join(', ');
- } else {
- languageLabel = contentLocales[this.defaultLocale];
- }
- }
- } else {
- languageLabel = contentLocales[this.defaultLocale];
- }
- this.$el.find('.output_language_list').text(languageLabel);
- this.$el.find('.output_language_list').attr('title', languageLabel);
- }.bind(this)).done();
- },
- shouldShowMobile: function() {
- var mobileTypes = ['interactiveReport', 'report', 'query', 'analysis'];
- return ((mobileTypes.indexOf(this.objectInformation.type) !== -1) || ((this.objectInformation.type === 'reportView') && (mobileTypes.indexOf(this.objectInformation.base[0].type) !== -1)));
- },
- renderDeliveryPicker: function() {
- var deliveryOptions = {};
- var name = this.objectInformation.defaultName;
- if(this.isEditMode) {
- if(this.objectInformation.descriptor.options.delivery) {
- deliveryOptions = this.objectInformation.descriptor.options.delivery;
- }
- }
- try {
- this.deliveryPicker = new ScheduleDeliveryPicker({
- $el: this.$el.find('.schedule_delivery_picker'),
- $toggler: this.$el.find('.schedule_delivery_picker'),
- $activeOptionsContainer: this.$el.find('.delivery_list'),
- reportName: name,
- deliveryOptions: deliveryOptions,
- rawOptions: this.objectInformation.rawOptions,
- isEditMode: this.isEditMode,
- glassContext: this.glassContext,
- slideoutparent: this.slideout,
- hasPermission: this.objectInformation.hasPermission,
- showMobile: this.shouldShowMobile(),
- enableAdvancedSettings: true,
- allowRecipients: function() { return !this._getBurstValue(); }.bind(this)
- });
- this.deliveryPicker.render();
- } catch(e) {
- console.log('There was an error initializing the DeliveryPicker.', e);
- }
- },
- renderPdfOptionsView: function() {
- var _self = this;
- var pdfOptions = {};
- if(this.isEditMode) {
- if(this.objectInformation.descriptor.options.pdf) {
- pdfOptions = this.objectInformation.descriptor.options.pdf;
- }
- }
- this.pdfOptionsView = new PdfOptionsView({
- glassContext: _self.glassContext,
- $toggler: _self.$el.find('.schedule_pdf_options_picker'),
- parentSlideout: _self.slideout,
- pdfOptions: pdfOptions
- });
- this.pdfOptionsView.render();
- },
- _saveExistingScheduleInitialState: function() {
- // Cache data of the existing schedule
- if (this.isEditMode) {
- this.initScheduleDescriptor = this._prepareScheduleDescriptor();
- // restore original timezone
- this.initScheduleDescriptor.scheduleInfo.timezone = this.descriptor.scheduleInfo.timezone;
- }
- },
- _renderTypeSelector: function(schType) {
- var schOptions = [];
- if (this.glassContext.hasCapability('canUseSchedulingByDay')) {
- schOptions.push({
- 'label': t.translate('daily_label'),
- 'value': 'daily',
- 'selected': (schType == 'daily')?true:false
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByWeek')) {
- schOptions.push({
- 'label': t.translate('weekly_label'),
- 'value': 'weekly',
- 'selected': (schType == 'weekly')?true:false
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByMonth')) {
- schOptions.push({
- 'label': t.translate('monthly_label'),
- 'value': 'monthly',
- 'selected': (schType == 'monthly')?true:false
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByYear')) {
- schOptions.push({
- 'label': t.translate('yearly_label'),
- 'value': 'yearly',
- 'selected': (schType == 'yearly')?true:false
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByTrigger')) {
- schOptions.push({
- 'label': t.translate('trigger_label'),
- 'value': 'trigger',
- 'selected': (schType == 'trigger')?true:false
- });
- }
- if (schOptions.length === 0) {
- // Should not happen. Use default
- schOptions.push({
- 'label': t.translate(schType + '_label'),
- 'value': schType,
- 'selected': true
- });
- }
- var scheduleId = 'schedule_type_' + this.uniqueId;
- var scheduleName = 'schedule_type_option';
- //var scheduleDescribedBy = 'schedule_type_describedby_'+this.uniqueId;
- this.scheduleTypeSelector = new DropDown({
- 'id': scheduleId,
- 'el': this.$el.find('#schedule_type_selector_container_' + this.uniqueId),
- 'label': t.translate('schedule_type_label'),
- 'name' : scheduleName,
- 'responsive': false,
- 'onChange': function(name, value){this._toggleCadenceView(name, value);}.bind(this),
- 'options': schOptions,
- 'readOnly': this.readOnly,
- 'ariaLabel': t.translate('schedule_type_aria_label'),
- 'ariaDescribedby': t.translate('schedule_type_description')
- });
- this.scheduleTypeSelector.doRender();
- },
- _toggleCadenceView: function(name, scheduleType) {
- // Handle change for different type of cadence view in the schedule pane
- var $cadence = this.$el.find('.schedule_cadence_picker');
- if (scheduleType != this.currentRenderedCadenceType) {
- this.currentRenderedCadenceType = scheduleType;
- $cadence.empty();
- this.renderCadencePicker(scheduleType);
- }
- },
- renderDateTimeRangeCadencePicker: function() {
- this.datetimeRangeCadencePicker = new DateTimeRangeCadencePicker({
- $el: this.$el.find('.schedule_datetime_range_picker'),
- objectInformation: {
- descriptor: this.objectInformation.descriptor
- },
- glassContext: this.glassContext
- });
- return this.datetimeRangeCadencePicker.render();
- },
- renderCadencePicker: function(type) {
- var $cadence = this.$el.find('.schedule_cadence_picker');
- switch(type) {
- case 'daily':
- this.cadencePicker = new DailyCadencePicker({
- $el: $cadence,
- objectInformation: {
- descriptor: this.objectInformation.descriptor,
- showDailyInterval: true
- },
- glassContext: this.glassContext,
- hasPermission: this.objectInformation.hasPermission
- });
- break;
- case 'weekly':
- this.cadencePicker = new WeeklyCadencePicker({
- $el: $cadence,
- objectInformation: {
- descriptor: this.objectInformation.descriptor,
- showRunEvery: true,
- showDailyInterval: true
- },
- glassContext: this.glassContext,
- hasPermission: this.objectInformation.hasPermission
- });
- break;
- case 'monthly':
- this.cadencePicker = new MonthlyCadencePicker({
- $el: $cadence,
- objectInformation: {
- descriptor: this.objectInformation.descriptor,
- showDailyInterval: true
- },
- glassContext: this.glassContext,
- hasPermission: this.objectInformation.hasPermission
- });
- break;
- case 'yearly':
- this.cadencePicker = new YearlyCadencePicker({
- $el: $cadence,
- objectInformation: {
- descriptor: this.objectInformation.descriptor,
- showDailyInterval: true
- },
- glassContext: this.glassContext,
- hasPermission: this.objectInformation.hasPermission
- });
- break;
- case 'trigger':
- this.cadencePicker = new TriggerCadencePicker({
- $el: $cadence,
- objectInformation: {
- descriptor: this.objectInformation.descriptor
- },
- glassContext: this.glassContext
- });
- break;
- default:
- console.log('Wrong cadence type.');
- }
- if (this.cadencePicker) {
- this.cadencePicker.render();
- }
- },
- renderOutputFormatPicker: function() {
- //var _self = this;
- var formats = this.options.outputFormat;
- if(this.isEditMode) {
- if(this.objectInformation.descriptor.options.outputFormat) {
- formats = this.objectInformation.descriptor.options.outputFormat.slice();
- }
- }
- try {
- /*
- We show all of the formats when it is not an interactive report or it is not a report view of an interactive report.
- Otherwise only html format shows
- */
- var showHtmlOnly = this.objectInformation.type === 'interactiveReport' ||
- this.objectInformation.type === 'reportView' &&
- this.objectInformation.base &&
- this.objectInformation.base[0] &&
- this.objectInformation.base[0].type &&
- this.objectInformation.base[0].type === 'interactiveReport';
- var showPdfOnly = this.objectInformation.type === 'powerPlay8Report' || this.objectInformation.type === 'powerPlay8ReportView';
- this.outputFormatPicker = new FormatPicker({
- $el: this.$el.find('.output_format_list'),
- $toggler: this.$el.find('.schedule_output_format_picker'),
- outputFormats: showPdfOnly ? this._getOutputFormatsForPowerPlayObjects(formats): formats.slice(),
- hasPermission: this.objectInformation.hasPermission,
- showHTML: !showPdfOnly,
- showPDF: (!showHtmlOnly) && this.glassContext.hasCapability('canGeneratePDFOutput'),
- showExcel: (!showHtmlOnly) && (!showPdfOnly) && this.glassContext.hasCapability('canGenerateXLSOutput'),
- showCSV: (!showHtmlOnly) && (!showPdfOnly) && this.glassContext.hasCapability('canGenerateCSVOutput'),
- showXML: (!showHtmlOnly) && (!showPdfOnly) && this.glassContext.hasCapability('canGenerateXMLOutput'),
- glassContext: this.glassContext,
- slideoutparent: this.slideout,
- overlay: false
- });
- this.outputFormatPicker.render();
- } catch(e) {
- console.log('There was an error initializing the FormatPicker.', e);
- }
- },
- _getOutputFormatsForPowerPlayObjects: function (formats) {
- if (!this.objectInformation.options) {
- return ['PDF'];
- } else {
- return formats.slice();
- }
- },
- _renderPromptRowForReport: function() {
- var _self = this;
- // content_apps.PromptValuesView uses 'objectInfo' instead of 'objectInformation'
- this.objectInfo = this.objectInformation;
- if(this.isEditMode) {
- if(this.descriptor.parameters) {
- this.parameterValues = this.descriptor.parameters;
- }
- }
- var hasScheduleParameterValues = this.parameterValues.length > 0;
- var displayParameterValues = hasScheduleParameterValues?this.parameterValues:this.reportParameterValues;
- this.$el.find('.prompt_picker_target').on('clicktap', function() {
- _self._closeOpenChildren().then(function() {
- _self.glassContext.appController.showSlideOut({
- 'position': _self.slideout ? null : 'right',
- 'parent': _self.slideout,
- 'width': '350',
- 'enableTabLooping': true,
- 'label': t.translate('schedule_prompt_picker_name'),
- 'content': {
- 'module': 'bi/content_apps/PromptValuesView',
- 'parentView': _self,
- 'glassContext': _self.glassContext,
- 'promptDisplayValues': ContentStoreObject.getPromptsDisplayValues(displayParameterValues),
- 'parameters': _self.parameterValues,
- 'hasPermission': _self.objectInformation.hasPermission,
- 'clearCallback': _self._updatePromptValueLabelCB.bind(_self),
- 'editCallback': _self._updatePromptValueLabelCB.bind(_self)
- }
- });
- }).done();
- });
- // Always show user specifically set parameter values first if any
- this._updatePromptValueLabel( displayParameterValues, !hasScheduleParameterValues);
- },
- renderPromptRow: function() {
- if (this.canShowPrompt){
- return this._renderPromptRowForReport();
- }
- },
- _updatePromptValueLabelCB: function(prompts) {
- // Set the parameter values associated with this schedule after user edit callback
- // Or reset the parameterValues to empty on Clear callback
- this.parameterValues = prompts? prompts:[];
- var $promptValueLabel = this.$el.find('.currentPromptValues');
- $promptValueLabel.text(this._getPromptValueLabel(this.parameterValues));
- },
- // On Render
- _updatePromptValueLabel: function(prompts, reportPrompts) {
- var $promptValueLabel = this.$el.find('.currentPromptValues');
- $promptValueLabel.text(this._getPromptValueLabel(prompts, reportPrompts));
- },
- _getPromptValueLabel: function(prompts, reportPrompts) {
- var label = t.translate('schedule_prompt_value_label_default');
- var prefix = reportPrompts?'report':'schedule';
- if (prompts && prompts.length > 0) {
- if(prompts.length == 1) {
- label = t.translate(prefix + '_prompt_value_label_single');
- } else {
- label = t.translate(prefix + '_prompt_value_label_multiple', {
- 'number': prompts.length
- });
- }
- }
- return label;
- },
- renderBurstCheckBox: function() {
- var burst = false;
- if(this.objectInformation && this.objectInformation.descriptor &&
- this.objectInformation.descriptor.options && this.objectInformation.descriptor.options.burst) {
- burst = this.objectInformation.descriptor.options.burst || false;
- }
- this.burstCheckbox = new CheckBox({
- 'id': 'schedule_burst_checkbox_' + this.uniqueId,
- 'el': this.$el.find('.schedule_burst_option_container'),
- 'name': 'schedule_burst_report',
- 'label': t.translate('schedule_burst_label'),
- 'ariaLabel': t.translate('schedule_burst_label'),
- 'checked': burst,
- 'controlOnLeft': true,
- 'onChange': function() {return;}
- });
- this.burstCheckbox.doRender();
- },
- close: function() {
- // Close off this pane
- this.slideout.hide();
- // temporary solution before glass overlay is ready
- $('.flyoutPane .pane-child').css('z-index', '-1');
- },
- /**
- * mark as in progress
- */
- setWorking: function() {
- this.$overlay = this.$el.find('.progress-overlay');
- this.$overlay.show();
- },
- /**
- * Show the view if hidden
- */
- setDone: function() {
- if(!this.$overlay) return;
- this.$overlay.hide();
- },
- _setIcons: function() {
- var icons = this.$el.find('.common_schedule_icon');
- for(var i = 0; i < icons.length; i++) {
- var $icon = $(icons[i]);
- Utils.setIcon($icon, 'common-' + $icon.data('icon'), t.translate('svg_expand_icon'));
- }
- },
- getScheduleType: function() {
- var capabilityType = this.getCapabilityScheduleType();
- if ( this.isEditMode ) {
- switch ( this.descriptor.scheduleInfo.type ) {
- case 'daily':
- case 'dailyWithIntradayRecurrence':
- return 'daily';
- case 'monthlyRelative':
- case 'monthlyAbsolute':
- case 'monthlyRelativeWithIntradayRecurrence':
- case 'monthlyAbsoluteWithIntradayRecurrence':
- return 'monthly';
- case 'yearlyRelative':
- case 'yearlyAbsolute':
- case 'yearlyRelativeWithIntradayRecurrence':
- case 'yearlyAbsoluteWithIntradayRecurrence':
- return 'yearly';
- case 'trigger':
- return 'trigger';
- default:
- return 'weekly';
- }
- } else {
- return capabilityType;
- }
- },
- getCapabilityScheduleType: function() {
- // Return the proper type according to capabilities for creating new
- // default to "weekly" whenever possible
- if ( this.glassContext.hasCapability('canUseSchedulingByWeek') ) {
- return 'weekly';
- }else {
- if ( this.glassContext.hasCapability('canUseSchedulingByDay') ) {
- return 'daily';
- }else if (this.glassContext.hasCapability('canUseSchedulingByMonth')) {
- return 'monthly';
- }else if (this.glassContext.hasCapability('canUseSchedulingByYear')) {
- return 'yearly';
- } else if (this.glassContext.hasCapability('canUseSchedulingByTrigger')) {
- return 'trigger';
- }
- }
- return 'weekly';
- },
- validate: function() {
- this.msgs = [];
- this.msgs = this.datetimeRangeCadencePicker.validate(this.msgs);
- if ( this.msgs.length > 0 ) {
- return false;
- }
- this.msgs = this.cadencePicker.validate(this.msgs);
- if ( this.msgs.length > 0 ) {
- return false;
- }
- // Burst
- var burst = this._getBurstValue();
- // Check delivery Options
- if(this.deliveryPicker) {
- var deliveryOptions = this.deliveryPicker.getDeliveryOptions();
- var $deliveryListDiv = this.$el.find('.delivery_list');
- $deliveryListDiv.removeAttr('aria-invalid aria-describedby');
- if (!burst) {
- if (deliveryOptions.email) {
- deliveryOptions.email.to = deliveryOptions.email.to? deliveryOptions.email.to : [];
- deliveryOptions.email.cc = deliveryOptions.email.cc? deliveryOptions.email.cc : [];
- deliveryOptions.email.bcc = deliveryOptions.email.bcc? deliveryOptions.email.bcc : [];
- if(deliveryOptions.email.to.length === 0 && deliveryOptions.email.cc.length === 0 && deliveryOptions.email.bcc.length === 0) {
- this.msgs.push(t.translate('schedule_delivery_no_email_recipients_error'));
- $deliveryListDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': this.msgs[0]
- });
- return false;
- }
- if (!deliveryOptions.email.emailAsAttachment && !deliveryOptions.email.emailAsURL) {
- this.msgs.push(t.translate('schedule_delivery_email_require_include'));
- $deliveryListDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': this.msgs[0]
- });
- return false;
- }
- }
- if (deliveryOptions.mobile) {
- if(typeof deliveryOptions.mobile.to === 'undefined' || deliveryOptions.mobile.to.length === 0) {
- this.msgs.push(t.translate('schedule_delivery_no_mobile_recipients_error'));
- $deliveryListDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': this.msgs[0]
- });
- return false;
- }
- }
- }
- if(deliveryOptions.print && $.trim(deliveryOptions.print.name) === '') {
- this.msgs.push(t.translate('schedule_delivery_printer_empty_error'));
- $deliveryListDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': this.msgs[0]
- });
- return false;
- }
- if(deliveryOptions.archive && $.trim(deliveryOptions.archive.filenameStub) === '') {
- this.msgs.push(t.translate('schedule_delivery_archive_name_empty_error'));
- $deliveryListDiv.attr({
- 'aria-invalid': 'true',
- 'aria-describedby': this.msgs[0]
- });
- return false;
- }
- }
- return this.msgs.length === 0;
- },
- /**
- * Show warning message for invalid time/date/form input by user
- */
- showWarningMessage: function() {
- this.warningMessage = this.$el.find('.invalid_input_warning_message');
- if (!this.warningMessage) {
- return;
- }else {
- this.warningMessage.text(this.msgs[0]);
- }
- this.warningMessage.show();
- },
- /**
- * Hide the warning message
- */
- hideWarningMessage: function() {
- if (!this.warningMessage) return;
- this.warningMessage.hide();
- },
- /** If this is a burst-enabled report, get whether or not to burst.
- * @return Whether the user wants this report bursted or not.
- * Returns false if the report cannot be bursted.
- */
- _getBurstValue: function() {
- var burst = false;
- if(this.canBurst && typeof this.burstCheckbox !== 'undefined') {
- burst = this.burstCheckbox.isChecked();
- }
- return burst;
- }
- });
- return scheduleView;
- });
|