ShapingModel.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2017, 2018
  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/dashboard-common/dist/core/Model', 'underscore'], function (Model, _) {
  13. 'use strict';
  14. var ShapingModel = Model.extend({
  15. whitelistAttrs: ['shapingId', 'embeddedModuleId', 'embeddedModuleName', 'embeddedModuleUpToDate', 'moserJSON'],
  16. init: function init(model, options) {
  17. if (model) {
  18. _.defaults(model, {
  19. embeddedModuleUpToDate: true
  20. });
  21. }
  22. ShapingModel.inherited('init', this, arguments);
  23. if (this.moserJSON && !this.shapingId) {
  24. this.shapingId = '__initialShapingID__';
  25. }
  26. this.logger = options.logger;
  27. // Used for undo/redo to know if we're back to the initial spec
  28. this._initialShapingId = this.shapingId;
  29. // Used to track what moserJSON we currently have set in the moserJSON property
  30. this._currentMoserJSONID = this.shapingId;
  31. this._initialEmbeddedModuleUpToData = this.embeddedModuleUpToDate;
  32. },
  33. destroy: function destroy() {
  34. if (this.shapingHelper && this.shapingModelManager) {
  35. if (this.shapingModelManager.isTemporaryModule()) {
  36. if (this.shapingHelper.getModuleId() && this.shapingHelper.getModuleId().indexOf('_sessionTemp') > 0 || this.shapingHelper.getModuleURL() && this.shapingHelper.getModuleURL().indexOf('temp-service') > 0) {
  37. this.shapingHelper.deleteSessionModule();
  38. }
  39. }
  40. this.shapingModelManager.destroy();
  41. this.shapingHelper = null;
  42. this.shapingModelManager = null;
  43. }
  44. },
  45. getShapingId: function getShapingId() {
  46. return this.get('shapingId') || null;
  47. },
  48. setShapingHelper: function setShapingHelper(shapingHelper) {
  49. this.shapingHelper = shapingHelper;
  50. },
  51. setShapingModelManager: function setShapingModelManager(shapingModelManager) {
  52. this.shapingModelManager = shapingModelManager;
  53. },
  54. /**
  55. * Make sure we update the moserJSON when being asked to serialize ourselves
  56. * @Overrides
  57. * @return {Object} The information to be saved in the dashboard spec
  58. */
  59. toJSON: function toJSON() {
  60. var shapingId = this.get('shapingId');
  61. if (!shapingId) {
  62. this._currentMoserJSONID = null;
  63. // Clear the moserJSON from the model
  64. this.updateMoserJSON(undefined);
  65. } else if (this.shapingHelper && (!this._currentMoserJSONID || this._currentMoserJSONID !== shapingId)) {
  66. this._currentMoserJSONID = shapingId;
  67. // If we're back to the initial spec
  68. if (shapingId === this._initialShapingId) {
  69. this.setEmbeddedModuleUpToDate(this._initialEmbeddedModuleUpToData);
  70. } else {
  71. this.setEmbeddedModuleUpToDate(false);
  72. }
  73. this.updateMoserJSON(this.shapingHelper.toJSON());
  74. }
  75. return ShapingModel.inherited('toJSON', this, arguments);
  76. },
  77. setEmbeddedModuleUpToDate: function setEmbeddedModuleUpToDate(upToDate) {
  78. this.set({
  79. embeddedModuleUpToDate: upToDate
  80. }, {
  81. silent: true,
  82. payloadData: {
  83. skipUndoRedo: true
  84. }
  85. });
  86. },
  87. updateMoserJSON: function updateMoserJSON(moserJSON) {
  88. this.set({
  89. moserJSON: moserJSON
  90. }, {
  91. silent: true,
  92. payloadData: {
  93. skipUndoRedo: true
  94. }
  95. });
  96. },
  97. getDeploymentReference: function getDeploymentReference(deploymentReferences, processedAssetIds, isSaveAs, contentLocale) {
  98. if (this.embeddedModuleId && !processedAssetIds[this.embeddedModuleId] && !isSaveAs) {
  99. var _name;
  100. var shapingContentLocale = contentLocale || 'en-us';
  101. processedAssetIds[this.embeddedModuleId] = true;
  102. deploymentReferences.push({
  103. objects: [{
  104. type: 'module',
  105. searchPath: 'storeID("' + this.embeddedModuleId + '")'
  106. }],
  107. name: (_name = {}, _name[shapingContentLocale] = this.embeddedModuleId, _name)
  108. });
  109. }
  110. }
  111. });
  112. return ShapingModel;
  113. });
  114. //# sourceMappingURL=ShapingModel.js.map