PalettesTab.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. /**
  3.  * Licensed Materials - Property of IBM
  4.  * IBM Cognos Products: Cognos Analytics
  5.  * Copyright IBM Corp. 2018
  6.  * US Government Users Restricted Rights -
  7. * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8.  */
  9. define(['underscore', 'doT', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'text!bi/admin/system/templates/PalettesTabTemplate.html', 'react-dom', 'react', 'bi/commons/ui/properties/PropertyUIControl', 'authoring-common'], function (_, dot, BasePane, StringResource, template, ReactDOM, React, PropertyUIControl, authoring) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var PalettesTab = BasePane.extend({
  12. init: function init(options) {
  13. PalettesTab.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. },
  16. _getPublicPalettes: function _getPublicPalettes() {
  17. return this.glassContext.getSvc('.Palette').then(function (svc) {
  18. return svc;
  19. }).then(function (svc) {
  20. return svc.getPublicPalettes();
  21. }).then(function (response) {
  22. return {
  23. public: response
  24. };
  25. });
  26. },
  27. _addCreatePaletteHandler: function _addCreatePaletteHandler() {
  28. var divForPaletteWidget = $("<div>");
  29. divForPaletteWidget.addClass("createPaletteHook");
  30. this.$el.append(divForPaletteWidget);
  31. this.$el.find('.bi-admin-create-global-palette').on("primaryaction", function () {
  32. this.newPaletteWidget = React.createElement(authoring.CustomPalette, {
  33. glassContext: this.glassContext,
  34. userClass: 'admin',
  35. type: 'global',
  36. removeDialog: function removeDialog() {
  37. ReactDOM.unmountComponentAtNode(divForPaletteWidget[0]);
  38. }
  39. });
  40. ReactDOM.render(this.newPaletteWidget, this.$el.find('.createPaletteHook')[0], function () {
  41. this.openDialog();
  42. });
  43. }.bind(this));
  44. },
  45. _createChangePaletteView: function _createChangePaletteView(spec) {
  46. return new authoring.ChangePaletteView(spec);
  47. },
  48. render: function render($body) {
  49. this.$el.html(dot.template(template)({
  50. 'title': StringResource.get('global'),
  51. 'createGlobalPaletteLabel': StringResource.get('createGlobalPaletteLabel')
  52. }));
  53. this._addCreatePaletteHandler();
  54. this._changePaletteView = this._createChangePaletteView({
  55. 'el': this.$el.find('.bi-admin-palettes-content'),
  56. 'name': 'customPalettes',
  57. 'glassContext': this.glassContext,
  58. 'showHeader': false,
  59. 'useSections': false,
  60. 'getPalettes': this._getPublicPalettes,
  61. 'showRecentlyUsed': false,
  62. 'isAdminUI': true,
  63. 'menuItems': {
  64. 'public': ['edit', 'duplicate', 'delete']
  65. }
  66. });
  67. return this._changePaletteView.render();
  68. }
  69. });
  70. return PalettesTab;
  71. });