PageletView.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Content Explorer
  5. *| (C) Copyright IBM Corp. 2018, 2020
  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/ContentView',
  13. 'text!bi/content_apps/common/templates/PageletViewTemplate.html',
  14. 'bi/glass/api/Url',
  15. 'jquery',
  16. 'doT'
  17. ], function(ContentView, viewTemplate, Url, $, dot) {
  18. 'use strict'; //NOSONAR: Meant to be strict
  19. var PageletView = ContentView.extend({
  20. init: function(options, appView) {
  21. $.extend(this, options);
  22. if (appView) {
  23. var actionId = 'common.navBarAction.hideNavBarItemLabelsAction';
  24. var glassContext = appView.glassContext;
  25. glassContext.appController.canExecuteAction(actionId, { glassContext: glassContext }).then(function(canExecute) {
  26. if (canExecute) {
  27. return glassContext.appController.performAction(actionId, { glassContext: glassContext });
  28. }
  29. });
  30. }
  31. this._url = new Url();
  32. PageletView.inherited('init', this, arguments);
  33. },
  34. setFocus: function() {
  35. ContentView.inherited('setFocus', this, arguments);
  36. this.trigger('change:state');
  37. },
  38. render: function() {
  39. return this._url.getObjInfoFromContent(this.glassContext.services.ajax, { objRef: this.id }, ['defaultName']).then(function(objInfo) {
  40. this.defaultName = objInfo.defaultName;
  41. var storeId = encodeURIComponent('"' + this.id + '"');
  42. var url = 'v1/disp?b_action=dashboard&pathinfo=/pagelet&path=storeID(' + storeId + ')&frag-header=false';
  43. return this._injectiFrame({ genericIframe_url: url });
  44. }.bind(this));
  45. },
  46. getContent: function() {
  47. return {
  48. objRef: this.id,
  49. id: this.id
  50. };
  51. },
  52. getType: function() {
  53. return 'pagelet';
  54. },
  55. getTitle: function() {
  56. return this.defaultName;
  57. },
  58. execute: function(context) {
  59. return {
  60. perspective: 'pagelet',
  61. objRef: context.urlMap.objRef
  62. };
  63. },
  64. _injectiFrame: function(context) {
  65. $.extend(context,{ 'genericIframe_title': this.getTitle() });
  66. var sHtml = dot.template(viewTemplate)(context);
  67. this.$el.append(sHtml);
  68. return Promise.resolve();
  69. }
  70. });
  71. return PageletView;
  72. });