feature #3748: Add host wilds tab

This commit is contained in:
Daniel Molina committed 2015-05-19 19:39:34 +02:00
1 parent a0739b7bc0
commit 8f26d66735
4 files changed
+157 -1

No files matched your search

+2 -1
View File
@@ -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 = {
@@ -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([
'<input type="checkbox" id="import_wild_checker" class="import_' + safe_name + '" unchecked/>',
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;
}
})
@@ -0,0 +1,15 @@
<div ,class="row">
<div class="large-12 columns">
<button id="import_wilds" class="button tiny success right radius" >{{tr "Import Wilds"}}</button>
<table id="datatable_host_wilds" class="datatable twelve">
<thead>
<tr>
<th></th>
<th>{{tr "VM name"}}</th>
<th>{{tr "Remote ID"}}</th>
</tr>
</thead>
<tbody id="tbody_host_wilds"></tbody>
</table>
</div>
</div>
@@ -0,0 +1,3 @@
define(function(require) {
return 'host_wilds_tab';
})