diff --git a/src/sunstone/public/app/tabs/hosts-tab.js b/src/sunstone/public/app/tabs/hosts-tab.js index 236fa50e19..ead5052f3f 100644 --- a/src/sunstone/public/app/tabs/hosts-tab.js +++ b/src/sunstone/public/app/tabs/hosts-tab.js @@ -15,7 +15,8 @@ define(function(require) { var _panels = [ require('./hosts-tab/panels/info'), require('./hosts-tab/panels/monitor'), - require('./hosts-tab/panels/vms') + require('./hosts-tab/panels/vms'), + require('./hosts-tab/panels/wilds') ]; var Tab = { diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js new file mode 100644 index 0000000000..c50bcb254f --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js @@ -0,0 +1,137 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + require('foundation-datatables'); + var Locale = require('utils/locale'); + var CanImportWilds = require('../utils/can-import-wilds'); + + /* + TEMPLATES + */ + + var TemplateWilds = require('hbs!./wilds/html'); + + /* + CONSTANTS + */ + + var PANEL_ID = require('./wilds/panelId'); + var RESOURCE = "Host" + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.title = Locale.tr("Wilds"); + this.icon = "fa-hdd-o"; + + this.element = info[RESOURCE.toUpperCase()]; + + // Do not create an instance of this panel if the Wilds cannot be imported + if (!CanImportWilds(this.element)) { + throw "Panel not available for this element"; + } + + return this; + }; + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateWilds(); + } + + function _setup(context) { + var that = this; + that.dataTableWildHosts = $("#datatable_host_wilds", context).dataTable({ + "bSortClasses" : false, + "bDeferRender": true + }); + + var wilds_list_array = []; + + if (that.element.TEMPLATE.VM) { + wilds = that.element.TEMPLATE.VM; + + $.each(wilds, function() { + name = this.VM_NAME; + safe_name = name.replace(/ /g, "_").replace(/\./g, "_"); + deploy_id = this.DEPLOY_ID; + + wilds_list_array.push([ + '', + name, + deploy_id + ]); + + that.dataTableWildHosts.fnAddData(wilds_list_array); + + $(".import_" + safe_name, that.dataTableWildHosts).data("wild_template", atob(this.IMPORT_TEMPLATE)); + $(".import_" + safe_name, that.dataTableWildHosts).data("host_id", that.element.ID); + + wilds_list_array = []; + }); + } + + delete that.element.TEMPLATE.WILDS; + delete that.element.TEMPLATE.VM; + + // Add event listener for importing WILDS + /* TODO Use only 1 action ----- + context.off("click", '#import_wilds'); + context.on("click", '#import_wilds', function () { + $("#import_wild_checker:checked", "#datatable_host_wilds").each(function() { + var vm_json = { + "vm": { + "vm_raw": $(this).data("wild_template") + } + }; + + var import_host_id = $(this).data("host_id"); + var wild_row = $(this).closest('tr'); + + // Create the VM in OpenNebula + OpenNebula.VM.create({ + timeout: true, + data: vm_json, + success: function(request, response) { + //TODO OpenNebula.Helper.clear_cache("VM"); + + var extra_info = {}; + + extra_info['host_id'] = import_host_id; + extra_info['ds_id'] = -1; + extra_info['enforce'] = false; + + // Deploy the VM + Sunstone.runAction("VM.silent_deploy_action", + response.VM.ID, + extra_info); + + // Notify + notifyCustom(tr("VM imported"), " ID: " + response.VM.ID, false); + + // Delete row (shouldn't be there in next monitorization) + dataTable_wilds_hosts = $("#datatable_host_wilds").dataTable(); + dataTable_wilds_hosts.fnDeleteRow(wild_row); + }, + error: function (request, error_json) { + notifyError(error_json.error.message || tr("Cannot contact server: is it running and reachable?")); + } + }); + }) + });*/ + return false; + } +}) diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs new file mode 100644 index 0000000000..fbfdd1b0a5 --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs @@ -0,0 +1,15 @@ +
+
+ + + + + + + + + + +
{{tr "VM name"}}{{tr "Remote ID"}}
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/panelId.js b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/panelId.js new file mode 100644 index 0000000000..4cc4beb676 --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/panelId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'host_wilds_tab'; +})