123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * (C) Copyright IBM Corp. 2015, 2018
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'bi/glass/app/ContentView',
- 'jquery',
- 'q',
- "bi/sharecommon/utils/translator"
- ],
- function(ContentView, $, Q, t) {
- var view = ContentView.extend({
- /**
- Expected context object:
- {
- ...
- "content": {
- "id": "object-id to open"
- }
- }
- */
- init: function(options){
- view.inherited('init', this, arguments);
- $.extend(this, options);
- },
- render: function() {
- var deferred = $.Deferred();
- if(!this.id) {
- deferred.reject();
- } else {
- this._getObjectProperties(this.id).then(function(objectInformation) {
- this._openObject(objectInformation).done(function() {
- //close this on fail and success case. user will go back to welcome on fail
- this.glassContext.appController.closeAppView('defaultaction',this.id);
- }.bind(this));
- deferred.resolve(this);
- }.bind(this)).fail(function() {
- // close on fail, go to home
- this.glassContext.appController.closeAppView('defaultaction',this.id);
- deferred.resolve(this);
- }.bind(this));
- }
- return deferred.promise();
- },
- getContent: function() {
- return { id: this.id };
- },
- getTitle: function() {
- return "";
- },
- _openObject: function(context) {
- var deferred = Q.defer();
- var actionId = "com.ibm.bi.contentApps.defaultAction." + context.type;
- this.glassContext.appController.performAction(actionId, {
- glassContext: this.glassContext,
- target: {
- itemId: actionId,
- activeObject: {
- aSelectedContext:[context]
- }
- }
- }).then(function() {
- deferred.resolve();
- }).fail(function() {
- deferred.reject();
- });
- return deferred.promise;
- },
- _getObjectProperties: function(objectId) {
- return this.glassContext.getSvc('.Content').then(function(contentSvc) {
- var deferred = Q.defer();
- var objectInformation = { };
- var server_URL = contentSvc.getBaseObjectsURL() + '/' + objectId + "?fields=id,defaultName,owner.defaultName,type,runAsOwner,runWithOwnerCapabilities,options,executionPrompt,parameters,disabled,hidden,modificationTime,runInAdvancedViewer,permissions";
- contentSvc.get(server_URL, {}).then(function(data, textStatus, jqXHR) {
- if(data.data[0]) {
- objectInformation = data.data[0];
- deferred.resolve(objectInformation);
- } else {
- this.glassContext.appController.showToast(t.translate('error_get_object_properties'),
- {
- 'type': 'error',
- 'newestOnTop' : true,
- 'preventDuplicates' : false,
- 'timeOut': 6000,
- 'extendedTimeOut': 1000
- });
- deferred.reject();
- }
- }.bind(this)).fail(function(error) {
- this.glassContext.appController.showToast(t.translate('error_get_object_properties'),
- {
- 'type': 'error',
- 'newestOnTop' : true,
- 'preventDuplicates' : false,
- 'timeOut': 6000,
- 'extendedTimeOut': 1000
- });
- deferred.reject();
- }.bind(this));
- return deferred.promise;
- }.bind(this));
- }
- });
- return view;
- });
|