1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017 - 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define([], function () {
- 'use strict';
- var EmbeddedModuleManager = {};
- /**
- * Called when removing a source from the dashboard.
- */
- EmbeddedModuleManager.deleteEmbeddedModule = function (shapingModel, options) {
- if (shapingModel.embeddedModuleId) {
- return options.ajaxSvc.ajax({
- type: 'DELETE',
- url: 'v1/metadata/modules/' + encodeURIComponent(shapingModel.embeddedModuleId)
- }).catch(function (error) {
- options.logger.error(error, shapingModel);
- });
- }
- return Promise.resolve();
- };
- /**
- * The dashboard was just saved, we need to update/create any needed modules under the dashboard object
- * @param {boolean} options.saveAs Boolean to let us know if it was a saveAs or save operations
- * @param {string} options.dashboardAssetId The ID for the dashboard
- * @param {object} options.ajaxSvc
- * @return {Promise} Promise that resolves to true if the shaping model was updated
- */
- EmbeddedModuleManager.onDashboardSave = function (shapingModel, options) {
- if (!shapingModel.moserJSON || shapingModel.embeddedModuleUpToDate && !options.saveAs) {
- return Promise.resolve(false);
- }
- var ajaxOptions = {
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- // When doing a saveAs or if we don't already have a module under the dashboard then POST to create the new module
- if (options.saveAs || !shapingModel.embeddedModuleId) {
- // Set the name of the embeddedModule that we're about to save
- shapingModel.set({
- embeddedModuleName: shapingModel.id
- }, {
- silent: true,
- payloadData: {
- skipUndoRedo: true
- }
- });
- ajaxOptions.url = 'v1/metadata/modules?location=' + encodeURIComponent(options.dashboardAssetId);
- ajaxOptions.type = 'POST';
- } else {
- ajaxOptions.url = 'v1/metadata/modules/' + encodeURIComponent(shapingModel.embeddedModuleId);
- ajaxOptions.type = 'PUT';
- }
- // Make sure the module name is consistent every time we update it
- shapingModel.moserJSON.label = shapingModel.embeddedModuleName;
- ajaxOptions.data = JSON.stringify(shapingModel.moserJSON);
- return options.ajaxSvc.ajax(ajaxOptions).then(function (response) {
- // We have a successful save/update
- shapingModel.setEmbeddedModuleUpToDate(true);
- if (response && response.data && response.data.id) {
- shapingModel.set({
- embeddedModuleId: response.data.id
- }, {
- silent: true,
- payloadData: {
- skipUndoRedo: true
- }
- });
- }
- return true;
- }).catch(function (error) {
- options.logger.error(error, shapingModel);
- return false;
- });
- };
- return EmbeddedModuleManager;
- });
- //# sourceMappingURL=EmbeddedModuleManager.js.map
|