"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * 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', 'bi/admin/nls/StringResource', 'doT', 'bi/content_apps/common/ContentListPageView', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/ui/ButtonBar', 'bi/admin/common/utils/parameters/CollectParameterValues', 'bi/admin/globalparameters/view/controls/PromptControlFactory', 'text!bi/admin/account/templates/SetParameterValuesTemplate.html', 'bi/commons/utils/Utils'], function (_, StringResource, doT, ContentView, PropertyUIControl, ButtonBar, CollectParameterValues, PromptControlFactory, SetParameterValuesTemplate, Utils) { 'use strict'; //NOSONAR var RoleParametersValuesPane = ContentView.extend({ init: function init(options) { RoleParametersValuesPane.inherited('init', this, arguments); _.extend(this, options); this._parameter_values = null; this._workingAnimationDiv = Utils.getLoadingAnimation(1); }, render: function render() { this.$el.empty(); this.$el.css('height', '100%'); var sHtml = doT.template(SetParameterValuesTemplate)({ 'title': StringResource.get('setParameterValues'), 'no_values_message': StringResource.get('noGlobalParameterValues') }); this.$el.html(sHtml); this._showLoadingSVG(); return Promise.all([this._renderHeader(), this._renderFooter(), this._renderControl()]); }, _renderHeader: function _renderHeader() { var banner = new PropertyUIControl({ 'el': this.$el.find('#admin-prompt-values-header'), 'glassContext': this.glassContext, 'slideout': this.slideout, 'items': this._getHeaderItems() }); return banner.render(); }, _getHeaderItems: function _getHeaderItems() { var items = [{ 'name': 'parameterName', 'label': '', 'value': StringResource.get('setParameterValues'), 'type': 'Banner', 'editable': false }, { 'type': 'Separator' }]; return items; }, _renderFooter: function _renderFooter() { this._buttonBar = new ButtonBar({ buttons: [{ 'id': 'gp-apply', 'label': StringResource.get('apply'), 'onSelect': this._applyParameterValues.bind(this), 'disabled': true }, { 'id': 'gp-close', 'label': StringResource.get('clear'), 'onSelect': this._clearParameterValues.bind(this), 'disabled': true, 'class': 'gp-secondaryButton' }] }); return this._buttonBar.render().then(function (buttonBarHtml) { this.$el.find('#admin-prompt-control-footer').html(buttonBarHtml); this._updateApplyButton(false); }.bind(this)); }, _clearParameterValues: function _clearParameterValues() { if (this.current_parameter_value) { this.current_parameter_value.values = []; } if (this._parameter_value) { this._parameter_value.values = []; } if (this.onApply) { this.onApply(this.parameter, this.current_parameter_value); } this._hideEmptyContent(); this.$el.empty(); this.render(); }, _updateApplyButton: function _updateApplyButton(enable) { _.each(this._buttonBar.getButtonList(), function (button) { if (button.id === 'gp-apply') { enable === true ? button.enable() : button.disable(); } }.bind(this)); }, _showLoadingSVG: function _showLoadingSVG() { var $waitContainer = this.$el.find('#gp-waitContainer'); $waitContainer.append(this._workingAnimationDiv); $waitContainer.css('display', 'block'); }, _hideLoadingSVG: function _hideLoadingSVG() { var $waitContainer = this.$el.find('#gp-waitContainer'); $waitContainer.css('display', 'none'); }, _renderControl: function _renderControl() { this._sendCollectParameterValuesRequest().then(function (response) { this._processCollectParameterValuesResponse(response); return true; }.bind(this)); }, _sendCollectParameterValuesRequest: function _sendCollectParameterValuesRequest() { if (this.activeCollectParameterValuesResponse) { return Promise.resolve(this.activeCollectParameterValuesResponse); } else { return new CollectParameterValues({ 'glassContext': this.glassContext, 'parameter': this.parameter, 'parameterValues': this.requestParameterValues }).get(); } }, _processCollectParameterValuesResponse: function _processCollectParameterValuesResponse(response) { if (response && (response.type === 'xml' && response.xml || response.type === 'json' && response.json)) { // check to see if we've hit a data source prompt, if so, show the data source panel var dataSourcePrompts = $(response.xml).find('selectDataSourceSignon'); if (dataSourcePrompts.length > 0) { this._showDataSourcePromptPanel(response); } else { this.cacheCollectParameterValuesResponse(this.parameter, response); this._hideLoadingSVG(); this._hideEmptyContent(); PromptControlFactory.render({ '$el': this.$el.find('#gp-react-div'), 'glassContext': this.glassContext, 'parameter': this.parameter, 'parameter_value': this.current_parameter_value, 'prompt_details': response, 'onValuesChange': this._onValuesChange.bind(this) }); } } else { this._showEmptyContent(); } }, _showEmptyContent: function _showEmptyContent() { this._hideLoadingSVG(); this.$el.find('.emptyTableContent').css('display', ''); }, _hideEmptyContent: function _hideEmptyContent() { this.$el.find('.emptyTableContent').css('display', 'none'); }, _showDataSourcePromptPanel: function _showDataSourcePromptPanel(collectParameterValuesResult) { this.glassContext.appController.showSlideOut({ parent: this.slideout, overlay: true, content: { module: 'bi/admin/globalparameters/view/DataSourcePromptPanel', glassContext: this.glassContext, parameter: collectParameterValuesResult.parameters[0], prompt_details: collectParameterValuesResult, onOKCallback: this._processCollectParameterValuesResponse.bind(this), doCancel: this._showEmptyContent.bind(this) }, onHide: function onHide() { if (this.contentView._cancelled === true) { this.contentView.doCancel(); } } }); }, _onValuesChange: function _onValuesChange(valid, parameter_values, invalidateCache) { if (invalidateCache) { this.cacheCollectParameterValuesResponse(this.parameter, null); } this._updateApplyButton(valid); this._parameter_values = parameter_values; }, _applyParameterValues: function _applyParameterValues() { if (this.onApply) { this.onApply(this.parameter, this._parameter_values); } this.slideout.hide(); } }); return RoleParametersValuesPane; });