From bcafe1937537f9a54f886cae66afd4d780879740 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 24 Aug 2015 17:56:34 +0200 Subject: [PATCH] feature #3912: Use commonAction in hosts tab --- .../public/app/tabs/hosts-tab/actions.js | 133 +++--------------- 1 file changed, 17 insertions(+), 116 deletions(-) diff --git a/src/sunstone/public/app/tabs/hosts-tab/actions.js b/src/sunstone/public/app/tabs/hosts-tab/actions.js index 8c86f25a92..79c8412e31 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/actions.js +++ b/src/sunstone/public/app/tabs/hosts-tab/actions.js @@ -3,118 +3,29 @@ define(function(require) { var Notifier = require('utils/notifier'); var Locale = require('utils/locale'); var DataTable = require('./datatable'); - var OpenNebulaHost = require('opennebula/host'); + var OpenNebulaResource = require('opennebula/host'); var OpenNebulaCluster = require('opennebula/cluster'); var OpenNebulaAction = require('opennebula/action'); + var CommonActions = require('utils/common-actions'); var TAB_ID = require('./tabId'); + var XML_ROOT = "HOST" + var RESOURCE = "Host" var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); + var _commonActions = new CommonActions(OpenNebulaResource, RESOURCE, TAB_ID, XML_ROOT); + var _actions = { - "Host.create" : { - type: "create", - call : OpenNebulaHost.create, - callback : function(request, response) { - Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID); - Sunstone.hideFormPanel(TAB_ID); - Sunstone.getDataTable(TAB_ID).addElement(request, response); - }, - error: function(request, response) { - Sunstone.hideFormPanelLoading(TAB_ID); - Notifier.onError(request, response); - }, - notify: true - }, - - "Host.create_dialog" : { - type: "custom", - call: function() { - Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); - } - }, - - "Host.list" : { - type: "list", - call: OpenNebulaHost.list, - callback: function(request, response) { - Sunstone.getDataTable(TAB_ID).updateView(request, response); - }, - error: Notifier.onError - }, - - "Host.show" : { - type: "single", - call: OpenNebulaHost.show, - callback: function(request, response) { - Sunstone.getDataTable(TAB_ID).updateElement(request, response); - if (Sunstone.rightInfoVisible($('#' + TAB_ID))) { - Sunstone.insertPanels(TAB_ID, response); - } - }, - error: Notifier.onError - }, - - "Host.refresh" : { - type: "custom", - call: function() { - var tab = $('#' + TAB_ID); - if (Sunstone.rightInfoVisible(tab)) { - Sunstone.runAction("Host.show", Sunstone.rightInfoResourceId(tab)) - } else { - Sunstone.getDataTable(TAB_ID).waitingNodes(); - Sunstone.runAction("Host.list", {force: true}); - } - }, - error: Notifier.onError - }, - - "Host.enable" : { - type: "multiple", - call: OpenNebulaHost.enable, - callback: function (req) { - Sunstone.runAction("Host.show", req.request.data[0]); - }, - elements: function() { - return Sunstone.getDataTable(TAB_ID).elements(); - }, - error: Notifier.onError, - notify: true - }, - - "Host.disable" : { - type: "multiple", - call: OpenNebulaHost.disable, - callback: function (req) { - Sunstone.runAction("Host.show", req.request.data[0]); - }, - elements: function() { - return Sunstone.getDataTable(TAB_ID).elements(); - }, - error: Notifier.onError, - notify: true - }, - - "Host.delete" : { - type: "multiple", - call: OpenNebulaHost.del, - callback : function(request, response) { - Sunstone.getDataTable(TAB_ID).deleteElement(request, response); - }, - elements: function() { - return Sunstone.getDataTable(TAB_ID).elements(); - }, - error: Notifier.onError, - notify: true - }, - - "Host.update_template" : { - type: "single", - call: OpenNebulaHost.update, - callback: function(request) { - Sunstone.runAction('Host.show', request.request.data[0][0]); - }, - error: Notifier.onError - }, + "Host.create" : _commonActions.create(CREATE_DIALOG_ID), + "Host.create_dialog" : _commonActions.showCreate(CREATE_DIALOG_ID), + "Host.list" : _commonActions.list(), + "Host.show" : _commonActions.show(), + "Host.refresh" : _commonActions.refresh(), + "Host.delete" : _commonActions.del(), + "Host.update_template" : _commonActions.updateTemplate(), + "Host.enable": _commonActions.multipleAction('enable'), + "Host.disable": _commonActions.multipleAction('disable'), + "Host.rename": _commonActions.singleAction('rename'), "Host.addtocluster" : { type: "multiple", @@ -123,7 +34,7 @@ define(function(require) { var host = params.data.id; if (cluster == -1){ - OpenNebulaHost.show({ + OpenNebulaResource.show({ data : { id: host }, @@ -168,16 +79,6 @@ define(function(require) { elements: function() { return Sunstone.getDataTable(TAB_ID).elements(); } - }, - - "Host.rename" : { - type: "single", - call: OpenNebulaHost.rename, - callback: function(request) { - Sunstone.runAction('Host.show', request.request.data[0][0]); - }, - error: Notifier.onError, - notify: true } };