DownloadOutputHandler.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Content-Apps
  5. *| (C) Copyright IBM Corp. 2018
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. define([
  12. 'bi/commons/utils/BrowserUtils',
  13. 'bi/commons/utils/Downloader',
  14. './OutputHandler'
  15. ], function (BrowserUtils, Downloader, OutputHandler) {
  16. 'use strict';
  17. var _HANDLED_FORMATS = ['xlsxdata','spreadsheetml','xlwa','csv','xml'];
  18. var DownloadOutputHandler = OutputHandler.extend({
  19. /**
  20. * @inheritdoc
  21. */
  22. getPriority: function() {
  23. // a relative number to other output handlers
  24. return 50;
  25. },
  26. /**
  27. * @inheritDoc
  28. */
  29. canExecute: function(options) {
  30. // don't download on an iPad
  31. var format = !BrowserUtils.isIPad() && options && options.output && options.output.format;
  32. return !!(format && _HANDLED_FORMATS.indexOf(format.toLowerCase()) !== -1);
  33. },
  34. /**
  35. * @inheritDoc
  36. */
  37. execute: function(options) {
  38. return this._getDownloader({
  39. 'url': options.output.content + '?download=true',
  40. 'logger': options.glassContext.appController.logger
  41. }).doDownload()
  42. .then(function() {
  43. // don't need to wait to return here
  44. options.glassContext.getSvc('.Content').then(function(contentSvc) {
  45. contentSvc.addToMRU(options.report);
  46. });
  47. });
  48. },
  49. // private for unit-test mocking
  50. _getDownloader: function(options) {
  51. return new Downloader(options);
  52. }
  53. });
  54. return DownloadOutputHandler;
  55. });