LayoutApi.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (Class) {
  8. var METHODS = {
  9. API_METHODS: ['getId', 'getChildren', 'render', 'getSelfRatio', 'getParentLayout', 'getWidgetAPI']
  10. };
  11. var LayoutAPI = Class.extend({
  12. model: null,
  13. controller: null,
  14. /**
  15. * Constructor
  16. *
  17. * @param {LayoutController} controller - layout controller
  18. */
  19. init: function init(controller) {
  20. this.model = controller.model;
  21. this.controller = controller;
  22. this.layoutController = controller.layoutController;
  23. },
  24. /**
  25. * Layout id getter
  26. * @return {string} layout id
  27. */
  28. getId: function getId() {
  29. return this.model.id;
  30. },
  31. /**
  32. * Get layout children
  33. *
  34. * @return {LayoutAPI[]} array of children layout APIs
  35. */
  36. getChildren: function getChildren() {
  37. var _this = this;
  38. return this.model.items.map(function (_ref) {
  39. var id = _ref.id;
  40. var layout = _this.layoutController.getView(id);
  41. if (layout && layout.view && layout.view.getAPI) {
  42. return layout.view.getAPI();
  43. }
  44. }).filter(function (item) {
  45. return !!item;
  46. });
  47. },
  48. /**
  49. * Show layout
  50. *
  51. * @param {object} options - Rendering Options
  52. * Supported options:
  53. * isBackgroundRun:true|false // Indicate that the rendering is non-interactive (for use by thumbnails)
  54. *
  55. */
  56. render: function render(options) {
  57. this.controller.render(options);
  58. },
  59. /**
  60. * Get layout ratio from parent layout
  61. * @return {Object} ratio; has properties `width` and `height` with the appropriate ratios
  62. */
  63. getSelfRatio: function getSelfRatio() {
  64. return this.controller.getSelfRatio();
  65. },
  66. /**
  67. * Get parent layout API
  68. *
  69. * @return {Object}
  70. */
  71. getParentLayout: function getParentLayout() {
  72. return this.controller.getParentLayout();
  73. },
  74. /**
  75. * Get widget API
  76. *
  77. * @return {WidgetAPI} widget API
  78. */
  79. getWidgetAPI: function getWidgetAPI() {
  80. return this.controller.widgetAPI;
  81. }
  82. });
  83. LayoutAPI.API_METHODS = METHODS.API_METHODS;
  84. return LayoutAPI;
  85. });
  86. //# sourceMappingURL=LayoutApi.js.map