123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /**
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * 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/commons/ui/View',
- 'jquery',
- 'bi/sharecommon/utils/simpledoT',
- 'bi/sharecommon/utils/translator',
- 'text!bi/schedule/templates/PromptPickerView.html',
- 'bi/commons/utils/ContentFormatter',
- 'bi/glass/common/ui/ProgressToast'
- ], function (View, $, dot, t, viewTemplate, stringFormatter, ProgressToast) {
- var view = View.extend({
- /** Allows for selecting parameter values for a particular report.
- * Uses the old UI. Parameters:
- * $el: Location where this View will display selected parameter values,
- * in the "name: value" format.
- * $toggler: link/button that launches the 'prompting dance'
- * reportId: the report to prompt for
- * values: Initial values to display. Not used to select the defaults in the prompting dance
- * glassContext: the glassContext
- */
- init: function (options) {
- view.inherited('init', this, arguments);
- $.extend(this, options);
- },
- /**
- * Calls stopPropagation() on an event when clicking on element that does not have '.prompt-overlay' as an ancestor
- * @param {boolean} ignore - if 'true', does not trigger stopPropagation() even if '.prompt-overlay' isn't an ancestor of the clicked element
- */
- setOverlayEvents: function (ignore) {
- $(document).on('clicktap', function (e) {
- var $event = $(e.target);
- var $p = $event.closest('.prompt-overlay');
- if ($p.length == 0 && !ignore) {
- e.stopPropagation();
- this.close();
- }
- }.bind(this));
- this.$promptOverlay.find('.prompt-iframe').load(function () {
- this.$promptOverlay.find('.prompt-iframe').contents().find('.dialogHeader a').on('clicktap', function (_e) {
- this.close();
- }.bind(this));
- // in case of error, an 'OK' button appears, whose default behaviour is to do a
- // history.back() (!) Turn that off and close the window instead.
- this.$promptOverlay.find('.prompt-iframe').contents().find('#cmdOK').prop('onclick', null).off('click').on('clicktap', function (e) {
- e.stopPropagation();
- this.close();
- }.bind(this));
- // this.show();
- }.bind(this));
- },
- setEvents: function () {
- this.$toggler.on('primaryaction', function () {
- this.showPromptOverlay();
- }.bind(this));
- },
- close: function () {
- this.$promptOverlay.remove();
- },
- show: function () {
- if (this.$promptOverlay.css('visibility') == 'hidden') {
- // Remove waitForPromptsProgressToast when displaying promptOverlay
- if (this.waitForPromptsProgressToast) {
- this.waitForPromptsProgressToast.remove(0);
- }
- this.$promptOverlay.css('visibility', 'visible');
- }
- },
- // prompting call back - NB* APAR 145884 depends on this function remaining here and not being replaced by promptFnOkCallback.
- // this is to avoid nested bound function calls in RS's prod/webcontent/bi/js/classicviewer/cvContentView.js
- // ... which for unknown reasons cause input object lockup/javascript problems in IE11 only.
- onPromptOK: function() {
- this.glassContext.getSvc('.Prompting').then(function (promptSvc) {
- promptSvc.getPromptAnswers(this.id).then(function(values) {
- this.applyPromptValues(values);
- }.bind(this));
- }.bind(this));
- },
-
- getParameterValues: function () {
- return this.values;
- },
- _createProgressToast: function (options) {
- return new ProgressToast(options);
- },
- showPromptOverlay: function () {
- var htmlGenerator = dot.simpleTemplate(viewTemplate);
- var _self = this;
- return this.glassContext.getSvc('.Prompting').then(function (promptSvc) {
- var options = { 'noCancelBtn': true, 'noHideBtn': true, 'noDetailsBtn': true };
- this.waitForPromptsProgressToast = this._createProgressToast(options);
- this.waitForPromptsProgressToast.show(t.translate('parameters_generating_inputs'));
- this.waitForPromptsProgressToast.indefinite(t.translate('parameters_generating_inputs'));
- return promptSvc.getPromptPageInfo(this.reportId);
- }.bind(this))
- .then(function (promptInfo) {
- this.id = promptInfo.id;
- // Use interactive report viewer to retrieve parameter values
- window.promptContext = {
- promptContext: {
- requestType: 'collectParameterValues',
- parameters: this.useValues ? this.values : null,
- promptFnOkCallback: function (values) {
- this.applyPromptValues(values);
- }.bind(_self),
- promptFnOkCallback1: this.onPromptOK.bind(_self),
- promptFnErrorCallback: function (values) {
- var errorMessage = values.code + ' ' + values.message;
- if (this.waitForPromptsProgressToast) {
- this.waitForPromptsProgressToast.remove();
- }
- _self.glassContext.appController.showToast(errorMessage, {
- 'type': 'error',
- 'preventDuplicates': true
- });
- }.bind(_self),
- promptFnCancelCallback: function (_values) {
- // Cancel clicked on prompt overlay, remove ProgressToast if present
- if (this.waitForPromptsProgressToast) {
- this.waitForPromptsProgressToast.remove();
- }
- }.bind(_self),
- // promptOpener has to have a function close()
- promptOpener: _self
- }
- };
- if (promptInfo && promptInfo._meta) {
- var isAdvancedViewer = (promptInfo.runInAdvancedViewer === true) || (promptInfo.base && promptInfo.base[0] && (promptInfo.base[0].runInAdvancedViewer === true));
- var perspective = '&perspective=' + (isAdvancedViewer ? 'authoring' : 'classicviewer');
- // Report output language will override content locale iff only one report output language is selected, otherwise no.
- var overrideContentLocale = (_self.languageOptions && _self.languageOptions.length === 1) ? '&contentLocale=' + _self.languageOptions[0] : '';
- promptInfo.url = promptInfo._meta.links.path.url;
- promptInfo.url = promptInfo.url.replace('v1/path?path=', '?pathRef=') + perspective + '&format=HTML&a11y=true&Download=false&prompt=true&ui_appbar=false&ui_navbar=false&launchParametersRef=promptContext' + overrideContentLocale;
- }
- if (!promptInfo.url) {
- this.glassContext.appController.showErrorMessage(t.translate('schedule_prompting_wrong_url'), t.translate('error_label_share'));
- } else {
- var path = promptInfo.url;
- var title = t.translate('schedule_prompting_iframe_title');
- var attributes = {
- prompt_path: path,
- prompt_title: title
- };
- $('body').append(htmlGenerator(attributes));
- this.$promptOverlay = $('body').find('.prompt-overlay');
- if (this.$promptOverlay) {
- this.setOverlayEvents(true);
- }
- }
- }.bind(this))
- .catch(function () {
- /* swallow */
- });
- },
- render: function () {
- this.updateParameterList();
- // in update mode the permissions are passed
- if (this.hasPermission && !this.hasPermission.write && this.hasPermission.read) {
- this.$toggler.prop('disabled', true);
- }
- this.setEvents();
- return Promise.resolve(this);
- },
- applyPromptValues: function (values) {
- this.values = values;
- this.updateParameterList();
- if (this.onFinish && typeof this.onFinish === 'function') {
- this.onFinish();
- }
- if (this.values.length === 0) {
- // No prompts to retrieve, set ProgressToast as complete
- if (this.waitForPromptsProgressToast) {
- this.waitForPromptsProgressToast.setComplete(100, {
- isComplete: true,
- completeMsg: t.translate('parameters_none_in_report')
- });
- }
- } else {
- // Prompt values exist, but ProgressToast may not have been removed by show() because report has default values and no prompt overlay
- if (this.waitForPromptsProgressToast) {
- this.waitForPromptsProgressToast.setComplete(100, { isComplete: true });
- }
- }
- },
- updateParameterList: function () {
- var parameters = this.values;
- var toDisplay = '';
- for (var i = 0; i < parameters.length; i++) {
- var parameter = '';
- var displayValues = '';
- var name = parameters[i].name;
- var values = parameters[i].value;
- if (!name)
- continue;
- if (!values)
- continue;
- for (var j = 0; j < values.length; j++) {
- if (!values[j].type)
- continue;
- var value = '';
- switch (values[j].type) {
- case 'rangeParmValueItem':
- case 'boundRangeParmValueItem':
- case 'unboundedStartRangeParmValueItem':
- case 'unboundedEndRangeParmValueItem':
- {
- if (values[j].start && values[j].end) {
- value = t.translate('parameter_range_start_end_label', {
- start: values[j].start.display
- ? values[j].start.display
- : values[j].start.use,
- end: values[j].end.display
- ? values[j].end.display
- : values[j].end.use
- });
- } else if (values[j].start) {
- value = t.translate('parameter_range_start_only_label', {
- start: values[j].start.display
- ? values[j].start.display
- : values[j].start.use
- });
- } else if (values[j].end) {
- value = t.translate('parameter_range_end_only_label', {
- end: values[j].end.display
- ? values[j].end.display
- : values[j].end.use
- });
- } else {
- value = t.translate('parameter_range_none_label');
- }
- break;
- }
- case 'simpleParmValueItem':
- {
- value = values[j].display
- ? values[j].display
- : values[j].use;
- break;
- }
- case 'hierarchicalParmValueItem':
- {
- break;
- }
- }
- if (value === '')
- continue;
- if (displayValues === '') {
- displayValues = value;
- } else {
- displayValues = displayValues + ', ' + value;
- }
- }
- parameter = name + ': ' + displayValues + '; ';
- toDisplay += parameter;
- }
- if (toDisplay === '') {
- var none = t.translate('parameter_no_values_set');
- this.$el.text(none);
- this.$el.attr('title', none);
- } else {
- this.$el.text(toDisplay);
- this.$el.attr('title', toDisplay);
- stringFormatter.middleShortenString(this.$el);
- }
- }
- });
- return view;
- });
|