diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched-actions/html.hbs b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched-actions/html.hbs index 76568c7ae0..b11892f390 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched-actions/html.hbs +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched-actions/html.hbs @@ -23,29 +23,5 @@ {{{sched_actions_table}}} - - -
{{tr "Perform an action"}}:
- - - - - - - -
- -
-
- - - -
- - - - - - - + {{{perform_action}}} diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched_actions.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched_actions.js index 2191fa86e9..2f1661bd4f 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched_actions.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/sched_actions.js @@ -80,11 +80,14 @@ define(function(require) { ); } - function _html() { - var optionsActions = ScheduleActions.defaultActions.map(function(ac){ - return ""; - }).join(""); + function _htmlPerformAction(optionsRoles){ + return ScheduleActions.htmlPerformAction( + RESOURCE, + optionsRoles + ); + } + function _html() { var optionsRoles = this.data .filter(function(role) { return role && role.name; @@ -106,9 +109,7 @@ define(function(require) { return TemplateHTML({ sched_actions_table: _htmlSchedActions(), - actions: optionsActions, - res: RESOURCE, - roles: optionsRoles + perform_action: _htmlPerformAction(optionsRoles) }); } @@ -121,5 +122,10 @@ define(function(require) { context, that ); + + ScheduleActions.setupPerformAction( + RESOURCE, + that.id //service ID + ); } }); diff --git a/src/sunstone/public/app/utils/schedule_action.js b/src/sunstone/public/app/utils/schedule_action.js index b67c058969..c8207e2e46 100644 --- a/src/sunstone/public/app/utils/schedule_action.js +++ b/src/sunstone/public/app/utils/schedule_action.js @@ -18,20 +18,22 @@ define(function (require) { /* IMPORTS */ + var Actions = require("opennebula/action"); var Config = require("sunstone-config"); var Humanize = require("utils/humanize"); var Locale = require("utils/locale"); var Notifier = require("utils/notifier"); + var OpenNebulaVM = require("opennebula/vm"); + var Sunstone = require("sunstone"); var TemplateUtils = require("utils/template-utils"); var Tips = require("utils/tips"); - var Sunstone = require("sunstone"); - var OpenNebulaVM = require("opennebula/vm"); /* TEMPLATES */ var TemplateHTML = require("hbs!./schedule_action/html"); var TemplateTableHTML = require("hbs!./schedule_action/table"); + var TemplatePerformHTML = require("hbs!./schedule_action/perform-action"); var TemplateTableRowHTML = require("hbs!./schedule_action/table-row"); var TemplateCharterTableHTML = require("hbs!./schedule_action/charter-table"); var TemplateCharterTableRowHTML = require("hbs!./schedule_action/charter-table-row"); @@ -130,6 +132,96 @@ define(function (require) { }); } + function _htmlPerformAction(resource, optionsRoles){ + var optionsActions = defaultActions.map(function(ac){ + return ""; + }).join(""); + + return TemplatePerformHTML({ + res: resource, + actions: optionsActions, + roles: optionsRoles + }); + } + + function _setupPerformAction(resource, service_id){ + $("select#select_new_action").off("change").on("change",function(){ + var snap_name = $("#snapname"); + var snap_id = $("#snapid"); + var disk_id = $("#diskid"); + switch ($(this).val()) { + case "snapshot-create": + snap_name.removeClass("hide"); + snap_id.addClass("hide").val(""); + disk_id.addClass("hide").val(""); + break; + case "snapshot-revert": + snap_name.addClass("hide").val(""); + snap_id.removeClass("hide"); + disk_id.addClass("hide").val(""); + break; + case "snapshot-delete": + snap_name.addClass("hide").val(""); + snap_id.removeClass("hide"); + disk_id.addClass("hide").val(""); + break; + case "disk-snapshot-create": + snap_name.removeClass("hide"); + snap_id.addClass("hide").val(""); + disk_id.removeClass("hide"); + break; + case "disk-snapshot-revert": + snap_name.addClass("hide").val(""); + snap_id.removeClass("hide"); + disk_id.removeClass("hide"); + break; + case "disk-snapshot-delete": + snap_name.addClass("hide").val(""); + snap_id.removeClass("hide"); + disk_id.removeClass("hide"); + break; + default: + snap_name.addClass("hide").val(""); + snap_id.addClass("hide").val(""); + disk_id.addClass("hide").val(""); + break; + } + }); + + $("#perform_"+resource+"_action_json").off("click").on("click", function(){ + var new_action = $("select#select_new_action").val(); + var role = $("select#role_name").val(); + var snap_name = $("#snapname").val(); + var snap_id = $("#snapid").val(); + var disk_id = $("#diskid").val(); + if(new_action){ + var actionJSON = {}; + actionJSON.error = function(e){ + Notifier.notifyError((e && e.error && e.error.message) || Locale.tr("Error")); + }; + actionJSON.success = function(e){ + Notifier.notifyMessage(Locale.tr("Bulk Action Created")); + }; + actionJSON.data = {}; + actionJSON.data.id = service_id; + actionJSON.data.action = {perform: new_action}; + actionJSON.data.action.params = {}; + if(defaultActions.includes(new_action)){ + var rawData = [disk_id,snap_id,snap_name]; + var args = rawData.filter(function (e) {return e;}).join(); + if(args){ + actionJSON.data.action.params.args = args; + } + } + if(role!=="" && role!==undefined){ + actionJSON.data.roleName = role; + } + Actions.addFlowAction(actionJSON,resource); + } + return false; + }); + } + function formatDate( date, type = "full") { var d = date? new Date(date): new Date(); var month = "" + (d.getMonth() + 1); @@ -1424,5 +1516,7 @@ define(function (require) { "updateServiceHTMLTable": _updateServiceHTMLTable, "getScheduleActionTableContent": _getScheduleActionTableContent, "sendSchedActionToServiceRoles": sendSchedActionToServiceRoles, + "htmlPerformAction": _htmlPerformAction, + "setupPerformAction": _setupPerformAction }; }); \ No newline at end of file diff --git a/src/sunstone/public/app/utils/schedule_action/perform-action.hbs b/src/sunstone/public/app/utils/schedule_action/perform-action.hbs new file mode 100644 index 0000000000..effc3d6ff2 --- /dev/null +++ b/src/sunstone/public/app/utils/schedule_action/perform-action.hbs @@ -0,0 +1,41 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2021, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + + + +
{{tr "Perform an action"}}:
+ + + + + + + +
+ +
+
+ + + +
+ + + + + + + \ No newline at end of file