diff --git a/src/sunstone/public/app/opennebula/action.js b/src/sunstone/public/app/opennebula/action.js index 06d1b79359..ff1405fd6d 100644 --- a/src/sunstone/public/app/opennebula/action.js +++ b/src/sunstone/public/app/opennebula/action.js @@ -92,15 +92,14 @@ define(function(require) { }); }, - "del": function(params, resource, path) { + "del": function(params, resource, path, extra_param) { var callback = params.success; var callbackError = params.error; var id = params.data.id; var request = OpenNebulaHelper.request(resource, "delete", id); var reqPath = path ? path : resource.toLowerCase(); var cache_name = params.cache_name ? params.cache_name : resource; - - $.ajax({ + var ajaxData = { url: reqPath + "/" + id, type: "DELETE", success: function() { @@ -112,7 +111,13 @@ define(function(require) { return callbackError ? callbackError(request, OpenNebulaError(response)) : null; } - }); + }; + if(extra_param){ + ajaxData.data = JSON.stringify(extra_param); + ajaxData.dataType = "json"; + ajaxData.contentType = "application/json; charset=utf-8"; + } + $.ajax(ajaxData); }, "cache": function(resource) { @@ -342,8 +347,8 @@ define(function(require) { var callback = params && params.success; var callbackError = params && params.error; var id = params && params.data && params.data.id; - var roleName = params && params.data && params.data.roleName - var action = params && params.data && params.data.action + var roleName = params && params.data && params.data.roleName; + var action = params && params.data && params.data.action; var cacheName = params.cacheName ? params.cacheName : resource; if(id!==undefined && action && resource){ $.ajax({ diff --git a/src/sunstone/public/app/opennebula/servicetemplate.js b/src/sunstone/public/app/opennebula/servicetemplate.js index ae967e2ce3..08492388c9 100644 --- a/src/sunstone/public/app/opennebula/servicetemplate.js +++ b/src/sunstone/public/app/opennebula/servicetemplate.js @@ -15,10 +15,10 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var OpenNebulaAction = require('./action'); + var OpenNebulaAction = require("./action"); var RESOURCE = "DOCUMENT"; - var PATH = 'service_template'; + var PATH = "service_template"; var CACHE_NAME = "SERVICE_TEMPLATE"; var ServiceTemplate = { @@ -72,15 +72,16 @@ define(function(require) { }, "del": function(params) { params.cache_name = CACHE_NAME; - OpenNebulaAction.del(params, RESOURCE, PATH); + var action_obj = params.data.extra_param; + OpenNebulaAction.del(params, RESOURCE, PATH, action_obj); }, "list" : function(params) { params.cache_name = CACHE_NAME; - OpenNebulaAction.list(params, RESOURCE, PATH) + OpenNebulaAction.list(params, RESOURCE, PATH); }, "show" : function(params) { params.cache_name = CACHE_NAME; - OpenNebulaAction.show(params, RESOURCE, false, PATH) + OpenNebulaAction.show(params, RESOURCE, false, PATH); }, "chown" : function(params) { params.cache_name = CACHE_NAME; @@ -108,7 +109,7 @@ define(function(require) { "getName": function(id){ return OpenNebulaAction.getName(id, CACHE_NAME); } - } + }; return ServiceTemplate; -}) +}); 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 11fe42d8eb..2d01cf5712 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js @@ -22,21 +22,18 @@ define(function(require) { var CommonActions = require("utils/common-actions"); var OpenNebulaAction = require("opennebula/action"); var Navigation = require("utils/navigation"); - var OpenNebula = require('opennebula'); - - var CREATE_APP_DIALOG_ID = require('tabs/marketplaceapps-tab/form-panels/create/formPanelId'); - var MARKETPLACEAPPS_TAB_ID = require('tabs/marketplaceapps-tab/tabId'); - + var OpenNebula = require("opennebula"); + var CREATE_APP_DIALOG_ID = require("tabs/marketplaceapps-tab/form-panels/create/formPanelId"); + var CONFIRM_DIALOG_ID = require("utils/dialogs/generic-confirm/dialogId"); + var MARKETPLACEAPPS_TAB_ID = require("tabs/marketplaceapps-tab/tabId"); var TAB_ID = require("./tabId"); var CREATE_DIALOG_ID = require("./form-panels/create/formPanelId"); var INSTANTIATE_DIALOG_ID = require("./form-panels/instantiate/formPanelId"); var CLONE_DIALOG_ID = require("./dialogs/clone/dialogId"); var XML_ROOT = "DOCUMENT"; var RESOURCE = "ServiceTemplate"; - var _commonActions = new CommonActions(OpenNebulaResource, RESOURCE, TAB_ID, XML_ROOT, Locale.tr("Service Template created")); - var _actions = { "ServiceTemplate.create" : _commonActions.create(CREATE_DIALOG_ID), "ServiceTemplate.show" : _commonActions.show(), @@ -48,8 +45,45 @@ define(function(require) { "ServiceTemplate.rename": _commonActions.singleAction("rename"), "ServiceTemplate.update" : _commonActions.update(), "ServiceTemplate.update_dialog" : _commonActions.checkAndShowUpdate(), - - "ServiceTemplate.create_dialog" : { + "ServiceTemplate.delete_dialog" : { + type: "custom", + call: function() { + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + //header : + headerTabId: TAB_ID, + body : Locale.tr("This will delete the Service.
You can also delete the template or the template and image referenced inside this Service."), + //question : + buttons : [ + Locale.tr("Delete Images and VM Templates"), + Locale.tr("Delete VM Templates"), + Locale.tr("Delete"), + ], + submit : [ + function(){ + Sunstone.runAction(RESOURCE+".delete", Sunstone.getDataTable(TAB_ID).elements(), {"delete_type": "all"}); + return false; + }, + function(){ + Sunstone.runAction(RESOURCE+".delete", Sunstone.getDataTable(TAB_ID).elements(), {"delete_type": "templates"}); + return false; + }, + function(){ + Sunstone.runAction(RESOURCE+".delete", Sunstone.getDataTable(TAB_ID).elements(), {"delete_type": "none"}); + return false; + } + ] + }); + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); + }, + callback : function(request, response) { + var tab = $("#" + that.tabId); + if (Sunstone.getTab() == that.tabId) { + Sunstone.showTab(that.tabId); + } + }, + }, + "ServiceTemplate.create_dialog" : { type: "custom", call: function() { Sunstone.runAction("Network.list"); @@ -57,7 +91,7 @@ define(function(require) { Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); } }, - "ServiceTemplate.show_to_update" : { + "ServiceTemplate.show_to_update" : { type: "single", call: function(params) { Sunstone.runAction("Network.list"); @@ -73,7 +107,6 @@ define(function(require) { }, error: Notifier.onError }, - "ServiceTemplate.list" : { type: "list", call: OpenNebulaResource.list, @@ -85,8 +118,6 @@ define(function(require) { Notifier.onError(request, error_json, $(".oneflow_templates_error_message")); } }, - - "ServiceTemplate.instantiate" : { type: "single", call: OpenNebulaResource.instantiate, @@ -107,7 +138,6 @@ define(function(require) { }, notify: false }, - "ServiceTemplate.instantiate_dialog" : { type: "custom", call: function() { @@ -116,9 +146,7 @@ define(function(require) { Notifier.notifyMessage("Please select one (and just one) template to instantiate."); return false; } - var templateId = "" + selected_nodes[0]; - Sunstone.resetFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID); Sunstone.showFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID, "instantiate", function(formPanelInstance, context) { @@ -126,21 +154,18 @@ define(function(require) { }); } }, - "ServiceTemplate.clone_dialog" : { type: "custom", call: function(){ Sunstone.getDialog(CLONE_DIALOG_ID).show(); } }, - "ServiceTemplate.clone" : { type: "single", call: OpenNebulaResource.clone, error: Notifier.onError, notify: true }, - "ServiceTemplate.upload_marketplace_dialog" : { type: "custom", call: function(params) { @@ -150,9 +175,7 @@ define(function(require) { Notifier.notifyMessage(Locale.tr("Please select one (and just one) Service to export.")); return false; } - - var resourceId = '' + selectedNodes[0]; - + var resourceId = "" + selectedNodes[0]; OpenNebulaResource.show({ data : { id: resourceId @@ -165,7 +188,7 @@ define(function(require) { "export_service", function(formPanelInstance, context) { formPanelInstance.setServiceId(resourceId); - $('#marketplaceapps-tab-wizardForms #TYPE').val('service_template').change(); + $("#marketplaceapps-tab-wizardForms #TYPE").val("service_template").change(); } ); }, @@ -176,6 +199,5 @@ define(function(require) { } } }; - return _actions; }); diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/buttons.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/buttons.js index 151a872ced..7d76c57ebf 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/buttons.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/buttons.js @@ -15,7 +15,7 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var Locale = require('utils/locale'); + var Locale = require("utils/locale"); var Buttons = { "ServiceTemplate.refresh" : { @@ -32,7 +32,7 @@ define(function(require) { "ServiceTemplate.upload_marketplace_dialog" : { type: "action", layout: "main", - text: ' '+ Locale.tr("MarketPlace") + text: " "+ Locale.tr("MarketPlace") }, "ServiceTemplate.update_dialog" : { type: "action", @@ -63,11 +63,17 @@ define(function(require) { layout: "main", text: Locale.tr("Clone") }, - "ServiceTemplate.delete" : { + /*"ServiceTemplate.delete" : { type: "confirm", text: Locale.tr("Delete"), layout: "del", tip: Locale.tr("This will delete the selected templates") + },*/ + "ServiceTemplate.delete_dialog" : { + type: "action", + text: Locale.tr("Delete"), + layout: "del", + tip: Locale.tr("This will delete the selected templates") }, "ServiceTemplate.edit_labels" : { layout: "labels", diff --git a/src/sunstone/public/app/tabs/templates-tab/actions-common.js b/src/sunstone/public/app/tabs/templates-tab/actions-common.js index 66e2350e1e..109dd6995c 100644 --- a/src/sunstone/public/app/tabs/templates-tab/actions-common.js +++ b/src/sunstone/public/app/tabs/templates-tab/actions-common.js @@ -15,289 +15,259 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var Sunstone = require('sunstone'); - var Notifier = require('utils/notifier'); - var Locale = require('utils/locale'); - var OpenNebulaResource = require('opennebula/template'); - var CommonActions = require('utils/common-actions'); - var OpenNebulaAction = require('opennebula/action'); - var Navigation = require('utils/navigation'); - var OpenNebula = require('opennebula'); - var CREATE_APP_DIALOG_ID = require('tabs/marketplaceapps-tab/form-panels/create/formPanelId'); - var MARKETPLACEAPPS_TAB_ID = require('tabs/marketplaceapps-tab/tabId'); - - var XML_ROOT = "VMTEMPLATE" - + var Sunstone = require("sunstone"); + var Notifier = require("utils/notifier"); + var Locale = require("utils/locale"); + var OpenNebulaResource = require("opennebula/template"); + var CommonActions = require("utils/common-actions"); + var OpenNebulaAction = require("opennebula/action"); + var Navigation = require("utils/navigation"); + var OpenNebula = require("opennebula"); + var CREATE_APP_DIALOG_ID = require("tabs/marketplaceapps-tab/form-panels/create/formPanelId"); + var MARKETPLACEAPPS_TAB_ID = require("tabs/marketplaceapps-tab/tabId"); + var XML_ROOT = "VMTEMPLATE"; function Actions(tabId, resource, ids){ - var RESOURCE = resource; - var TAB_ID = ids.TAB_ID; var CREATE_DIALOG_ID = ids.CREATE_DIALOG_ID; var CLONE_DIALOG_ID = ids.CLONE_DIALOG_ID; var INSTANTIATE_DIALOG_ID = ids.INSTANTIATE_DIALOG_ID; var IMPORT_DIALOG_ID = ids.IMPORT_DIALOG_ID; var CONFIRM_DIALOG_ID = ids.CONFIRM_DIALOG_ID; - var _commonActions = new CommonActions(OpenNebulaResource, RESOURCE, TAB_ID, XML_ROOT, Locale.tr("VM Template created")); - var _actions = {}; - - _actions[resource+".list"] = _commonActions.list(), - _actions[resource+".show"] = _commonActions.show(), - _actions[resource+".refresh"] = _commonActions.refresh(), - _actions[resource+".delete"] = _commonActions.del(), - - _actions[resource+".delete_dialog"] = - { - type: "custom", - call: function() { - Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ - //header : - headerTabId: TAB_ID, - body : Locale.tr("This will delete the Template.
You can also delete any Image referenced inside this Template"), - //question : - buttons : [ - Locale.tr("Delete all images"), - Locale.tr("Delete"), - ], - submit : [ - function(){ - Sunstone.runAction(RESOURCE+'.delete_recursive', Sunstone.getDataTable(TAB_ID).elements()); - return false; - }, - function(){ - Sunstone.runAction(RESOURCE+'.delete', Sunstone.getDataTable(TAB_ID).elements()); - return false; - } - ] - }); - - Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); - Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); - } - }, - - _actions[resource+".delete_recursive"] = - { - type: "multiple", - call: OpenNebulaResource.delete_recursive, - callback : function(request, response) { - if (Sunstone.getTab() == TAB_ID) { - Sunstone.showTab(TAB_ID); + _actions[resource+".list"] = _commonActions.list(), + _actions[resource+".show"] = _commonActions.show(), + _actions[resource+".refresh"] = _commonActions.refresh(), + _actions[resource+".delete"] = _commonActions.del(), + _actions[resource+".delete_dialog"] = { + type: "custom", + call: function() { + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + //header : + headerTabId: TAB_ID, + body : Locale.tr("This will delete the Template.
You can also delete any Image referenced inside this Template"), + //question : + buttons : [ + Locale.tr("Delete all images"), + Locale.tr("Delete"), + ], + submit : [ + function(){ + Sunstone.runAction(RESOURCE+".delete_recursive", Sunstone.getDataTable(TAB_ID).elements()); + return false; + }, + function(){ + Sunstone.runAction(RESOURCE+".delete", Sunstone.getDataTable(TAB_ID).elements()); + return false; } - }, - elements: function(opts) { - return Sunstone.getDataTable(TAB_ID).elements(opts); - }, - error: Notifier.onError, - notify: true - }, - - _actions[resource+".chown"] = _commonActions.multipleAction('chown'), - _actions[resource+".chgrp"] = _commonActions.multipleAction('chgrp'), - _actions[resource+".chmod"] = _commonActions.singleAction('chmod'), - _actions[resource+".share"] = - { - type: "multiple", - call: function(params){ - var permissions = { - 'group_u' : 1, - 'recursive' : true - }; - - Sunstone.runAction(RESOURCE+".chmod", params.data.id, permissions); - }, - callback : function(request, response) { - Sunstone.runAction(RESOURCE+".show", req.request.data[0]); - }, - elements: function(opts) { - return Sunstone.getDataTable(TAB_ID).elements(opts); - }, - error: Notifier.onError, - notify: false - }, - - _actions[resource+".unshare"] = - { - type: "multiple", - call: function(params){ - var permissions = { - 'group_u' : 0, - 'recursive' : true - }; - - Sunstone.runAction(RESOURCE+".chmod", params.data.id, permissions); - }, - callback : function(request, response) { - Sunstone.runAction(RESOURCE+".show", req.request.data[0]); - }, - elements: function(opts) { - return Sunstone.getDataTable(TAB_ID).elements(opts); - }, - error: Notifier.onError, - notify: false - }, - - _actions[resource+".rename"] = _commonActions.singleAction('rename'), - _actions[resource+".create"] = _commonActions.create(CREATE_DIALOG_ID), - _actions[resource+".create_dialog"] = _commonActions.showCreate(CREATE_DIALOG_ID), - _actions[resource+".import_dialog"] = { - type: "custom", - call: function() { - Sunstone.showFormPanel(TAB_ID, IMPORT_DIALOG_ID, "import"); - } - }, - _actions[resource+".append_template"] = _commonActions.appendTemplate(), - _actions[resource+".update"] = _commonActions.update(), - _actions[resource+".update_dialog"] = _commonActions.checkAndShowUpdate(), - _actions[resource+".update_template"] = _commonActions.updateTemplate(), - _actions[resource+".show_to_update"] = _commonActions.showUpdate(CREATE_DIALOG_ID), - _actions[resource+".instantiate"] = { - type: "multiple", - call: OpenNebulaResource.instantiate, - callback: function(request, response) { - Sunstone.hideFormPanel(); - OpenNebulaAction.clear_cache("VM"); - - Notifier.notifyCustom( - Locale.tr("VM created"), - Navigation.link(" ID: " + response, "vms-tab", response), - false - ); - }, - elements: function(opts) { - return Sunstone.getDataTable(TAB_ID).elements(opts); - }, - error: function(request, response){ - // without tab id param to work for both templates and vms tab - Sunstone.hideFormPanelLoading(); - Notifier.onError(request, response); - }, - notify: false - }, - _actions[resource+".instantiate_quiet"] = { - type: "single", - call: OpenNebulaResource.instantiate, - callback: function(request, response) { - Sunstone.hideFormPanel(); - OpenNebulaAction.clear_cache("VM"); - }, - error: function(request, response){ - // without tab id param to work for both templates and vms tab - Sunstone.hideFormPanelLoading(); - Notifier.onError(request, response); - } - }, - _actions[resource+".instantiate_vms"] = { - type: "custom", - call: function(){ - //Sunstone.resetFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID); - var selected_nodes = Sunstone.getDataTable(TAB_ID).elements(); - - Sunstone.showFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID, "instantiate", - function(formPanelInstance, context) { - formPanelInstance.setTemplateIds(context, selected_nodes); - }); - } - }, - _actions[resource+".instantiate_persistent"] = - { - type: "single", - call: OpenNebulaResource.instantiate_persistent, - callback: function(request, response) { - Sunstone.hideFormPanel(); - OpenNebulaAction.clear_cache("VM"); - - Notifier.notifyCustom(Locale.tr("VM created"), - Navigation.link(" ID: " + response, "vms-tab", response), - false); - }, - error: function(request, response){ - // without tab id param to work for both templates and vms tab - Sunstone.hideFormPanelLoading(); - Notifier.onError(request, response); - } - }, - _actions[resource+".clone_dialog"] = { - type: "custom", - call: function(){ - Sunstone.getDialog(CLONE_DIALOG_ID).setParams( - { tabId : TAB_ID, - resource : resource - }); - Sunstone.getDialog(CLONE_DIALOG_ID).reset(); - Sunstone.getDialog(CLONE_DIALOG_ID).show(); - } - }, - _actions[resource+".clone"] = { - type: "single", - call: OpenNebulaResource.clone, - callback: function(request, response) { - OpenNebulaAction.clear_cache("VMTEMPLATE"); - Notifier.notifyCustom(Locale.tr("VM Template created"), - Navigation.link(" ID: " + response.VMTEMPLATE.ID, "templates-tab", response.VMTEMPLATE.ID), - false); - }, - error: Notifier.onError, - notify: true - }, - _actions[resource+".clone_recursive"] = - { - type: "single", - call: OpenNebulaResource.clone_recursive, - callback : function(request, response) { - OpenNebulaAction.clear_cache("VMTEMPLATE"); - Notifier.notifyCustom(Locale.tr("VM Template created"), - Navigation.link(" ID: " + response.VMTEMPLATE.ID, "templates-tab", response.VMTEMPLATE.ID), - false); - }, - error: Notifier.onError, - notify: true - }, - _actions[resource+".lockA"] = _commonActions.multipleAction("lock"), - _actions[resource+".lockM"] = _commonActions.multipleAction("lock"), - _actions[resource+".lockU"] = _commonActions.multipleAction("lock"), - _actions[resource+".unlock"] = _commonActions.multipleAction("unlock"), - _actions[resource+".upload_marketplace_dialog"] = { - type: "custom", - call: function() { - var selectedNodes = Sunstone.getDataTable(TAB_ID).elements(); - - if (selectedNodes.length !== 1) { - Notifier.notifyMessage(Locale.tr("Please select one (and just one) Image to export.")); - return false; - } - - var resourceId = '' + selectedNodes[0]; - - OpenNebulaResource.show({ - data : { - id: resourceId - }, - success: function(){ - Sunstone.showTab(MARKETPLACEAPPS_TAB_ID); - Sunstone.showFormPanel( - MARKETPLACEAPPS_TAB_ID, - CREATE_APP_DIALOG_ID, - 'export_template', - function(formPanelInstance, context) { - formPanelInstance.setTemplateId(resourceId); - $('#marketplaceapps-tab-wizardForms #TYPE').val('vmtemplate').change(); - } - ); - }, - error: function(error){ - Notifier.onError(error); - } - }); - } + ] + }); + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); } - - + }, + _actions[resource+".delete_recursive"] = { + type: "multiple", + call: OpenNebulaResource.delete_recursive, + callback : function(request, response) { + if (Sunstone.getTab() == TAB_ID) { + Sunstone.showTab(TAB_ID); + } + }, + elements: function(opts) { + return Sunstone.getDataTable(TAB_ID).elements(opts); + }, + error: Notifier.onError, + notify: true + }, + _actions[resource+".chown"] = _commonActions.multipleAction("chown"), + _actions[resource+".chgrp"] = _commonActions.multipleAction("chgrp"), + _actions[resource+".chmod"] = _commonActions.singleAction("chmod"), + _actions[resource+".share"] = { + type: "multiple", + call: function(params){ + var permissions = { + "group_u" : 1, + "recursive" : true + }; + Sunstone.runAction(RESOURCE+".chmod", params.data.id, permissions); + }, + callback : function(request, response) { + Sunstone.runAction(RESOURCE+".show", req.request.data[0]); + }, + elements: function(opts) { + return Sunstone.getDataTable(TAB_ID).elements(opts); + }, + error: Notifier.onError, + notify: false + }, + _actions[resource+".unshare"] = { + type: "multiple", + call: function(params){ + var permissions = { + "group_u" : 0, + "recursive" : true + }; + Sunstone.runAction(RESOURCE+".chmod", params.data.id, permissions); + }, + callback : function(request, response) { + Sunstone.runAction(RESOURCE+".show", req.request.data[0]); + }, + elements: function(opts) { + return Sunstone.getDataTable(TAB_ID).elements(opts); + }, + error: Notifier.onError, + notify: false + }, + _actions[resource+".rename"] = _commonActions.singleAction("rename"), + _actions[resource+".create"] = _commonActions.create(CREATE_DIALOG_ID), + _actions[resource+".create_dialog"] = _commonActions.showCreate(CREATE_DIALOG_ID), + _actions[resource+".import_dialog"] = { + type: "custom", + call: function() { + Sunstone.showFormPanel(TAB_ID, IMPORT_DIALOG_ID, "import"); + } + }, + _actions[resource+".append_template"] = _commonActions.appendTemplate(), + _actions[resource+".update"] = _commonActions.update(), + _actions[resource+".update_dialog"] = _commonActions.checkAndShowUpdate(), + _actions[resource+".update_template"] = _commonActions.updateTemplate(), + _actions[resource+".show_to_update"] = _commonActions.showUpdate(CREATE_DIALOG_ID), + _actions[resource+".instantiate"] = { + type: "multiple", + call: OpenNebulaResource.instantiate, + callback: function(request, response) { + Sunstone.hideFormPanel(); + OpenNebulaAction.clear_cache("VM"); + Notifier.notifyCustom( + Locale.tr("VM created"), + Navigation.link(" ID: " + response, "vms-tab", response), + false + ); + }, + elements: function(opts) { + return Sunstone.getDataTable(TAB_ID).elements(opts); + }, + error: function(request, response){ + // without tab id param to work for both templates and vms tab + Sunstone.hideFormPanelLoading(); + Notifier.onError(request, response); + }, + notify: false + }, + _actions[resource+".instantiate_quiet"] = { + type: "single", + call: OpenNebulaResource.instantiate, + callback: function(request, response) { + Sunstone.hideFormPanel(); + OpenNebulaAction.clear_cache("VM"); + }, + error: function(request, response){ + // without tab id param to work for both templates and vms tab + Sunstone.hideFormPanelLoading(); + Notifier.onError(request, response); + } + }, + _actions[resource+".instantiate_vms"] = { + type: "custom", + call: function(){ + //Sunstone.resetFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID); + var selected_nodes = Sunstone.getDataTable(TAB_ID).elements(); + Sunstone.showFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID, "instantiate", + function(formPanelInstance, context) { + formPanelInstance.setTemplateIds(context, selected_nodes); + }); + } + }, + _actions[resource+".instantiate_persistent"] = { + type: "single", + call: OpenNebulaResource.instantiate_persistent, + callback: function(request, response) { + Sunstone.hideFormPanel(); + OpenNebulaAction.clear_cache("VM"); + Notifier.notifyCustom(Locale.tr("VM created"), + Navigation.link(" ID: " + response, "vms-tab", response), + false); + }, + error: function(request, response){ + // without tab id param to work for both templates and vms tab + Sunstone.hideFormPanelLoading(); + Notifier.onError(request, response); + } + }, + _actions[resource+".clone_dialog"] = { + type: "custom", + call: function(){ + Sunstone.getDialog(CLONE_DIALOG_ID).setParams( + { tabId : TAB_ID, + resource : resource + }); + Sunstone.getDialog(CLONE_DIALOG_ID).reset(); + Sunstone.getDialog(CLONE_DIALOG_ID).show(); + } + }, + _actions[resource+".clone"] = { + type: "single", + call: OpenNebulaResource.clone, + callback: function(request, response) { + OpenNebulaAction.clear_cache("VMTEMPLATE"); + Notifier.notifyCustom(Locale.tr("VM Template created"), + Navigation.link(" ID: " + response.VMTEMPLATE.ID, "templates-tab", response.VMTEMPLATE.ID), + false); + }, + error: Notifier.onError, + notify: true + }, + _actions[resource+".clone_recursive"] = { + type: "single", + call: OpenNebulaResource.clone_recursive, + callback : function(request, response) { + OpenNebulaAction.clear_cache("VMTEMPLATE"); + Notifier.notifyCustom(Locale.tr("VM Template created"), + Navigation.link(" ID: " + response.VMTEMPLATE.ID, "templates-tab", response.VMTEMPLATE.ID), + false); + }, + error: Notifier.onError, + notify: true + }, + _actions[resource+".lockA"] = _commonActions.multipleAction("lock"), + _actions[resource+".lockM"] = _commonActions.multipleAction("lock"), + _actions[resource+".lockU"] = _commonActions.multipleAction("lock"), + _actions[resource+".unlock"] = _commonActions.multipleAction("unlock"), + _actions[resource+".upload_marketplace_dialog"] = { + type: "custom", + call: function() { + var selectedNodes = Sunstone.getDataTable(TAB_ID).elements(); + if (selectedNodes.length !== 1) { + Notifier.notifyMessage(Locale.tr("Please select one (and just one) Image to export.")); + return false; + } + var resourceId = "" + selectedNodes[0]; + OpenNebulaResource.show({ + data : { + id: resourceId + }, + success: function(){ + Sunstone.showTab(MARKETPLACEAPPS_TAB_ID); + Sunstone.showFormPanel( + MARKETPLACEAPPS_TAB_ID, + CREATE_APP_DIALOG_ID, + "export_template", + function(formPanelInstance, context) { + formPanelInstance.setTemplateId(resourceId); + $("#marketplaceapps-tab-wizardForms #TYPE").val("vmtemplate").change(); + } + ); + }, + error: function(error){ + Notifier.onError(error); + } + }); + } + }; return _actions; } - return Actions; -}) +}); diff --git a/src/sunstone/public/app/tabs/templates-tab/actions.js b/src/sunstone/public/app/tabs/templates-tab/actions.js index 9c5c0b6b71..16bb7f28df 100644 --- a/src/sunstone/public/app/tabs/templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/templates-tab/actions.js @@ -15,24 +15,24 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var Actions = require('tabs/templates-tab/actions-common'); + var Actions = require("tabs/templates-tab/actions-common"); - var TAB_ID = require('tabs/templates-tab/tabId'); - var CREATE_DIALOG_ID = require('tabs/templates-tab/form-panels/create/formPanelId'); - var CLONE_DIALOG_ID = require('tabs/templates-tab/dialogs/clone/dialogId'); - var INSTANTIATE_DIALOG_ID = require('tabs/templates-tab/form-panels/instantiate/formPanelId'); - var IMPORT_DIALOG_ID = require('tabs/templates-tab/form-panels/import/formPanelId'); - var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); + var TAB_ID = require("tabs/templates-tab/tabId"); + var CREATE_DIALOG_ID = require("tabs/templates-tab/form-panels/create/formPanelId"); + var CLONE_DIALOG_ID = require("tabs/templates-tab/dialogs/clone/dialogId"); + var INSTANTIATE_DIALOG_ID = require("tabs/templates-tab/form-panels/instantiate/formPanelId"); + var IMPORT_DIALOG_ID = require("tabs/templates-tab/form-panels/import/formPanelId"); + var CONFIRM_DIALOG_ID = require("utils/dialogs/generic-confirm/dialogId"); - var RESOURCE = "Template" + var RESOURCE = "Template"; - return Actions(TAB_ID, RESOURCE, + return Actions(TAB_ID, RESOURCE, { - 'TAB_ID' : TAB_ID, - 'CREATE_DIALOG_ID' : CREATE_DIALOG_ID, - 'CLONE_DIALOG_ID' : CLONE_DIALOG_ID, - 'INSTANTIATE_DIALOG_ID' : INSTANTIATE_DIALOG_ID, - 'IMPORT_DIALOG_ID' : IMPORT_DIALOG_ID, - 'CONFIRM_DIALOG_ID' : CONFIRM_DIALOG_ID, + "TAB_ID" : TAB_ID, + "CREATE_DIALOG_ID" : CREATE_DIALOG_ID, + "CLONE_DIALOG_ID" : CLONE_DIALOG_ID, + "INSTANTIATE_DIALOG_ID" : INSTANTIATE_DIALOG_ID, + "IMPORT_DIALOG_ID" : IMPORT_DIALOG_ID, + "CONFIRM_DIALOG_ID" : CONFIRM_DIALOG_ID, }); }); diff --git a/src/sunstone/public/app/utils/common-actions.js b/src/sunstone/public/app/utils/common-actions.js index 311ee84c19..19b4f59e07 100644 --- a/src/sunstone/public/app/utils/common-actions.js +++ b/src/sunstone/public/app/utils/common-actions.js @@ -15,10 +15,10 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var Sunstone = require('sunstone'); - var Notifier = require('utils/notifier'); - var Locale = require('utils/locale'); - var Navigation = require('utils/navigation'); + var Sunstone = require("sunstone"); + var Notifier = require("utils/notifier"); + var Locale = require("utils/locale"); + var Navigation = require("utils/navigation"); /* CONSTRUCTOR @@ -61,7 +61,7 @@ define(function(require) { } }, error: Notifier.onError - } + }; } function _show() { @@ -72,13 +72,13 @@ define(function(require) { callback: function(request, response) { if(that && that.tabId && Sunstone && Sunstone.getDataTable && Sunstone.getDataTable(that.tabId)){ Sunstone.getDataTable(that.tabId).updateElement(request, response); - if (Sunstone.rightInfoVisible($('#' + that.tabId))) { + if (Sunstone.rightInfoVisible($("#" + that.tabId))) { Sunstone.insertPanels(that.tabId, response); } } }, error: Notifier.onError - } + }; } function _refresh() { @@ -86,7 +86,7 @@ define(function(require) { return { type: "custom", call: function() { - var tab = $('#' + that.tabId); + var tab = $("#" + that.tabId); if (Sunstone.rightInfoVisible(tab)) { Sunstone.runAction(that.resourceStr + ".show", Sunstone.rightInfoResourceId(tab)); } else { @@ -95,7 +95,7 @@ define(function(require) { } }, error: Notifier.onError - } + }; } function _del() { @@ -104,7 +104,7 @@ define(function(require) { type: "multiple", call : that.openNebulaResource.del, callback : function(request, response) { - var tab = $('#' + that.tabId); + var tab = $("#" + that.tabId); if (Sunstone.getTab() == that.tabId) { Sunstone.showTab(that.tabId); @@ -115,7 +115,7 @@ define(function(require) { }, error: Notifier.onError, notify: true - } + }; } function _multipleAction(actionStr, notify) { @@ -135,7 +135,7 @@ define(function(require) { }, error: Notifier.onError, notify: notify_bool - } + }; } function _singleAction(actionStr) { @@ -151,7 +151,7 @@ define(function(require) { }, error: Notifier.onError, notify: true - } + }; } function _create(formPanelId) { @@ -177,7 +177,7 @@ define(function(require) { Notifier.onError(request, response); }, notify: false - } + }; } function _showCreate(formPanelId) { @@ -187,7 +187,7 @@ define(function(require) { call: function() { Sunstone.showFormPanel(that.tabId, formPanelId, "create"); } - } + }; } function _showUpdate(formPanelId) { @@ -206,42 +206,42 @@ define(function(require) { }); }, error: Notifier.onError - } + }; } function _checkAndShowUpdate() { var that = this; return { - type: 'single', + type: "single", 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("Please select one (and just one) resource to update."); return false; } - var resourceId = '' + selectedNodes[0]; + var resourceId = "" + selectedNodes[0]; window.ServiceId = resourceId; - Sunstone.runAction(that.resourceStr + '.show_to_update', resourceId); + Sunstone.runAction(that.resourceStr + ".show_to_update", resourceId); } - } + }; } function _checkAndShow(action) { var that = this; return { - type: 'single', + type: "single", 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("Please select one (and just one) resource to update."); return false; } - var resourceId = '' + selectedNodes[0]; - Sunstone.runAction(that.resourceStr + '.' + action, resourceId); + var resourceId = "" + selectedNodes[0]; + Sunstone.runAction(that.resourceStr + "." + action, resourceId); } - } + }; } function _update() { @@ -256,7 +256,7 @@ define(function(require) { Sunstone.hideFormPanelLoading(that.tabId); Notifier.onError(request, response); } - } + }; } function _updateTemplate() { @@ -265,10 +265,10 @@ define(function(require) { type: "single", call: that.openNebulaResource.update, callback: function(request) { - Sunstone.runAction(that.resourceStr + '.show', request.request.data[0]); + Sunstone.runAction(that.resourceStr + ".show", request.request.data[0]); }, error: Notifier.onError - } + }; } function _appendTemplate() { @@ -277,9 +277,9 @@ define(function(require) { type: "single", call: that.openNebulaResource.append, callback: function(request) { - Sunstone.runAction(that.resourceStr + '.show', request.request.data[0]); + Sunstone.runAction(that.resourceStr + ".show", request.request.data[0]); }, error: Notifier.onError - } + }; } }); diff --git a/src/sunstone/routes/oneflow.rb b/src/sunstone/routes/oneflow.rb index dd93aebbb5..b47afe25b3 100644 --- a/src/sunstone/routes/oneflow.rb +++ b/src/sunstone/routes/oneflow.rb @@ -136,7 +136,7 @@ end delete '/service_template/:id' do client = af_build_client - resp = client.delete('/service_template/' + params[:id]) + resp = client.delete('/service_template/' + params[:id], @request_body) af_format_response(resp) end