123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: BI Glass
- *
- * Copyright IBM Corp. 2015, 2017
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'jquery', 'bi/commons/ui/properties/PropertyUIControl', 'doT', 'bi/commons/ui/View', 'bi/admin/globalparameters/view/controls/PromptControlFactory', 'bi/commons/ui/ButtonBar', 'bi/admin/nls/StringResource', 'bi/admin/common/utils/parameters/ParameterValues', 'bi/admin/globalparameters/helpers/SoapHelper', 'text!bi/admin/globalparameters/view/templates/DataSourcePromptPanel.html', 'text!bi/admin/globalparameters/view/templates/forward.xml'], function (_, $, PropertyUIControl, doT, View, PromptControlFactory, ButtonBar, StringResource, ParameterValues, SoapHelper, DataSourcePromptPanelTemplate, ForwardTemplate) {
- //NOSONAR
- 'use strict'; //NOSONAR
- var DataSourcePromptPanel = View.extend({
- init: function init(options) {
- DataSourcePromptPanel.inherited('init', this, arguments);
- _.extend(this, options);
- this._cancelled = true;
- },
- render: function render() {
- this.$el.css('height', '100%');
- var sHtml = doT.template(DataSourcePromptPanelTemplate)({});
- this.$el.html(sHtml);
- this._renderHeader();
- this._renderBody();
- this._renderFooter();
- },
- _renderHeader: function _renderHeader() {
- var promptControl = PromptControlFactory.transformNode(this.parameter, this.prompt_details.xml);
- var banner = new PropertyUIControl({
- 'el': this.$el.find('.gp-setvalues-header'),
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'items': [{
- 'name': 'dataSourcePanelTitle',
- 'value': promptControl.control.title,
- 'type': 'Banner',
- 'editable': false
- }, {
- 'type': 'Separator'
- }]
- });
- banner.render();
- },
- _renderBody: function _renderBody() {
- PromptControlFactory.render({
- '$el': this.$el.find('#parameterControls'),
- 'glassContext': this.glassContext,
- 'parameter': this.parameter,
- 'parameter_value': {},
- 'prompt_details': this.prompt_details,
- 'onValuesChange': this._onValuesChange.bind(this)
- });
- },
- _renderFooter: function _renderFooter() {
- this._buttonBar = new ButtonBar({
- buttons: [{
- 'id': 'gp-cancel',
- 'label': StringResource.get('cancel'),
- 'onSelect': this._onCancel.bind(this)
- }, {
- 'id': 'gp-ok',
- 'label': StringResource.get('ok'),
- 'onSelect': this._onOk.bind(this)
- }]
- });
- this._buttonBar.render().then(function (buttonBarHtml) {
- this.$el.find('#globalFiltersFooter').html(buttonBarHtml);
- this._enableOkButton(false);
- }.bind(this));
- },
- _enableOkButton: function _enableOkButton(enable) {
- var okButton = _.find(this._buttonBar.getButtonList(), function (button) {
- return button.id === 'gp-ok';
- });
- enable ? okButton.enable() : okButton.disable();
- },
- _onValuesChange: function _onValuesChange(valid, parameterValues) {
- this._parameter_values = parameterValues;
- this._enableOkButton(true);
- },
- _onOk: function _onOk() {
- this._cancelled = false;
- this._enableOkButton(false);
- var parameterValuesJSON = {
- 'credential': this._parameter_values
- };
- var parameterValues = ParameterValues.toXML(parameterValuesJSON);
- var conversation = '';
- _.each(this.prompt_details.$conversation.children(), function (node) {
- conversation += new XMLSerializer().serializeToString(node);
- });
- var loadTreeDataRequest = doT.template(ForwardTemplate)({
- 'cafContextId': this.glassContext.authInfo.cafContextId,
- 'conversation': conversation,
- 'conversationContext': new XMLSerializer().serializeToString(this.prompt_details.$tracking[0]),
- 'parameterValues': parameterValues
- });
- return this.glassContext.services.fetch.post('v1/reports', {
- 'headers': {
- 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/reportService/201703/.high'
- },
- 'contentType': 'text/xml; charset=UTF-8',
- 'data': loadTreeDataRequest
- }).then(function (response) {
- this.onOKCallback(SoapHelper.processResponse({
- id: this.prompt_details.report_id,
- defaultName: this.prompt_details.report
- }, response.data));
- this.slideout.hide();
- }.bind(this)).catch(function (response) {
- this.glassContext.appController.showToast(response.message, {
- type: 'error'
- });
- this._cancelled = true;
- this.slideout.hide();
- }.bind(this));
- },
- _onCancel: function _onCancel() {
- this.slideout.hide();
- }
- });
- return DataSourcePromptPanel;
- });
|