ThemesTab.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2016, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyTabView', 'bi/admin/common/Uploader', 'bi/admin/common/services/ExtensionService', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/common/actions/ThemeListActionController', 'react', 'react-dom', 'ba-react-admin/ba-react-admin.min'], function (_, StringResource, View, Uploader, ExtensionService, PropertyUIControl, ThemeListActionController, React, ReactDOM, AdminReact) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var ThemesTab = View.extend({
  12. init: function init(options) {
  13. ThemesTab.inherited('init', this, arguments);
  14. this.showTitle = false;
  15. _.extend(this, options);
  16. },
  17. remove: function remove() {
  18. this.cleanUpReact();
  19. },
  20. cleanUpReact: function cleanUpReact() {
  21. if (this.$el) {
  22. ReactDOM.unmountComponentAtNode(this.$el.find('.themesListPaneRoot')[0]);
  23. }
  24. },
  25. render: function render() {
  26. this.actController = new ThemeListActionController();
  27. var aRoot = this.$el.append("<div ><div class='themesListPaneRoot'></div></div>");
  28. var themeListView = React.createElement(AdminReact.ThemeListView, {
  29. glassContext: this.glassContext,
  30. StringResource: StringResource,
  31. parent: this
  32. });
  33. ReactDOM.render(themeListView, this.$el.find('.themesListPaneRoot')[0]);
  34. return Promise.resolve(this);
  35. },
  36. _getContentBarAccesibleLabel: function _getContentBarAccesibleLabel() {
  37. return StringResource.get('themes');
  38. },
  39. /**
  40. * Prepares the uploader and calls for an upload, then refreshes the themes list
  41. */
  42. uploadTheme: function uploadTheme() {
  43. if (_.isUndefined(this.extensionService)) {
  44. var esOptions = {
  45. 'glassContext': this.glassContext
  46. };
  47. this.extensionService = new ExtensionService(esOptions);
  48. }
  49. var ajaxOptions = {
  50. 'isUpload': true,
  51. 'type': 'theme',
  52. 'tenantID': this.tenantID
  53. };
  54. var uploader = new Uploader({
  55. '$el': this.$el,
  56. 'glassContext': this.glassContext,
  57. 'ajax': this.extensionService.updateOrUpload.bind(this.extensionService),
  58. 'ajaxOptions': ajaxOptions
  59. });
  60. return uploader.doUpload().then(function () {
  61. AdminReact.ThemeListStore.readThemes(this.glassContext);
  62. }.bind(this));
  63. }
  64. });
  65. return ThemesTab;
  66. });