DataSourcePromptPanel.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: BI Glass
  6. *
  7. * Copyright IBM Corp. 2015, 2017
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. 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) {
  12. //NOSONAR
  13. 'use strict'; //NOSONAR
  14. var DataSourcePromptPanel = View.extend({
  15. init: function init(options) {
  16. DataSourcePromptPanel.inherited('init', this, arguments);
  17. _.extend(this, options);
  18. this._cancelled = true;
  19. },
  20. render: function render() {
  21. this.$el.css('height', '100%');
  22. var sHtml = doT.template(DataSourcePromptPanelTemplate)({});
  23. this.$el.html(sHtml);
  24. this._renderHeader();
  25. this._renderBody();
  26. this._renderFooter();
  27. },
  28. _renderHeader: function _renderHeader() {
  29. var promptControl = PromptControlFactory.transformNode(this.parameter, this.prompt_details.xml);
  30. var banner = new PropertyUIControl({
  31. 'el': this.$el.find('.gp-setvalues-header'),
  32. 'glassContext': this.glassContext,
  33. 'slideout': this.slideout,
  34. 'items': [{
  35. 'name': 'dataSourcePanelTitle',
  36. 'value': promptControl.control.title,
  37. 'type': 'Banner',
  38. 'editable': false
  39. }, {
  40. 'type': 'Separator'
  41. }]
  42. });
  43. banner.render();
  44. },
  45. _renderBody: function _renderBody() {
  46. PromptControlFactory.render({
  47. '$el': this.$el.find('#parameterControls'),
  48. 'glassContext': this.glassContext,
  49. 'parameter': this.parameter,
  50. 'parameter_value': {},
  51. 'prompt_details': this.prompt_details,
  52. 'onValuesChange': this._onValuesChange.bind(this)
  53. });
  54. },
  55. _renderFooter: function _renderFooter() {
  56. this._buttonBar = new ButtonBar({
  57. buttons: [{
  58. 'id': 'gp-cancel',
  59. 'label': StringResource.get('cancel'),
  60. 'onSelect': this._onCancel.bind(this)
  61. }, {
  62. 'id': 'gp-ok',
  63. 'label': StringResource.get('ok'),
  64. 'onSelect': this._onOk.bind(this)
  65. }]
  66. });
  67. this._buttonBar.render().then(function (buttonBarHtml) {
  68. this.$el.find('#globalFiltersFooter').html(buttonBarHtml);
  69. this._enableOkButton(false);
  70. }.bind(this));
  71. },
  72. _enableOkButton: function _enableOkButton(enable) {
  73. var okButton = _.find(this._buttonBar.getButtonList(), function (button) {
  74. return button.id === 'gp-ok';
  75. });
  76. enable ? okButton.enable() : okButton.disable();
  77. },
  78. _onValuesChange: function _onValuesChange(valid, parameterValues) {
  79. this._parameter_values = parameterValues;
  80. this._enableOkButton(true);
  81. },
  82. _onOk: function _onOk() {
  83. this._cancelled = false;
  84. this._enableOkButton(false);
  85. var parameterValuesJSON = {
  86. 'credential': this._parameter_values
  87. };
  88. var parameterValues = ParameterValues.toXML(parameterValuesJSON);
  89. var conversation = '';
  90. _.each(this.prompt_details.$conversation.children(), function (node) {
  91. conversation += new XMLSerializer().serializeToString(node);
  92. });
  93. var loadTreeDataRequest = doT.template(ForwardTemplate)({
  94. 'cafContextId': this.glassContext.authInfo.cafContextId,
  95. 'conversation': conversation,
  96. 'conversationContext': new XMLSerializer().serializeToString(this.prompt_details.$tracking[0]),
  97. 'parameterValues': parameterValues
  98. });
  99. return this.glassContext.services.fetch.post('v1/reports', {
  100. 'headers': {
  101. 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/reportService/201703/.high'
  102. },
  103. 'contentType': 'text/xml; charset=UTF-8',
  104. 'data': loadTreeDataRequest
  105. }).then(function (response) {
  106. this.onOKCallback(SoapHelper.processResponse({
  107. id: this.prompt_details.report_id,
  108. defaultName: this.prompt_details.report
  109. }, response.data));
  110. this.slideout.hide();
  111. }.bind(this)).catch(function (response) {
  112. this.glassContext.appController.showToast(response.message, {
  113. type: 'error'
  114. });
  115. this._cancelled = true;
  116. this.slideout.hide();
  117. }.bind(this));
  118. },
  119. _onCancel: function _onCancel() {
  120. this.slideout.hide();
  121. }
  122. });
  123. return DataSourcePromptPanel;
  124. });