SaveActionHandler.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2015, 2017
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', 'bi/admin/nls/StringResource', 'ba-react-admin/ba-react-admin.min', 'bacontentnav/ui/dialogs/SaveAsDialog'], function (BaseClass, stringResources, AdminReact, SaveAsDialog) {
  13. 'use strict';
  14. var ActionHandler = BaseClass.extend({
  15. onPress: function onPress(context) {
  16. if (context.target.plugin.itemSpec.id === 'com.ibm.bi.job_mgt.saveMenu') {
  17. return this.doSave(context);
  18. }
  19. this.doClassicLink(context);
  20. },
  21. closeAppAndLoadClassicUI: function closeAppAndLoadClassicUI(context) {
  22. var jobId = AdminReact.JobObjectStore.id;
  23. return context.glassContext.appController.closeAppView('job_mgt', '123').then(function () {
  24. var jPath = 'storeID("' + jobId + '")';
  25. window.open('v1/disp?b_action=xts.run&m=portal/properties_job.xts&m_class=jobDefinition&m_obj=' + jPath + '&backURL=disp%3Fb_action%3Dxts.run%26m%3Dportal%2Fclose.xts%26ui.compid%3Dps', '_blank');
  26. });
  27. },
  28. doClassicLink: function doClassicLink(context) {
  29. if (AdminReact.JobObjectStore.isDirty || AdminReact.JobObjectStore.isNew) {
  30. this.doSave(context).then(function (res) {
  31. console.log(res);
  32. this.closeAppAndLoadClassicUI(context);
  33. }.bind(this));
  34. return;
  35. }
  36. this.closeAppAndLoadClassicUI(context);
  37. },
  38. doSave: function doSave(context) {
  39. var glassContext = context.glassContext;
  40. if (AdminReact.JobObjectStore.isNew) {
  41. var pro = new Promise(function (resolve) {
  42. var dialog = new SaveAsDialog({
  43. glassContext: glassContext,
  44. onSave: function (location, name) {
  45. this.respondToSave(glassContext, location, name, resolve);
  46. }.bind(this)
  47. });
  48. dialog.title = stringResources.get('createNewJob');
  49. dialog.open();
  50. this.dialog = dialog;
  51. }.bind(this));
  52. return pro;
  53. } else {
  54. AdminReact.JobObjectStore.save(glassContext);
  55. return Promise.resolve();
  56. }
  57. },
  58. isItemVisible: function isItemVisible() {
  59. return false; //return (AdminReact.JobObjectStore.canWrite);
  60. },
  61. respondToSave: function respondToSave(glassContext, location, name, resFunction) {
  62. this.dialog.hide();
  63. AdminReact.JobObjectStore.save(glassContext, location, name).then(function () {
  64. glassContext.appController.currentAppView.currentContentView.updateAfterSave();
  65. if (resFunction) {
  66. resFunction();
  67. }
  68. });
  69. }
  70. });
  71. return ActionHandler;
  72. });