ExportToStoryDialog.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: BI UI Commons
  6. *
  7. * Copyright IBM Corp. 2017, 2018
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['bacontentnav/ui/dialogs/SaveAsDialog', 'storytelling/nls/StringResources', './ExportView', 'underscore'], function (BaseDialog, StringResources, ExportView, _) {
  12. /**
  13. * Create an export dialog that will be used to select a folder and a file name.
  14. * A service object can be passed to the dialog in order to implement the saving process and returns a Promise.
  15. * Doing so will show an overwrite dialog if the promise returns an error.
  16. * Note: If passing a service, onSave won't be called.
  17. *
  18. * @param - options
  19. * {
  20. * glassContext: <glassContextObject>, // Glass context object.
  21. * defaultFileName: "some name", // Default file name to be used in the save dialog.
  22. * onHide: function() {} // Callback when dialog is hidden.
  23. * viewOptions.url String , viewOptions.selfUrl String and viewOptions.ancestors Array of objects are three parameters
  24. * to customize the initial folder when dialog opens
  25. *
  26. * service: {
  27. * export: function (service, selection, filename, overwrite, loadAfterSave) // export function returning a promise.
  28. * : Promise() // The promise should be resolved when the save succeed, or can reject
  29. * // with the following object: { isDuplicate: true }
  30. * }
  31. *
  32. * }
  33. *
  34. */
  35. var ExportToStoryDialog = BaseDialog.extend({
  36. init: function init(options) {
  37. this.options = options;
  38. this.options.service = this.options.service || {};
  39. this.options.service.save = this.onSave.bind(this);
  40. var dialogOptions = _.defaults(this.options, {
  41. 'buttons': [{
  42. 'text': StringResources.get('exportLabel'),
  43. 'handler': this.ok.bind(this),
  44. 'type': 'primary',
  45. 'defaultId': 'save_button'
  46. }, 'cancel'],
  47. 'viewClass': ExportView,
  48. 'className': 'exportToStoryDialog',
  49. 'id': 'exportDialogTitle',
  50. 'title': StringResources.get('exportDialogTitle')
  51. });
  52. ExportToStoryDialog.inherited('init', this, [dialogOptions]);
  53. },
  54. /**
  55. * Called when the dialog is opened
  56. */
  57. onOpen: function onOpen() {
  58. ExportToStoryDialog.inherited('onOpen', this);
  59. var container = this._container();
  60. container.find('footer').attr('role', 'contentinfo').attr('aria-label', StringResources.get('exportDialogFooter'));
  61. },
  62. /**
  63. * Called when the export button is clicked
  64. */
  65. onSave: function onSave(service, selection, filename, overwrite) {
  66. return this.options.service.export(service, selection, filename, overwrite, this.view.getLoadAfterExport());
  67. }
  68. });
  69. return ExportToStoryDialog;
  70. });
  71. //# sourceMappingURL=ExportToStoryDialog.js.map