1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- "use strict";
- /*
- * 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/content_apps/authoring/AuthoringHelper', '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', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/DropDown', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/CheckBox', 'ca_portal/features/mypreferences/MyPreferences', 'bi/schedule/views/PdfOptionsView', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl', 'bi/content_apps/utils/ContentStoreObject', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/content_apps/utils/C10Utils', 'bi/admin/nls/StringResource', 'ba-react-admin/ba-react-admin.min', 'text!bi/admin/job/importOptions.html'], function (AuthoringHelper, View, controler, $, Utils, t, Q, dot, template, _, moment, DateTimeRangeCadencePicker, DailyCadencePicker, WeeklyCadencePicker, MonthlyCadencePicker, YearlyCadencePicker, TriggerCadencePicker, FormatPicker, ScheduleDeliveryPicker, DropDown, CheckBox, MyPreferences, PdfOptionsView, PropertyUIControl, ContentStoreObject, ConfirmationDialog, C10Utils, StringResource, AdminReact, importTemplate) {
- 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 init(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: ['HTML']
- };
- _.extend(this, options); // set defaults
- this.canBurst = this.objectInformation.canBurst;
- this.currentRenderedCadenceType = 'weekly';
- this.outputLocale = [this.defaultLocale];
- this.msgs = [];
- this.warningMessage = null;
- this.parameterValues = [];
- 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
- };
- if (this.objectInformation.descriptor) {
- this.initScheduleDescriptor.parameters = this.objectInformation.descriptor.parameters;
- }
- if (this.objectInformation.type === 'jobDefinition') {
- this.initScheduleDescriptor.signonUPG = 'true';
- this.initScheduleDescriptor.reportUpgrade = 'keep';
- this.initScheduleDescriptor.importOptions = false;
- if (this.objectInformation.descriptor && this.objectInformation.descriptor.importOptions) {
- this.initScheduleDescriptor.signonUPG = this.objectInformation.descriptor.signonUPG;
- this.initScheduleDescriptor.reportUpgrade = this.objectInformation.descriptor.reportUpgrade;
- this.initScheduleDescriptor.importOptions = true;
- }
- }
- if (!options.objectInformation.descriptor.options.outputLocale) {
- options.objectInformation.descriptor.options.outputLocale = [this.defaultLocale];
- } else {
- this.outputLocale = options.objectInformation.descriptor.options.outputLocale;
- }
- var initDesc = this._prepareScheduleDescriptor();
- delete initDesc.scheduleInfo;
- delete initDesc.reportId;
- delete initDesc.reportType;
- options.selectedStep.setOptionsSnapshot(initDesc);
- },
- setFocus: function setFocus() {
- this.$el.focus();
- },
- _setEvents: function _setEvents() {
- this.$el.find('.schedule_primary_button').on('clicktap', function () {
- this._closeOpenChildren().then(function () {
- this.setWorking();
- this.hideWarningMessage();
- var scheduleDescriptor = this._prepareScheduleDescriptor();
- if (this.validate(scheduleDescriptor)) {
- // Create a new schedule
- if (!this.descriptor) {
- this._createOrUpdateScheduleRoutine(scheduleDescriptor); // Update an existing schedule
- } else {
- if (this._hasOnlyTimezoneBeenChanged(this.initScheduleDescriptor, scheduleDescriptor)) {
- var updateDialog = new ConfirmationDialog('warning', t.translate('schedule_update_confirm'), t.translate('schedule_update_timezone_difference_confirm_message'));
- updateDialog.confirm(function () {
- this._createOrUpdateScheduleRoutine(scheduleDescriptor);
- }.bind(this), this.setDone.bind(this));
- } else {
- this._createOrUpdateScheduleRoutine(scheduleDescriptor);
- }
- }
- } else {
- this.showWarningMessage();
- this.setDone();
- }
- }.bind(this)).done();
- }.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 _prepareScheduleDescriptor() {
- var reportId = this.objectInformation.id;
- var reportType = this.objectInformation.type;
- var 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
- if (this.datetimeRangeCadencePicker) {
- scheduleInfo = this.datetimeRangeCadencePicker.toDescriptor(scheduleInfo);
- } // grab cadencePicker info
- if (this.cadencePicker) {
- 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
- });
- return scheduleDescriptor;
- },
- _updateImportValues: function _updateImportValues(desc) {
- var $importOpts = this.$el.find('.importOptionsCheckbox');
- if ($importOpts.is(':checked')) {
- var $upgradReport = $(this.$el.find('.upgradeReport'));
- var $upgradID = $(this.$el.find('.updateID'));
- desc.importOptions = {
- upgradeReport: $upgradReport.is(':checked'),
- updateID: $upgradID.is(':checked')
- };
- }
- },
- _hasOnlyTimezoneBeenChanged: function _hasOnlyTimezoneBeenChanged(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 _closeOpenChildren() {
- /* 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; */
- return Promise.resolve();
- },
- _createOrUpdateSchedule: function _createOrUpdateSchedule(scheduleDescriptor) {
- var _self = this;
- controler.createSchedule(scheduleDescriptor, _self.glassContext).then(function () {
- // call callback if specified
- if (_self.onCreateOrUpdateCallback && typeof _self.onCreateOrUpdateCallback === 'function') {
- _self.onCreateOrUpdateCallback();
- }
- var message;
- if (_self.isEditMode) {
- message = t.translate('sch_update_success_msg');
- } else {
- message = t.translate('sch_create_success_msg');
- }
- _self.glassContext.appController.showToast(message, {
- newestOnTop: true,
- preventDuplicates: false,
- timeOut: 6000,
- extendedTimeOut: 1000
- });
- _self.setDone();
- _self.close();
- }).fail(function () {
- _self.setDone();
- }).done();
- },
- _createOrUpdateScheduleRoutine: function _createOrUpdateScheduleRoutine(scheduleDescriptor) {
- var _self = this; // Get user Credentials
- controler.getUserCredential(this.glassContext).then(function () {
- _self._createOrUpdateSchedule(scheduleDescriptor);
- }).fail(function () {
- // Getting user credentials failed; try creating them
- controler.createUserCredential(_self.glassContext).then(function () {
- _self._createOrUpdateSchedule(scheduleDescriptor);
- }).fail(function (promptInfo) {
- if (promptInfo) {
- // Creating user credentials failed; ask the user for them
- var myPreferences = new MyPreferences({
- glassContext: _self.glassContext
- });
- myPreferences.openCreateCredentialDialog(promptInfo.displayObjects).then(function () {
- _self._createOrUpdateSchedule(scheduleDescriptor);
- }).fail(function () {
- _self.setDone();
- });
- } else {
- // error, set done
- _self.setDone();
- }
- });
- });
- },
- /**
- * Render the new schedule view
- *
- */
- render: function render() {
- this.$el.closest('.root.flyoutPane').addClass('runOptionsSlideout');
- 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) || this.objectInformation.type === 'jobDefinition');
- if (this.canShowPrompt) {
- // For display render the prompt picker
- this.parameterValues = this.objectInformation.parameters ? 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 = {
- asset_name: _.escape(objectInformation.defaultName),
- schedule_panel_back: t.translate('schedule_panel_back_text'),
- schedule_panel_title: 'Run options',
- schedule_type_label: 'Select run options',
- 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: '',
- 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_name'),
- canShowPrompt: this.canShowPrompt
- };
- attributes.schedule_controls_description = t.translate('schedule_controls_description', {
- action1: attributes.schedule_create_btn,
- action2: attributes.schedule_cancel_btn
- });
- this.$el.addClass('runOptionsView');
- var items = [{
- type: 'Banner',
- backButton: this.slideout.overlay,
- value: StringResource.get('selectRunOptions')
- }];
- this._propertyUIControl = new PropertyUIControl({
- glassContext: this.glassContext,
- el: this.$el,
- closeCallback: this.close.bind(this),
- items: items
- });
- this._propertyUIControl.render().then(function () {
- return this._updateEmailDisplayNames(this.objectInformation.descriptor.options.delivery.email);
- }.bind(this)).then(function () {
- return this._updateEmailDisplayNames(this.objectInformation.descriptor.options.delivery.mobile);
- }.bind(this)).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 Promise.resolve();
- }.bind(this)).then(function () {
- if (this.showOptions) {
- if (this.objectInformation.type.indexOf('agentDefinition') !== -1) {
- var fmEl = this.$el.find('.schedule_output_format_picker');
- var deEl = this.$el.find('.schedule_delivery_picker');
- var lnEl = this.$el.find('.schedule_language_picker');
- var pdfEl = this.$el.find('.schedule_pdf_options_picker');
- fmEl.css('display', 'none');
- deEl.css('display', 'none');
- lnEl.css('display', 'none');
- pdfEl.css('display', 'none');
- }
- this.renderOutputFormatPicker();
- var formatRestrictedTypes = ['powerPlay8Report', 'powerPlay8ReportView', 'interactiveReport', 'interactiveReportView'];
- var typeForFormat = this.objectInformation.type;
- if (this.objectInformation.type === 'reportView') {
- typeForFormat = this.objectInformation.base[0].type;
- }
- if (formatRestrictedTypes.indexOf(typeForFormat) !== -1) {
- var formartButton = this.$el.find('.schedule_output_format_picker .schedule_form_input button');
- formartButton.css('display', 'none');
- var aTog = this.$el.find('.schedule_output_format_picker');
- aTog.off('primaryaction');
- this.$el.find('.schedule_output_format_picker').removeClass('options_picker');
- }
- 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.$el.find('.classicViewLink').remove();
- this.$el.find('.new_schedule_panel_button').remove();
- 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._renderResetLink();
- return Promise.resolve();
- }.bind(this));
- },
- _renderResetLink: function _renderResetLink() {
- if (AdminReact.JobUIStore.isEditJobOptionsDialogOpen && AdminReact.JobObjectStore.hasOptions) {
- var $entryPoint = $($.find('.runOptionsView .banner'));
- var el = $entryPoint.append("<div tabindex='0' class='resetButton' style='margin-left: auto;><svg focusable='false' class='ba-common-svgIcon is-small' style='vertical-align: bottom;'><use xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#" + AdminReact.reset16.id + "'></use></svg><span style='padding-left: 16px'>" + StringResource.get('reset') + '</span></div>');
- el.find('.resetButton').on('primaryaction', function (e) {
- e.preventDefault();
- AdminReact.JobUIStore.clearEditDialog();
- this.slideout.hide();
- AdminReact.JobObjectStore.clearOptions();
- }.bind(this));
- }
- },
- setLanguageLabel: function setLanguageLabel() {
- this.glassContext.services.config.getContentLocales().then(function (contentLocales) {
- this.supportedContentLocales = contentLocales;
- var languageLabel = t.translate('schedule_no_languages_label');
- if (this.isEditMode) {
- if (this.objectInformation.descriptor.options.outputLocale) {
- this.outputLocale = 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();
- },
- _updateEmailDisplayNames: function _updateEmailDisplayNames(emailSection) {
- var mailPromises = [];
- var getDisplayNamesForAccount = function (account) {
- if (account.address.indexOf('CAMID(') === 0) {
- var options = {
- dataType: 'json',
- type: 'GET',
- data: {},
- url: 'v1/search_path?searchPath=' + account.address + '&fields=defaultName',
- cache: false
- };
- mailPromises.push(this.glassContext.services.ajax.ajax(options));
- }
- }.bind(this);
- var allRecipients = [];
- if (emailSection) {
- if (emailSection.to) {
- allRecipients = allRecipients.concat(emailSection.to);
- }
- if (emailSection.cc) {
- allRecipients = allRecipients.concat(emailSection.cc);
- }
- if (emailSection.bcc) {
- allRecipients = allRecipients.concat(emailSection.bcc);
- }
- }
- allRecipients.forEach(getDisplayNamesForAccount);
- if (mailPromises.length === 0) {
- return Promise.resolve();
- }
- return Promise.all(mailPromises).then(function (result) {
- var count = 0;
- allRecipients.forEach(function (account) {
- if (account.address.indexOf('CAMID(') === 0) {
- account.defaultName = result[count].data[0].defaultName;
- count += 1;
- }
- });
- return Promise.resolve();
- });
- },
- shouldShowMobile: function shouldShowMobile() {
- var mobileTypes = ['interactiveReport', 'report', 'query', 'analysis', 'jobDefinition'];
- return mobileTypes.indexOf(this.objectInformation.type) !== -1 || this.objectInformation.type === 'reportView' && mobileTypes.indexOf(this.objectInformation.base[0].type) !== -1;
- },
- _getRawOptionsForSaveToS3: function _getRawOptionsForSaveToS3() {
- var rawOptions = [];
- _.find(this.selectedStep.options, function (item) {
- if (item.name === 'runOptionEnum#saveToCloud' || item.name === 'runOptionEnum#cloudName') {
- rawOptions.push(item);
- }
- });
- return rawOptions;
- },
- _getReportName: function _getReportName() {
- if (this.selectedStep.options) {
- _.find(this.selectedStep.options, function (item) {
- if (item.name === 'runOptionEnum#cloudName') {
- return item.value;
- }
- });
- }
- if (this.selectedStep.stepObject) {
- return this.selectedStep.stepObject[0].defaultName;
- }
- return null;
- },
- renderDeliveryPicker: function renderDeliveryPicker() {
- 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: this._getReportName() ? this._getReportName() : name,
- deliveryOptions: deliveryOptions,
- 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),
- rawOptions: this._getRawOptionsForSaveToS3()
- }); // first need to update any email recipeints
- this.deliveryPicker.render();
- } catch (e) {
- console.log('There was an error initializing the DeliveryPicker.', e);
- }
- },
- renderPdfOptionsView: function renderPdfOptionsView() {
- 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 _saveExistingScheduleInitialState() {
- // Cache data of the existing schedule
- if (this.isEditMode) {
- this.initScheduleDescriptor = this._prepareScheduleDescriptor();
- }
- },
- _renderTypeSelector: function _renderTypeSelector(schType) {
- var schOptions = [];
- if (this.glassContext.hasCapability('canUseSchedulingByDay')) {
- schOptions.push({
- label: t.translate('daily_label'),
- value: 'daily',
- selected: schType == 'daily'
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByWeek')) {
- schOptions.push({
- label: t.translate('weekly_label'),
- value: 'weekly',
- selected: schType == 'weekly'
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByMonth')) {
- schOptions.push({
- label: t.translate('monthly_label'),
- value: 'monthly',
- selected: schType == 'monthly'
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByYear')) {
- schOptions.push({
- label: t.translate('yearly_label'),
- value: 'yearly',
- selected: schType == 'yearly'
- });
- }
- if (this.glassContext.hasCapability('canUseSchedulingByTrigger')) {
- schOptions.push({
- label: t.translate('trigger_label'),
- value: 'trigger',
- selected: schType == 'trigger'
- });
- }
- 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();
- },
- _renderImportOptions: function _renderImportOptions() {
- var $entryEl = $(this.$el.find('.new_schedule_panel_footer'));
- var $ioEl = $('<div style="margin: 0px !important; padding: 0px;" class="ImportOptions"/>');
- $entryEl.prev().prepend($ioEl);
- var htmlGenerator = dot.simpleTemplate(importTemplate);
- var attributes = {
- descriptor: this.initScheduleDescriptor,
- strings: {
- importOptions: StringResource.get('importOptions'),
- reportSpecification: StringResource.get('reportSpecUpgrade'),
- upgradeReport: StringResource.get('upgradeReportLabel'),
- keepReport: StringResource.get('doNotUpgradeReportLabel'),
- storeID: StringResource.get('importStoreIDLabel'),
- assignNew: StringResource.get('assignNewStoreIDLabel'),
- keepID: StringResource.get('keepStoreIDLabel')
- }
- };
- var $content = $(htmlGenerator(attributes));
- $ioEl.append($content);
- $(this.$el.find('.importOptionsCheckbox')).on('click', this._toggleImportOptions.bind(this));
- },
- _toggleImportOptions: function _toggleImportOptions(evt) {
- var $impSec = $(this.$el.find('.importOptionsSection'));
- if (evt.currentTarget.checked) {
- $impSec.css('display', 'block');
- } else {
- $impSec.css('display', 'none');
- }
- },
- _toggleCadenceView: function _toggleCadenceView(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 renderDateTimeRangeCadencePicker() {
- 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 renderCadencePicker(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 renderOutputFormatPicker() {
- var _self = this;
- var formats = [];
- if (this.isEditMode) {
- if (this.objectInformation.descriptor.options.outputFormat) {
- formats = this.objectInformation.descriptor.options.outputFormat.slice();
- }
- }
- var updatedList = _.reject(formats, function (aFormat) {
- return !AuthoringHelper.userCanGenerateFormat(this.glassContext, aFormat);
- }.bind(this));
- if (updatedList.length === 0) {
- updatedList.push('HTML');
- }
- formats = updatedList;
- 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: 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'),
- glassContext: this.glassContext,
- slideoutparent: this.slideout,
- overlay: false
- });
- this.outputFormatPicker.render();
- } catch (e) {
- console.log('There was an error initializing the FormatPicker.', e);
- }
- },
- _renderPromptRowForReport: function _renderPromptRowForReport() {
- 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;
- }
- }
- 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(_self.parameterValues),
- parameters: _self.parameterValues,
- hasPermission: _self.objectInformation.hasPermission,
- clearCallback: function clearCallback() {
- if (_self.parameterValues.length > 0) {
- _self._updatePromptValueLabel();
- }
- },
- editCallback: _self._updatePromptValueLabel.bind(_self)
- }
- });
- }).done();
- });
- this._updatePromptValueLabel(this.parameterValues);
- },
- renderPromptRow: function renderPromptRow() {
- if (this.canShowPrompt) {
- return this._renderPromptRowForReport();
- }
- },
- _updatePromptValueLabel: function _updatePromptValueLabel(prompts) {
- // Reset the parameterValues to empty on Clear callback
- // need to copy the values of the prompts otherwise ie will be
- // displeased
- var promptsCP = JSON.parse(JSON.stringify(prompts));
- this.parameterValues = prompts ? promptsCP : [];
- var $promptValueLabel = this.$el.find('.currentPromptValues');
- $promptValueLabel.text(this._getPromptValueLabel());
- },
- _getPromptValueLabel: function _getPromptValueLabel() {
- var label = t.translate('schedule_prompt_value_label_default');
- if (this.parameterValues && this.parameterValues.length > 0) {
- if (this.parameterValues.length == 1) {
- label = t.translate('schedule_prompt_value_label_single');
- } else {
- label = t.translate('schedule_prompt_value_label_multiple', {
- number: this.parameterValues.length
- });
- }
- }
- return label;
- },
- renderBurstCheckBox: function renderBurstCheckBox() {
- 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 onChange() {}
- });
- this.burstCheckbox.doRender();
- },
- close: function close() {
- // 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 setWorking() {
- this.$overlay = this.$el.find('.progress-overlay');
- this.$overlay.show();
- },
- /**
- * Show the view if hidden
- */
- setDone: function setDone() {
- if (!this.$overlay) return;
- this.$overlay.hide();
- },
- _setIcons: function _setIcons() {
- 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 getScheduleType() {
- var capabilityType = this.getCapabilityScheduleType();
- if (this.isEditMode) {
- return 'weekly';
- } else {
- return capabilityType;
- }
- return capabilityType;
- },
- getCapabilityScheduleType: function getCapabilityScheduleType() {
- // 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 validate() {
- 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 showWarningMessage() {
- 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 hideWarningMessage() {
- 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 _getBurstValue() {
- var burst = false;
- if (this.canBurst && typeof this.burstCheckbox !== 'undefined') {
- burst = this.burstCheckbox.isChecked();
- }
- return burst;
- },
- onHide: function onHide() {
- AdminReact.JobUIStore.editJobOboptionsDialogClosed(this._prepareScheduleDescriptor(), this.glassContext);
- }
- });
- return scheduleView;
- });
|