From a54ede378b2cace974c293c6f3dbbc3289e29083 Mon Sep 17 00:00:00 2001 From: Jorge Miguel Lobo Escalona <47326048+jloboescalona2@users.noreply.github.com> Date: Wed, 19 May 2021 14:06:51 +0200 Subject: [PATCH] B #5405: Redirect delete flow (#1232) Co-authored-by: Jorge Lobo (cherry picked from commit c9442943870802f3ea0b6acda5f983eefe9c97d5) --- src/sunstone/public/app/sunstone.js | 100 ++++++++++-------- .../app/tabs/oneflow-templates-tab/actions.js | 2 +- .../public/app/utils/common-actions.js | 26 ++++- 3 files changed, 80 insertions(+), 48 deletions(-) diff --git a/src/sunstone/public/app/sunstone.js b/src/sunstone/public/app/sunstone.js index 09388a1f0e..2789c4904d 100644 --- a/src/sunstone/public/app/sunstone.js +++ b/src/sunstone/public/app/sunstone.js @@ -948,7 +948,6 @@ define(function(require) { var actionCfg = actions[action]; var notify = actionCfg.notify; - var condition = actionCfg["condition"]; //Is the condition to run the action met? @@ -965,67 +964,78 @@ define(function(require) { var err = actionCfg["error"]; switch (actionCfg.type){ - case "create": - case "register": - call({data:dataArg, success: callback, error:err}); + case "create": + case "register": + call({data:dataArg, success: callback, error:err}); break; - case "single": - if (extraParam !== undefined) { + case "single": + if (extraParam !== undefined) { + call({ + data:{ + id:dataArg, + extra_param: extraParam + }, + success: callback, + error: err + }); + } else { + call({ + data:{ + id:dataArg + }, + success: callback, + error:err + }); + }; + break; + case "list": + call({success: callback, error:err, options:dataArg}); + break; + case "monitor_global": call({ - data:{ - id:dataArg, - extra_param: extraParam - }, - success: callback, error:err - }); - } else { - call({data:{id:dataArg}, success: callback, error:err}); - }; - break; - case "list": - call({success: callback, error:err, options:dataArg}); - break; - case "monitor_global": - call({ timeout: true, success: callback, error:err, data: {monitor: dataArg}}); break; - case "monitor": - case "monitor_single": - call({ + case "monitor": + case "monitor_single": + call({ timeout: true, success: callback, error:err, data: {id:dataArg, monitor: extraParam}}); break; - case "multiple": - $.each(dataArg, function() { - if (extraParam) { - call({ - data:{ - id:this, - extra_param:extraParam - }, - success: callback, - error: err}); + case "multiple": + $.each(dataArg, function() { + if (extraParam) { + call({ + data:{ + id:this, + extra_param:extraParam + }, + success: callback, + error: err + }); } else { call({ - data:{id:this}, - success: callback, - error:err}); + data:{ + id:this + }, + success: callback, + error: err + }); } }); break; - default: - if (dataArg && extraParam) { - call(dataArg, extraParam); - } else if (dataArg) { - call(dataArg); - } else { - call(); - } + default: + if (dataArg && extraParam) { + call(dataArg, extraParam); + } else if (dataArg) { + call(dataArg); + } else { + call(); + } } if (notify) { diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js index 5fb6c30247..3ff07038f4 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js @@ -40,7 +40,7 @@ define(function(require) { "ServiceTemplate.create" : _commonActions.create(CREATE_DIALOG_ID), "ServiceTemplate.show" : _commonActions.show(), "ServiceTemplate.refresh" : _commonActions.refresh(), - "ServiceTemplate.delete" : _commonActions.del(), + "ServiceTemplate.delete" : _commonActions.delWithoutRedirect(), "ServiceTemplate.chown": _commonActions.multipleAction("chown"), "ServiceTemplate.chgrp": _commonActions.multipleAction("chgrp"), "ServiceTemplate.chmod": _commonActions.singleAction("chmod"), diff --git a/src/sunstone/public/app/utils/common-actions.js b/src/sunstone/public/app/utils/common-actions.js index deb79da178..ba29b47cdd 100644 --- a/src/sunstone/public/app/utils/common-actions.js +++ b/src/sunstone/public/app/utils/common-actions.js @@ -34,6 +34,7 @@ define(function(require) { CommonActions.prototype.list = _list; CommonActions.prototype.show = _show; CommonActions.prototype.refresh = _refresh; + CommonActions.prototype.delWithoutRedirect = _delWithoutRedirect; CommonActions.prototype.del = _del; CommonActions.prototype.multipleAction = _multipleAction; CommonActions.prototype.singleAction = _singleAction; @@ -115,6 +116,27 @@ define(function(require) { }; } + function _delWithoutRedirect() { + var that = this; + return { + type: "multiple", + call : that.openNebulaResource.del, + callback : function(request, response) { + var tab = $("#" + that.tabId); + if (Sunstone.getTab() == that.tabId) { + Sunstone.showTab(that.tabId); + } + }, + elements: function(opts) { + return Sunstone.getDataTable(that.tabId).elements(opts); + }, + error: function(req, res){ + Notifier.notifyError(res && res.error && res.error.message); + }, + notify: true + }; + } + function _multipleAction(actionStr, notify) { notify_bool = true; if(notify != undefined){ @@ -214,7 +236,7 @@ define(function(require) { call: function() { var selectedNodes = Sunstone.getDataTable(that.tabId).elements(); if (selectedNodes.length != 1) { - Notifier.notifyMessage("Please select one (and just one) resource to update."); + Notifier.notifyMessage(Locale.tr("Please select one (and just one) resource to update.")); return false; } @@ -232,7 +254,7 @@ define(function(require) { call: function() { var selectedNodes = Sunstone.getDataTable(that.tabId).elements(); if (selectedNodes.length != 1) { - Notifier.notifyMessage("Please select one (and just one) resource to update."); + Notifier.notifyMessage(Locale.tr("Please select one (and just one) resource to update.")); return false; }