EventGroupEntry.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../lib/@waca/dashboard-common/dist/core/Model'], function (Model) {
  8. /**
  9. * Model which represents the event group associated with a widget
  10. */
  11. var EventGroupEntry = null;
  12. EventGroupEntry = Model.extend({
  13. whitelistAttrs: ['id', 'widgetIds'],
  14. init: function init() /*attrs, options */{
  15. EventGroupEntry.inherited('init', this, arguments);
  16. if (!this.widgetIds) {
  17. this.widgetIds = [];
  18. }
  19. },
  20. addWidget: function addWidget(id, options) {
  21. var index = this.widgetIds.indexOf(id);
  22. if (index < 0) {
  23. var ids = this.widgetIds.slice();
  24. ids.push(id);
  25. this.set({ widgetIds: ids }, options);
  26. }
  27. },
  28. removeWidget: function removeWidget(id, options) {
  29. var index = this.widgetIds.indexOf(id);
  30. if (index > -1) {
  31. var ids = this.widgetIds.filter(function (widgetId) {
  32. return id !== widgetId;
  33. });
  34. this.set({ widgetIds: ids }, options);
  35. }
  36. },
  37. getGroupIndex: function getGroupIndex() {
  38. var tokens = this.id.split(':');
  39. return tokens.length === 2 ? parseInt(tokens[1], 10) : 0;
  40. },
  41. setGroupIndex: function setGroupIndex(index, options) {
  42. this.set({ id: this.getPageId() + ':' + index }, options);
  43. },
  44. getPageId: function getPageId() {
  45. return this.id.split(':')[0];
  46. }
  47. });
  48. return EventGroupEntry;
  49. });
  50. //# sourceMappingURL=EventGroupEntry.js.map