CustomWidgetButton.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Content Explorer
  6. *| (C) Copyright IBM Corp. 2016, 2020
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../../lib/@waca/baglass/js/baglass/app/plugins/Button'], function (BaseClass) {
  13. var WIDGET_CONTAINER_ID = 'com.ibm.bi.dashboard.widgets';
  14. var CONTENT_CONTAINER_ID = 'com.ibm.bi.dashboard.contentTypes';
  15. var CustomWidgetButton = BaseClass.extend({
  16. init: function init(options) {
  17. CustomWidgetButton.inherited('init', this, arguments);
  18. var appController = options.glassContext.appController;
  19. this._determineVisibility(appController);
  20. },
  21. _determineVisibility: function _determineVisibility(appController) {
  22. var _this = this;
  23. appController.findCollection(WIDGET_CONTAINER_ID).then(function (collection) {
  24. var customWidgets = collection.filter(function (widget) {
  25. return !widget.builtin;
  26. });
  27. if (customWidgets.length > 0) {
  28. return true;
  29. } else {
  30. return appController.findCollection(CONTENT_CONTAINER_ID).then(function (contents) {
  31. return (contents || []).some(function (content) {
  32. return content.expose;
  33. });
  34. });
  35. }
  36. }).then(function (shouldRender) {
  37. if (shouldRender) {
  38. _this.show();
  39. } else {
  40. // We have no custom widgets/contents so we never want this button to be shown.
  41. _this.hideForever = true;
  42. _this.hide();
  43. }
  44. });
  45. }
  46. });
  47. return CustomWidgetButton;
  48. });
  49. //# sourceMappingURL=CustomWidgetButton.js.map