"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("
" + StringResource.get('reset') + '
');
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 = $('');
$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;
});