WidgetModel.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 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. var WidgetModel = null;
  9. WidgetModel = Model.extend({
  10. runtimeAttrs: ['filters'],
  11. validLocalizedProps: ['content', 'title', 'altText', 'name'],
  12. validWidgetTypesForLocalizationProps: ['text', 'image', 'media', 'webpage'],
  13. init: function init(spec) {
  14. this._addLocalizedProps(spec);
  15. WidgetModel.inherited('init', this, arguments);
  16. if (spec) {
  17. this.whitelistAttrs = ['id'];
  18. for (var item in spec) {
  19. if (spec.hasOwnProperty(item)) {
  20. this.whitelistAttrs.push(item);
  21. }
  22. }
  23. }
  24. },
  25. /**
  26. * Temp for R releases. We should try and get proper models for Endor instead of them all using the same one
  27. */
  28. _addLocalizedProps: function _addLocalizedProps(spec) {
  29. var localizedProps = [];
  30. // This is needed because both the image and text widget use a property called 'content'. Make sure
  31. // we're only adding multilingual model properties for the widget we know have them.
  32. if (spec && this.validWidgetTypesForLocalizationProps.indexOf(spec.type) !== -1) {
  33. for (var item in spec) {
  34. if (spec.hasOwnProperty(item)) {
  35. if (this.validLocalizedProps.indexOf(item) !== -1) {
  36. localizedProps.push(item);
  37. }
  38. }
  39. }
  40. }
  41. this.localizedProps = localizedProps;
  42. },
  43. cloneWidget: function cloneWidget(idMap) {
  44. var clone = new WidgetModel(this.toJSON());
  45. clone.replaceIds(idMap);
  46. return clone;
  47. }
  48. });
  49. return WidgetModel;
  50. });
  51. //# sourceMappingURL=WidgetModel.js.map