ButtonSlideoutController.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Content Explorer
  5. *| (C) Copyright IBM Corp. 2017, 2021
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. define([
  12. 'bi/glass/app/NavbarButtonSlideoutController',
  13. 'bacontentnav/utils/UIHelper',
  14. 'bacontentnav/utils/ContentServiceUrls',
  15. 'underscore'
  16. ], function(NavbarButtonSlideoutController, UIHelper, ContentServiceUrls, _) {
  17. 'use strict'; //NOSONAR
  18. var ButtonSlideoutController = NavbarButtonSlideoutController.extend({
  19. /**
  20. * Builds a predefined spec for slideout.
  21. * If current content view has a folderInfo object then it
  22. * builds a slideout spec to display a folder instead of root
  23. * based on ancestors from folderInfo object.
  24. * @public
  25. * @override
  26. * @param {object} Context containing glass context and target
  27. * @returns {object} Slideout item spec
  28. */
  29. getCustomSpec: function() {
  30. var spec = ButtonSlideoutController.inherited('getCustomSpec', this, arguments);
  31. if (spec.options && spec.options.content.id) {
  32. let specWidth = UIHelper.getSlideoutWidth(spec.options.content.id);
  33. if (specWidth) {
  34. // We need to add 9px for the bar.
  35. specWidth = parseInt(specWidth);
  36. specWidth += 9;
  37. if (specWidth < $(document).width()) {
  38. spec.options.width = '' + specWidth + 'px';
  39. }
  40. }
  41. }
  42. return spec;
  43. },
  44. onRender: function(pluginData) {
  45. if (pluginData.target.itemId === 'com.ibm.bi.contentApps.myPortalPages') {
  46. return pluginData.glassContext.getCoreSvc('.Config').getConfigValue('ContentApps/enableMyPortalPages').then(function(isFeatureEnabled) {
  47. if (isFeatureEnabled === 'true') {
  48. pluginData.target.plugin.hideForever = false;
  49. return Promise.resolve(pluginData.target.plugin.show());
  50. } else {
  51. pluginData.target.plugin.hideForever = true;
  52. return Promise.resolve(pluginData.target.plugin.hide());
  53. }
  54. }.bind(this));
  55. } else if (pluginData.target.itemId === 'com.ibm.bi.contentApps.customFoldersSlideout') {
  56. var teamFolders = pluginData.glassContext.getCoreSvc('.UserProfile').userProfileSettings.ui_teamFolders;
  57. if (!_.isEmpty(teamFolders)) {
  58. var path = teamFolders.pathRef;
  59. if (path) {
  60. path = path.replace(/^\//, '');
  61. }
  62. var pathURL = ContentServiceUrls.getBasePathURL() + encodeURIComponent(path);
  63. var options = {
  64. dataType: 'json',
  65. url: pathURL
  66. };
  67. return pluginData.glassContext.getCoreSvc('.Ajax').ajax(options).then(function(result) {
  68. var cmObj = result.data.data[0];
  69. var label = cmObj.defaultName;
  70. pluginData.target.plugin.changeLabel(label);
  71. pluginData.target.plugin.hideForever = false;
  72. return Promise.resolve(pluginData.target.plugin.show());
  73. }.bind(this));
  74. } else {
  75. pluginData.target.plugin.hideForever = true;
  76. return Promise.resolve(pluginData.target.plugin.hide());
  77. }
  78. }
  79. }
  80. });
  81. return ButtonSlideoutController;
  82. });