RelinkDialog.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: BI Dashboard
  6. *
  7. * Copyright IBM Corp. 2016, 2020
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['../../lib/@waca/bacontentnav/public/js/bacontentnav/ui/dialogs/OpenDialog', '../nls/StringResources'], function (BaseDialog, resources) {
  12. 'use strict';
  13. var RelinkDialog = BaseDialog.extend({
  14. oDataSource: null,
  15. /**
  16. * @param options {object} Options to initialize the dialog object
  17. * */
  18. init: function init(options) {
  19. this.dashboardApi = options.dashboardApi;
  20. this.setDataSource(options.dataSource);
  21. RelinkDialog.inherited('init', this, [this.getRelinkDlgOptions(options)]);
  22. this.logger = this.dashboardApi.getGlassCoreSvc('.Logger');
  23. },
  24. /**
  25. * Populate the options used to initialize data source relink dialog
  26. * @param {object} options:{context:<object>, dataSource:<object>, dataSourceName:<string>}
  27. *
  28. * @returns {object}
  29. */
  30. getRelinkDlgOptions: function getRelinkDlgOptions(options) {
  31. var supportedTypes = ['module', 'dataSet2', 'uploadedFile', 'package'];
  32. var filtersByType = ['folder|package|module|dataSet2|uploadedFile'];
  33. var oResult = {
  34. 'primaryBtnText': resources.get('dlg_use'),
  35. 'typesToOpen': supportedTypes,
  36. 'dialogTitle': resources.get('dlg_RelinkDataSourceTitle', {
  37. 'dataSourceName': options.dataSourceName
  38. }),
  39. 'filtersByTypes': filtersByType,
  40. 'multiSelect': false,
  41. 'onOpenCallback': this.onOpenCallback.bind(this)
  42. };
  43. // We are opening a glass dialog. Prepare the options to contain a glass context (needed by the dialog)
  44. this.dashboardApi.prepareGlassOptions(oResult);
  45. return oResult;
  46. },
  47. /**
  48. * @return {object} Data source object that is to be relinked
  49. * */
  50. getDataSource: function getDataSource() {
  51. return this.oDataSource;
  52. },
  53. setDataSource: function setDataSource(dataSource) {
  54. this.oDataSource = dataSource;
  55. },
  56. /**
  57. * Callback hander after user clicks 'use' button to do data source relink
  58. * @param {object} item selected from dialog
  59. * */
  60. onOpenCallback: function onOpenCallback(selectedItem) {
  61. if (selectedItem && selectedItem.length > 0) {
  62. var item = selectedItem[0];
  63. var oNewDataSourceObj = {
  64. 'assetId': item.id,
  65. 'name': item.defaultName,
  66. 'type': item.type,
  67. 'searchPath': item.searchPath
  68. };
  69. var dataSourcesSvc = this.dashboardApi.getFeature('dataSources.deprecated');
  70. dataSourcesSvc.relink(this.oDataSource, oNewDataSourceObj);
  71. }
  72. }
  73. });
  74. return RelinkDialog;
  75. });
  76. //# sourceMappingURL=RelinkDialog.js.map