ParameterValuesPane.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. 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) {
  9. 'use strict'; //NOSONAR
  10. var RoleParametersValuesPane = ContentView.extend({
  11. init: function init(options) {
  12. RoleParametersValuesPane.inherited('init', this, arguments);
  13. _.extend(this, options);
  14. this._parameter_values = null;
  15. this._workingAnimationDiv = Utils.getLoadingAnimation(1);
  16. },
  17. render: function render() {
  18. this.$el.empty();
  19. this.$el.css('height', '100%');
  20. var sHtml = doT.template(SetParameterValuesTemplate)({
  21. 'title': StringResource.get('setParameterValues'),
  22. 'no_values_message': StringResource.get('noGlobalParameterValues')
  23. });
  24. this.$el.html(sHtml);
  25. this._showLoadingSVG();
  26. return Promise.all([this._renderHeader(), this._renderFooter(), this._renderControl()]);
  27. },
  28. _renderHeader: function _renderHeader() {
  29. var banner = new PropertyUIControl({
  30. 'el': this.$el.find('#admin-prompt-values-header'),
  31. 'glassContext': this.glassContext,
  32. 'slideout': this.slideout,
  33. 'items': this._getHeaderItems()
  34. });
  35. return banner.render();
  36. },
  37. _getHeaderItems: function _getHeaderItems() {
  38. var items = [{
  39. 'name': 'parameterName',
  40. 'label': '',
  41. 'value': StringResource.get('setParameterValues'),
  42. 'type': 'Banner',
  43. 'editable': false
  44. }, {
  45. 'type': 'Separator'
  46. }];
  47. return items;
  48. },
  49. _renderFooter: function _renderFooter() {
  50. this._buttonBar = new ButtonBar({
  51. buttons: [{
  52. 'id': 'gp-apply',
  53. 'label': StringResource.get('apply'),
  54. 'onSelect': this._applyParameterValues.bind(this),
  55. 'disabled': true
  56. }, {
  57. 'id': 'gp-close',
  58. 'label': StringResource.get('clear'),
  59. 'onSelect': this._clearParameterValues.bind(this),
  60. 'disabled': true,
  61. 'class': 'gp-secondaryButton'
  62. }]
  63. });
  64. return this._buttonBar.render().then(function (buttonBarHtml) {
  65. this.$el.find('#admin-prompt-control-footer').html(buttonBarHtml);
  66. this._updateApplyButton(false);
  67. }.bind(this));
  68. },
  69. _clearParameterValues: function _clearParameterValues() {
  70. if (this.current_parameter_value) {
  71. this.current_parameter_value.values = [];
  72. }
  73. if (this._parameter_value) {
  74. this._parameter_value.values = [];
  75. }
  76. if (this.onApply) {
  77. this.onApply(this.parameter, this.current_parameter_value);
  78. }
  79. this._hideEmptyContent();
  80. this.$el.empty();
  81. this.render();
  82. },
  83. _updateApplyButton: function _updateApplyButton(enable) {
  84. _.each(this._buttonBar.getButtonList(), function (button) {
  85. if (button.id === 'gp-apply') {
  86. enable === true ? button.enable() : button.disable();
  87. }
  88. }.bind(this));
  89. },
  90. _showLoadingSVG: function _showLoadingSVG() {
  91. var $waitContainer = this.$el.find('#gp-waitContainer');
  92. $waitContainer.append(this._workingAnimationDiv);
  93. $waitContainer.css('display', 'block');
  94. },
  95. _hideLoadingSVG: function _hideLoadingSVG() {
  96. var $waitContainer = this.$el.find('#gp-waitContainer');
  97. $waitContainer.css('display', 'none');
  98. },
  99. _renderControl: function _renderControl() {
  100. this._sendCollectParameterValuesRequest().then(function (response) {
  101. this._processCollectParameterValuesResponse(response);
  102. return true;
  103. }.bind(this));
  104. },
  105. _sendCollectParameterValuesRequest: function _sendCollectParameterValuesRequest() {
  106. if (this.activeCollectParameterValuesResponse) {
  107. return Promise.resolve(this.activeCollectParameterValuesResponse);
  108. } else {
  109. return new CollectParameterValues({
  110. 'glassContext': this.glassContext,
  111. 'parameter': this.parameter,
  112. 'parameterValues': this.requestParameterValues
  113. }).get();
  114. }
  115. },
  116. _processCollectParameterValuesResponse: function _processCollectParameterValuesResponse(response) {
  117. if (response && (response.type === 'xml' && response.xml || response.type === 'json' && response.json)) {
  118. // check to see if we've hit a data source prompt, if so, show the data source panel
  119. var dataSourcePrompts = $(response.xml).find('selectDataSourceSignon');
  120. if (dataSourcePrompts.length > 0) {
  121. this._showDataSourcePromptPanel(response);
  122. } else {
  123. this.cacheCollectParameterValuesResponse(this.parameter, response);
  124. this._hideLoadingSVG();
  125. this._hideEmptyContent();
  126. PromptControlFactory.render({
  127. '$el': this.$el.find('#gp-react-div'),
  128. 'glassContext': this.glassContext,
  129. 'parameter': this.parameter,
  130. 'parameter_value': this.current_parameter_value,
  131. 'prompt_details': response,
  132. 'onValuesChange': this._onValuesChange.bind(this)
  133. });
  134. }
  135. } else {
  136. this._showEmptyContent();
  137. }
  138. },
  139. _showEmptyContent: function _showEmptyContent() {
  140. this._hideLoadingSVG();
  141. this.$el.find('.emptyTableContent').css('display', '');
  142. },
  143. _hideEmptyContent: function _hideEmptyContent() {
  144. this.$el.find('.emptyTableContent').css('display', 'none');
  145. },
  146. _showDataSourcePromptPanel: function _showDataSourcePromptPanel(collectParameterValuesResult) {
  147. this.glassContext.appController.showSlideOut({
  148. parent: this.slideout,
  149. overlay: true,
  150. content: {
  151. module: 'bi/admin/globalparameters/view/DataSourcePromptPanel',
  152. glassContext: this.glassContext,
  153. parameter: collectParameterValuesResult.parameters[0],
  154. prompt_details: collectParameterValuesResult,
  155. onOKCallback: this._processCollectParameterValuesResponse.bind(this),
  156. doCancel: this._showEmptyContent.bind(this)
  157. },
  158. onHide: function onHide() {
  159. if (this.contentView._cancelled === true) {
  160. this.contentView.doCancel();
  161. }
  162. }
  163. });
  164. },
  165. _onValuesChange: function _onValuesChange(valid, parameter_values, invalidateCache) {
  166. if (invalidateCache) {
  167. this.cacheCollectParameterValuesResponse(this.parameter, null);
  168. }
  169. this._updateApplyButton(valid);
  170. this._parameter_values = parameter_values;
  171. },
  172. _applyParameterValues: function _applyParameterValues() {
  173. if (this.onApply) {
  174. this.onApply(this.parameter, this._parameter_values);
  175. }
  176. this.slideout.hide();
  177. }
  178. });
  179. return RoleParametersValuesPane;
  180. });