123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2022
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define([
- 'bi/content_apps/nls/StringResource',
- 'bacontentnav/lib/@waca/core-client/js/core-client/utils/Deferred'
- ], function(StringResource, Deferred) {
- 'use strict';
- return {
- saveAgentView: function(cmProperties, context) {
- var saveDeferred = new Deferred();
- window.parent.require(['bi/commons/ui/content/dialog/SaveAsDialog'], function(SaveAsDialog) {
- var dialog = new SaveAsDialog({
- glassContext: context.glassContext,
- defaultFileName: StringResource.get('agentViewOf', { agentName: cmProperties.defaultName }),
- ancestors: cmProperties.ancestors,
- service: {
- context: context,
- save: function(service, selection, name, overwrite) {
- dialog.hide();
- var data = {
- 'type': 'agentDefinitionView',
- 'defaultName': name,
- 'executionPrompt': false,
- 'base': [{
- 'searchPath': 'storeID("' + cmProperties.id + '")',
- 'type': 'baseClass'
- }]
- };
- var deferred = new Deferred();
- var url = selection.url + '?updateAction=' + (overwrite ? 'replace' : 'fail');
- service.context.glassContext.services.ajax.post(url, {
- contentType: 'application/json',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(data)
- })
- .fail(function(d, request) {
- var response = request.responseJSON;
- if (!response && request.responseText){
- response = JSON.parse(request.responseText);
- }
- if (response.errorCode === 'cmDuplicateName') {
- deferred.reject({ isDuplicate: true });
- } else {
- deferred.reject();
- saveDeferred.reject();
- }
- })
- .done(function(v_oResult) {
- service.context.glassContext.services.ajax.ajax({
- 'url': 'v1/objects/' + cmProperties.id + '/items',
- 'dataType': 'json',
- 'type': 'GET'
- }).then(function(reportObj) {
- // Find current report in AgentDefinition (only one report obj can be there)
- var reportId = reportObj.data.filter(function(item){
- return item.type === 'report';
- })[0].id;
- service.context.glassContext.services.ajax.ajax({
- 'url': selection.url,
- 'dataType': 'json',
- 'type': 'GET'
- }).then(function(objs){
- var agentViewId = objs.data.filter(function(d) {
- return d.defaultName === name;
- })[0].id;
- //create reportView with agentViewId and reportId that stored in agentdefinition
- var rvdata = {
- 'type': 'reportView',
- 'defaultName': new Date(),
- 'executionPrompt': false,
- 'searchPath': 'storeID("' + agentViewId + '")',
- 'base': [{
- 'searchPath': 'storeID("' + reportId + '")',
- 'type': 'baseClass'
- }]
- };
- service.context.glassContext.services.ajax.post(url, {
- contentType: 'application/json',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(rvdata)
- }).done(function(){
- context.target.plugin.activeObject.oListControl.contentView.refresh();
- });
- });
- });
- deferred.resolve(v_oResult);
- saveDeferred.resolve(v_oResult);
- });
- return deferred.promise;
- }
- }
- });
- dialog.open();
- });
- return saveDeferred.promise;
- }
- };
- });
|