DefaultActionView.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2018
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure
  9. * restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define([
  12. 'bi/glass/app/ContentView',
  13. 'jquery',
  14. 'q',
  15. "bi/sharecommon/utils/translator"
  16. ],
  17. function(ContentView, $, Q, t) {
  18. var view = ContentView.extend({
  19. /**
  20. Expected context object:
  21. {
  22. ...
  23. "content": {
  24. "id": "object-id to open"
  25. }
  26. }
  27. */
  28. init: function(options){
  29. view.inherited('init', this, arguments);
  30. $.extend(this, options);
  31. },
  32. render: function() {
  33. var deferred = $.Deferred();
  34. if(!this.id) {
  35. deferred.reject();
  36. } else {
  37. this._getObjectProperties(this.id).then(function(objectInformation) {
  38. this._openObject(objectInformation).done(function() {
  39. //close this on fail and success case. user will go back to welcome on fail
  40. this.glassContext.appController.closeAppView('defaultaction',this.id);
  41. }.bind(this));
  42. deferred.resolve(this);
  43. }.bind(this)).fail(function() {
  44. // close on fail, go to home
  45. this.glassContext.appController.closeAppView('defaultaction',this.id);
  46. deferred.resolve(this);
  47. }.bind(this));
  48. }
  49. return deferred.promise();
  50. },
  51. getContent: function() {
  52. return { id: this.id };
  53. },
  54. getTitle: function() {
  55. return "";
  56. },
  57. _openObject: function(context) {
  58. var deferred = Q.defer();
  59. var actionId = "com.ibm.bi.contentApps.defaultAction." + context.type;
  60. this.glassContext.appController.performAction(actionId, {
  61. glassContext: this.glassContext,
  62. target: {
  63. itemId: actionId,
  64. activeObject: {
  65. aSelectedContext:[context]
  66. }
  67. }
  68. }).then(function() {
  69. deferred.resolve();
  70. }).fail(function() {
  71. deferred.reject();
  72. });
  73. return deferred.promise;
  74. },
  75. _getObjectProperties: function(objectId) {
  76. return this.glassContext.getSvc('.Content').then(function(contentSvc) {
  77. var deferred = Q.defer();
  78. var objectInformation = { };
  79. var server_URL = contentSvc.getBaseObjectsURL() + '/' + objectId + "?fields=id,defaultName,owner.defaultName,type,runAsOwner,runWithOwnerCapabilities,options,executionPrompt,parameters,disabled,hidden,modificationTime,runInAdvancedViewer,permissions";
  80. contentSvc.get(server_URL, {}).then(function(data, textStatus, jqXHR) {
  81. if(data.data[0]) {
  82. objectInformation = data.data[0];
  83. deferred.resolve(objectInformation);
  84. } else {
  85. this.glassContext.appController.showToast(t.translate('error_get_object_properties'),
  86. {
  87. 'type': 'error',
  88. 'newestOnTop' : true,
  89. 'preventDuplicates' : false,
  90. 'timeOut': 6000,
  91. 'extendedTimeOut': 1000
  92. });
  93. deferred.reject();
  94. }
  95. }.bind(this)).fail(function(error) {
  96. this.glassContext.appController.showToast(t.translate('error_get_object_properties'),
  97. {
  98. 'type': 'error',
  99. 'newestOnTop' : true,
  100. 'preventDuplicates' : false,
  101. 'timeOut': 6000,
  102. 'extendedTimeOut': 1000
  103. });
  104. deferred.reject();
  105. }.bind(this));
  106. return deferred.promise;
  107. }.bind(this));
  108. }
  109. });
  110. return view;
  111. });