'
};
var template_tab = {
title: "Template",
@@ -894,16 +896,16 @@ function setupCreateTemplateDialog(){
// ui.panel // element, that contains the selected/clicked tab contents
// ui.index // zero-based index of the selected (clicked) tab
switch(ui.index){
- case 0:
- enable_kvm();
- break;
- case 1:
- enable_xen();
- break;
- case 2:
- enable_vmware();
- case 3:
- break;
+ case 0:
+ enable_kvm();
+ break;
+ case 1:
+ enable_xen();
+ break;
+ case 2:
+ enable_vmware();
+ case 3:
+ break;
}
//hide_disabled();
//show_enabled();
@@ -935,17 +937,17 @@ function setupCreateTemplateDialog(){
//Using kvm wizard. Updates mandatory tag, optional tags, disable
//XEN-only (and others) items, enables KVM items
- var enable_kvm = function(){
- man_class="kvm";
- opt_class="kvm_opt";
- $(xen_items).attr("disabled","disabled");
+ var enable_kvm = function(){
+ man_class="kvm";
+ opt_class="kvm_opt";
+ $(xen_items).attr("disabled","disabled");
$(vmware_items).attr("disabled","disabled");
- $(kvm_items).removeAttr("disabled");
+ $(kvm_items).removeAttr("disabled");
$('.vm_param .man_icon').css("display","none");
$('.kvm .man_icon').css("display","inline-block");
- //KVM particularities:
+ //KVM particularities:
// * Add no_type option for disks
// * Add driver default option for boot and select it - hide some fields
// * Set the raw type to kvm
@@ -953,27 +955,27 @@ function setupCreateTemplateDialog(){
var type_opts =
'\
- \
- \
- \
- \
- \
- ';
+ \
+ \
+ \
+ \
+ \
+ ';
- $('div#disks select#TYPE').html(type_opts);
+ $('div#disks select#TYPE').html(type_opts);
var boot_opts =
- '\
- \
- \
- ';
+ '\
+ \
+ \
+ ';
$('div#os_boot_opts select#BOOT').html(boot_opts);
$('div#kernel_bootloader',section_os_boot).show();
$('select#boot_method option').removeAttr("selected");
- $('select#boot_method option#no_boot').html("Driver default");
+ $('select#boot_method option#no_boot').html("Driver default");
$('select#boot_method option').removeAttr("selected");
$('.kernel, .bootloader', $('div#os_boot_opts')).hide();
@@ -985,27 +987,27 @@ function setupCreateTemplateDialog(){
$('div#disks select#BUS').html(bus_opts);
- $('input#TYPE', section_raw).val("kvm");
+ $('input#TYPE', section_raw).val("kvm");
- $(section_inputs).show();
+ $(section_inputs).show();
$(section_graphics).show();
- };
+ };
// Using XEN wizard. Update mandatory and optional classes, disable
// KVM-only (and other) items, enable XEN fields...
- var enable_xen = function(){
- man_class="xen";
- opt_class="xen_opt";
- $(kvm_items).attr("disabled","disabled");
+ var enable_xen = function(){
+ man_class="xen";
+ opt_class="xen_opt";
+ $(kvm_items).attr("disabled","disabled");
$(vmware_items).attr("disabled","disabled");
- $(xen_items).removeAttr("disabled");
+ $(xen_items).removeAttr("disabled");
$('.vm_param .man_icon').css("display","none");
$('.xen .man_icon').css("display","inline-block");
- // XEN particularities:
+ // XEN particularities:
// * Remove no_type option from disks
// * Remove driver default boot method
// * Set the raw section to XEN
@@ -1013,20 +1015,20 @@ function setupCreateTemplateDialog(){
var type_opts =
'\
- \
- \
- \
- \
- ';
+ \
+ \
+ \
+ \
+ ';
$('div#disks select#TYPE').html(type_opts);
$('div#os_boot_opts select#BOOT').empty();
$('div#kernel_bootloader',section_os_boot).show();
- $('select#boot_method option:selected').removeAttr("selected");
+ $('select#boot_method option:selected').removeAttr("selected");
$('select#boot_method option#no_boot').html("Please choose");
- $('.kernel, .bootloader', $('div#os_boot_opts')).hide();
+ $('.kernel, .bootloader', $('div#os_boot_opts')).hide();
var bus_opts =
'\
@@ -1034,39 +1036,37 @@ function setupCreateTemplateDialog(){
$('div#disks select#BUS').html(bus_opts);
- $('input#TYPE', section_raw).val("xen");
- $(section_inputs).hide(); //not present for xen
+ $('input#TYPE', section_raw).val("xen");
+ $(section_inputs).hide(); //not present for xen
$(section_graphics).show();
-
-
- };
+ };
var enable_vmware = function() {
man_class="vmware";
- opt_class="vmware_opt";
- $(xen_items).attr("disabled","disabled");
+ opt_class="vmware_opt";
+ $(xen_items).attr("disabled","disabled");
$(kvm_items).attr("disabled","disabled");
- $(vmware_items).removeAttr("disabled");
+ $(vmware_items).removeAttr("disabled");
$('.vm_param .man_icon').css("display","none");
$('.vmware .man_icon').css("display","inline-block");
- //VMWARE particularities
+ //VMWARE particularities
// * Add no_type option for disks
// * Set the raw type to kvm
// * Hide the inputs and graphics section
// * Hide boot method
var type_opts =
'\
- \
- ';
+ \
+ ';
$('div#os_boot_opts select#BOOT').empty();
$('div#disks select#BOOT').empty();
$('select#boot_method option').removeAttr("selected");
- $('select#boot_method option#no_boot').html("Driver default");
+ $('select#boot_method option#no_boot').html("Driver default");
$('select#boot_method option').removeAttr("selected");
$('.kernel, .bootloader', $('div#os_boot_opts')).hide();
@@ -1077,9 +1077,9 @@ function setupCreateTemplateDialog(){
$('div#disks select#BUS').html(bus_opts);
- $('input#TYPE', section_raw).val("vmware");
+ $('input#TYPE', section_raw).val("vmware");
- $(section_inputs).hide();
+ $(section_inputs).hide();
$(section_graphics).hide();
$('div#kernel_bootloader',section_os_boot).hide();
@@ -1088,95 +1088,96 @@ function setupCreateTemplateDialog(){
//This function checks that all mandatory items within a section
//have some value. Returns true if so, false if not.
- var mandatory_filter = function(context){
- var man_items = "."+man_class;
+ var mandatory_filter = function(context){
+ var man_items = "."+man_class;
- //find enabled mandatory items in this context
- man_items = $(man_items+' input:visible, '+man_items+' select:visible',context);
- var r = true;
+ //find enabled mandatory items in this context
+ man_items = $(man_items+' input:visible, '+man_items+' select:visible',context);
+ var r = true;
- //we fail it the item is enabled and has no value
- $.each(man_items,function(){
- if ($(this).parents(".vm_param").attr("disabled") ||
- !($(this).val().length)) {
- r = false;
- return false;
- };
- });
- return r;
+ //we fail it the item is enabled and has no value
+ $.each(man_items,function(){
+ if ($(this).parents(".vm_param").attr("disabled") ||
+ !($(this).val().length)) {
+ r = false;
+ return false;
+ };
+ });
+ return r;
- };
+ };
//Adds an option element to a multiple select box. Before doing so,
//it checks that the desired filter is passed
- var box_add_element = function(context,box_tag,filter){
- var value="";
- var params= $('.vm_param',context);
- var inputs= $('input:enabled',params);
- var selects = $('select:enabled',params);
- var fields = $.merge(inputs,selects);
+ var box_add_element = function(context,box_tag,filter){
+ var value="";
+ var params= $('.vm_param',context);
+ var inputs= $('input:enabled',params);
+ var selects = $('select:enabled',params);
+ var fields = $.merge(inputs,selects);
- //are fields passing the filter?
- var result = filter();
- if (!result) {
- notifyError("There are mandatory parameters missing in this section");
- return false;
- }
+ //are fields passing the filter?
+ var result = filter();
+ if (!result) {
+ notifyError("There are mandatory parameters missing in this section");
+ return false;
+ }
- value={};
+ value={};
- //With each enabled field we form a JSON object
- var id = null;
- $.each(fields,function(){
- if (!($(this).parents(".vm_param").attr("disabled")) &&
- $(this).val().length){
- //Pick up parent's ID if we do not have one
- id = $(this).attr('id').length ? $(this).attr('id') : $(this).parent().attr('id');
- value[id] = $(this).val();
- }
- });
- var value_string = JSON.stringify(value);
- var option= '';
- $('select'+box_tag,context).append(option);
- return false;
- };
+ //With each enabled field we form a JSON object
+ var id = null;
+ $.each(fields,function(){
+ if (!($(this).parents(".vm_param").attr("disabled")) &&
+ $(this).val().length){
+ //Pick up parent's ID if we do not have one
+ id = $(this).attr('id').length ? $(this).attr('id') : $(this).parent().attr('id');
+ value[id] = $(this).val();
+ }
+ });
+ var value_string = JSON.stringify(value);
+ var option=
+ '';
+ $('select'+box_tag,context).append(option);
+ return false;
+ };
//Removes selected elements from a multiple select box
- var box_remove_element = function(section_tag,box_tag){
- var context = $(section_tag);
- $('select'+box_tag+' :selected',context).remove();
- return false;
- };
+ var box_remove_element = function(section_tag,box_tag){
+ var context = $(section_tag);
+ $('select'+box_tag+' :selected',context).remove();
+ return false;
+ };
//Given the JSON of a VM template (or of a section of it), it crawls
//the fields of certain section (context) and add their name and
//values to the template JSON.
- var addSectionJSON = function(template_json,context){
- var params= $('.vm_param',context);
- var inputs= $('input:enabled',params);
- var selects = $('select:enabled',params);
- var fields = $.merge(inputs,selects);
+ var addSectionJSON = function(template_json,context){
+ var params= $('.vm_param',context);
+ var inputs= $('input:enabled',params);
+ var selects = $('select:enabled',params);
+ var fields = $.merge(inputs,selects);
- fields.each(function(){
- if (!($(this).parents(".vm_param").attr("disabled"))){ //if ! disabled
- if ($(this).val().length){ //if has a length
- template_json[$(this).attr('id')]=$(this).val();
- }
- }
- });
- }
+ fields.each(function(){
+ if (!($(this).parents(".vm_param").attr("disabled"))){ //if ! disabled
+ if ($(this).val().length){ //if has a length
+ template_json[$(this).attr('id')]=$(this).val();
+ }
+ }
+ });
+ }
// Given an array (usually empty), a section (context) and a tag for
// a multiple select in that section, it adds the contents of the
// box as objects in the array.
// TODO: Make it return a new array?
- var addBoxJSON = function(array,context,box_tag){
- $('select'+box_tag+' option',context).each(function(){
- array.push( JSON.parse($(this).val()) );
- });
- }
+ var addBoxJSON = function(array,context,box_tag){
+ $('select'+box_tag+' option',context).each(function(){
+ array.push( JSON.parse($(this).val()) );
+ });
+ }
//Given an object, removes those elements which are empty
//Used to clean up a template JSON before submitting
@@ -1211,41 +1212,40 @@ function setupCreateTemplateDialog(){
}
//Toggles the icon when a section is folded/unfolded
- var iconToggle = function(){
- $('.icon_right').toggle(
- function(e){
- $('span',e.currentTarget).removeClass("ui-icon-plusthick");
- $('span',e.currentTarget).addClass("ui-icon-minusthick");
- },function(e){
- $('span',e.currentTarget).removeClass("ui-icon-minusthick");
- $('span',e.currentTarget).addClass("ui-icon-plusthick");
- });
- }
+ var iconToggle = function(){
+ $('.icon_right').toggle(
+ function(e){
+ $('span',e.currentTarget).removeClass("ui-icon-plusthick");
+ $('span',e.currentTarget).addClass("ui-icon-minusthick");
+ },function(e){
+ $('span',e.currentTarget).removeClass("ui-icon-minusthick");
+ $('span',e.currentTarget).addClass("ui-icon-plusthick");
+ });
+ }
// Set ups the capacity section
- var capacity_setup = function(){
+ var capacity_setup = function(){
//Actually there is nothing to set up, but it used to be
//possible to hide it like others
/*
- $('fieldset',section_capacity).hide();
- $('#add_capacity',section_capacity).click(function(){
- $('fieldset',section_capacity).toggle();
- return false;
- });
+ $('fieldset',section_capacity).hide();
+ $('#add_capacity',section_capacity).click(function(){
+ $('fieldset',section_capacity).toggle();
+ return false;
+ });
*/
- }
+ }
//Sets up the OS_BOOT section
- var os_boot_setup = function(){
- $('fieldset',section_os_boot).hide();
- $('.bootloader, .kernel',section_os_boot).hide();
+ var os_boot_setup = function(){
+ $('fieldset',section_os_boot).hide();
+ $('.bootloader, .kernel',section_os_boot).hide();
- $('#add_os_boot_opts',section_os_boot).click(function(){
- $('fieldset',section_os_boot).toggle();
+ $('#add_os_boot_opts',section_os_boot).click(function(){
+ $('fieldset',section_os_boot).toggle();
return false;
- });
-
+ });
//Chrome workaround
$('#boot_method').change(function(){
@@ -1254,28 +1254,28 @@ function setupCreateTemplateDialog(){
//Depending on the boot method we enable/disable some options
$('#boot_method',section_os_boot).click(function(){
- select = $(this).val();
- switch (select)
- {
- case "kernel":
- $('.bootloader',section_os_boot).hide();
- $('.bootloader',section_os_boot).attr("disabled","disabled");
- $('.kernel',section_os_boot).show();
- $('.kernel',section_os_boot).removeAttr("disabled");
- break;
- case "bootloader":
- $('.kernel',section_os_boot).hide();
- $('.kernel',section_os_boot).attr("disabled","disabled");
- $('.bootloader',section_os_boot).show();
- $('.bootloader',section_os_boot).removeAttr("disabled");
- break;
- default:
- $('.kernel, .bootloader',section_os_boot).hide();
- $('.kernel, .bootloader',section_os_boot).attr("disabled","disabled");
- $('.kernel input, .bootloader input',section_os_boot).val("");
- };
- });
- };
+ select = $(this).val();
+ switch (select)
+ {
+ case "kernel":
+ $('.bootloader',section_os_boot).hide();
+ $('.bootloader',section_os_boot).attr("disabled","disabled");
+ $('.kernel',section_os_boot).show();
+ $('.kernel',section_os_boot).removeAttr("disabled");
+ break;
+ case "bootloader":
+ $('.kernel',section_os_boot).hide();
+ $('.kernel',section_os_boot).attr("disabled","disabled");
+ $('.bootloader',section_os_boot).show();
+ $('.bootloader',section_os_boot).removeAttr("disabled");
+ break;
+ default:
+ $('.kernel, .bootloader',section_os_boot).hide();
+ $('.kernel, .bootloader',section_os_boot).attr("disabled","disabled");
+ $('.kernel input, .bootloader input',section_os_boot).val("");
+ };
+ });
+ };
// Sets up the features section
var features_setup = function(){
@@ -1288,289 +1288,289 @@ function setupCreateTemplateDialog(){
};
// Sets up the disk section
- var disks_setup = function(){
+ var disks_setup = function(){
- $('fieldset',section_disks).hide();
- $('.vm_param', section_disks).hide();
- //$('#image_vs_disk',section_disks).show();
+ $('fieldset',section_disks).hide();
+ $('.vm_param', section_disks).hide();
+ //$('#image_vs_disk',section_disks).show();
- $('#add_disks', section_disks).click(function(){
- $('fieldset',section_disks).toggle();
+ $('#add_disks', section_disks).click(function(){
+ $('fieldset',section_disks).toggle();
return false;
- });
+ });
//Depending on adding a disk or a image we need to show/hide
//different options and make then mandatory or not
- $('#image_vs_disk input',section_disks).click(function(){
- //$('fieldset',section_disks).show();
+ $('#image_vs_disk input',section_disks).click(function(){
+ //$('fieldset',section_disks).show();
$('.vm_param', section_disks).show();
- var select = $('#image_vs_disk :checked',section_disks).val();
- switch (select)
- {
- case "disk":
- $('.add_image',section_disks).hide();
- $('.add_image',section_disks).attr("disabled","disabled");
- $('.add_disk',section_disks).show();
- $('.add_disk',section_disks).removeAttr("disabled");
- $('#TARGET',section_disks).parent().removeClass(opt_class);
- $('#TARGET',section_disks).parent().addClass(man_class);
- break;
- case "image":
- $('.add_disk',section_disks).hide();
- $('.add_disk',section_disks).attr("disabled","disabled");
- $('.add_image',section_disks).show();
- $('.add_image',section_disks).removeAttr("disabled");
- $('#TARGET',section_disks).parent().removeClass(man_class);
- $('#TARGET',section_disks).parent().addClass(opt_class);
- break;
- }
- $('#SIZE',section_disks).parent().hide();
- $('#SIZE',section_disks).parent().attr("disabled","disabled");
- $('#FORMAT',section_disks).parent().hide();
- $('#SIZE',section_disks).parent().attr("disabled","disabled");
- $('#TYPE :selected',section_disks).removeAttr("selected");
+ var select = $('#image_vs_disk :checked',section_disks).val();
+ switch (select)
+ {
+ case "disk":
+ $('.add_image',section_disks).hide();
+ $('.add_image',section_disks).attr("disabled","disabled");
+ $('.add_disk',section_disks).show();
+ $('.add_disk',section_disks).removeAttr("disabled");
+ $('#TARGET',section_disks).parent().removeClass(opt_class);
+ $('#TARGET',section_disks).parent().addClass(man_class);
+ break;
+ case "image":
+ $('.add_disk',section_disks).hide();
+ $('.add_disk',section_disks).attr("disabled","disabled");
+ $('.add_image',section_disks).show();
+ $('.add_image',section_disks).removeAttr("disabled");
+ $('#TARGET',section_disks).parent().removeClass(man_class);
+ $('#TARGET',section_disks).parent().addClass(opt_class);
+ break;
+ }
+ $('#SIZE',section_disks).parent().hide();
+ $('#SIZE',section_disks).parent().attr("disabled","disabled");
+ $('#FORMAT',section_disks).parent().hide();
+ $('#SIZE',section_disks).parent().attr("disabled","disabled");
+ $('#TYPE :selected',section_disks).removeAttr("selected");
//hide_disabled(section_disks);
- });
+ });
//Chrome workaround
$('select#TYPE',section_disks).change(function(){
- $(this).trigger('click');
+ $(this).trigger('click');
});
//Depending on the type of disk we need to show/hide
//different options and make then mandatory or not
- $('select#TYPE',section_disks).click(function(){
- var select = $(this).val();
- switch (select) {
- //size,format,target
- case "swap":
- //size mandatory
- $('#SIZE',section_disks).parent().show();
- $('#SIZE',section_disks).parent().removeAttr("disabled");
- $('#SIZE',section_disks).parent().removeClass(opt_class);
- $('#SIZE',section_disks).parent().addClass(man_class);
+ $('select#TYPE',section_disks).click(function(){
+ var select = $(this).val();
+ switch (select) {
+ //size,format,target
+ case "swap":
+ //size mandatory
+ $('#SIZE',section_disks).parent().show();
+ $('#SIZE',section_disks).parent().removeAttr("disabled");
+ $('#SIZE',section_disks).parent().removeClass(opt_class);
+ $('#SIZE',section_disks).parent().addClass(man_class);
- //target optional
- $('#TARGET',section_disks).parent().removeClass(man_class);
- $('#TARGET',section_disks).parent().addClass(opt_class);
+ //target optional
+ $('#TARGET',section_disks).parent().removeClass(man_class);
+ $('#TARGET',section_disks).parent().addClass(opt_class);
- //format hidden
- $('#FORMAT',section_disks).parent().hide();
- $('#FORMAT',section_disks).parent().attr("disabled","disabled");
+ //format hidden
+ $('#FORMAT',section_disks).parent().hide();
+ $('#FORMAT',section_disks).parent().attr("disabled","disabled");
- //source hidden
- $('#SOURCE',section_disks).parent().hide();
- $('#SOURCE',section_disks).parent().
- attr("disabled","disabled");
- break;
- case "fs":
- //size mandatory
- $('#SIZE',section_disks).parent().show();
- $('#SIZE',section_disks).parent().removeAttr("disabled");
- $('#SIZE',section_disks).parent().removeClass(opt_class);
- $('#SIZE',section_disks).parent().addClass(man_class);
+ //source hidden
+ $('#SOURCE',section_disks).parent().hide();
+ $('#SOURCE',section_disks).parent().
+ attr("disabled","disabled");
+ break;
+ case "fs":
+ //size mandatory
+ $('#SIZE',section_disks).parent().show();
+ $('#SIZE',section_disks).parent().removeAttr("disabled");
+ $('#SIZE',section_disks).parent().removeClass(opt_class);
+ $('#SIZE',section_disks).parent().addClass(man_class);
- //target mandatory
- $('#TARGET',section_disks).parent().removeClass(opt_class);
- $('#TARGET',section_disks).parent().addClass(man_class);
+ //target mandatory
+ $('#TARGET',section_disks).parent().removeClass(opt_class);
+ $('#TARGET',section_disks).parent().addClass(man_class);
- //format mandatory
- $('#FORMAT',section_disks).parent().show();
- $('#FORMAT',section_disks).parent().removeAttr("disabled");
- $('#FORMAT',section_disks).parent().removeClass(opt_class);
- $('#FORMAT',section_disks).parent().addClass(man_class);
+ //format mandatory
+ $('#FORMAT',section_disks).parent().show();
+ $('#FORMAT',section_disks).parent().removeAttr("disabled");
+ $('#FORMAT',section_disks).parent().removeClass(opt_class);
+ $('#FORMAT',section_disks).parent().addClass(man_class);
- //source hidden
- $('#SOURCE',section_disks).parent().hide();
- $('#SOURCE',section_disks).parent().
- attr("disabled","disabled");
- break;
- case "block":
- //size shown and optional
- $('#SIZE',section_disks).parent().show();
- $('#SIZE',section_disks).parent().removeAttr("disabled");
- $('#SIZE',section_disks).parent().removeClass(man_class);
- $('#SIZE',section_disks).parent().addClass(opt_class);
+ //source hidden
+ $('#SOURCE',section_disks).parent().hide();
+ $('#SOURCE',section_disks).parent().
+ attr("disabled","disabled");
+ break;
+ case "block":
+ //size shown and optional
+ $('#SIZE',section_disks).parent().show();
+ $('#SIZE',section_disks).parent().removeAttr("disabled");
+ $('#SIZE',section_disks).parent().removeClass(man_class);
+ $('#SIZE',section_disks).parent().addClass(opt_class);
- //target mandatory
- $('#TARGET',section_disks).parent().removeClass(opt_class);
- $('#TARGET',section_disks).parent().addClass(man_class);
+ //target mandatory
+ $('#TARGET',section_disks).parent().removeClass(opt_class);
+ $('#TARGET',section_disks).parent().addClass(man_class);
- //format hidden
- $('#FORMAT',section_disks).parent().hide();
- $('#FORMAT',section_disks).parent().attr("disabled","disabled");
+ //format hidden
+ $('#FORMAT',section_disks).parent().hide();
+ $('#FORMAT',section_disks).parent().attr("disabled","disabled");
- //source hidden
- $('#SOURCE',section_disks).parent().hide();
- $('#SOURCE',section_disks).parent().
- attr("disabled","disabled");
- break;
- case "floppy":
- case "disk":
- case "cdrom":
- default:
- //size hidden
- $('#SIZE',section_disks).parent().hide();
- $('#SIZE',section_disks).parent().attr("disabled","disabled");
+ //source hidden
+ $('#SOURCE',section_disks).parent().hide();
+ $('#SOURCE',section_disks).parent().
+ attr("disabled","disabled");
+ break;
+ case "floppy":
+ case "disk":
+ case "cdrom":
+ default:
+ //size hidden
+ $('#SIZE',section_disks).parent().hide();
+ $('#SIZE',section_disks).parent().attr("disabled","disabled");
- //target mandatory
- $('#TARGET',section_disks).parent().removeClass(opt_class);
- $('#TARGET',section_disks).parent().addClass(man_class);
+ //target mandatory
+ $('#TARGET',section_disks).parent().removeClass(opt_class);
+ $('#TARGET',section_disks).parent().addClass(man_class);
- //format optional
- $('#FORMAT',section_disks).parent().hide();
- $('#FORMAT',section_disks).parent().attr("disabled","disabled");
+ //format optional
+ $('#FORMAT',section_disks).parent().hide();
+ $('#FORMAT',section_disks).parent().attr("disabled","disabled");
- //source shown
- $('#SOURCE',section_disks).parent().show();
- $('#SOURCE',section_disks).parent().
- removeAttr("disabled");
- }
+ //source shown
+ $('#SOURCE',section_disks).parent().show();
+ $('#SOURCE',section_disks).parent().
+ removeAttr("disabled");
+ }
//hide_disabled(section_disks);
- });
+ });
//Our filter for the disks section fields is the mandatory
//filter for this section
- var diskFilter = function(){
- return mandatory_filter(section_disks);
- };
+ var diskFilter = function(){
+ return mandatory_filter(section_disks);
+ };
- $('#add_disk_button',section_disks).click(function(){
- box_add_element(section_disks,'#disks_box',diskFilter);
- return false;
- });
- $('#remove_disk_button',section_disks).click(function(){
- box_remove_element(section_disks,'#disks_box');
- return false;
- });
+ $('#add_disk_button',section_disks).click(function(){
+ box_add_element(section_disks,'#disks_box',diskFilter);
+ return false;
+ });
+ $('#remove_disk_button',section_disks).click(function(){
+ box_remove_element(section_disks,'#disks_box');
+ return false;
+ });
};
// Sets up the network section
- var networks_setup = function(){
+ var networks_setup = function(){
- $('.vm_param',section_networks).hide();
- $('fieldset',section_networks).hide();
+ $('.vm_param',section_networks).hide();
+ $('fieldset',section_networks).hide();
- $('#add_networks',section_networks).click(function(){
- $('fieldset',section_networks).toggle();
+ $('#add_networks',section_networks).click(function(){
+ $('fieldset',section_networks).toggle();
return false;
- });
+ });
//Depending on adding predefined network or not we show/hide
//some fields
- $('#network_vs_niccfg input',section_networks).click(function(){
+ $('#network_vs_niccfg input',section_networks).click(function(){
- select = $('#network_vs_niccfg :checked',section_networks).val();
- switch (select) {
- case "network":
- $('.niccfg',section_networks).hide();
- $('.niccfg',section_networks).attr("disabled","disabled");
- $('.network',section_networks).show();
- $('.network',section_networks).removeAttr("disabled");
- break;
- case "niccfg":
- $('.network',section_networks).hide();
- $('.network',section_networks).attr("disabled","disabled");
- $('.niccfg',section_networks).show();
- $('.niccfg',section_networks).removeAttr("disabled");
- break;
- }
+ select = $('#network_vs_niccfg :checked',section_networks).val();
+ switch (select) {
+ case "network":
+ $('.niccfg',section_networks).hide();
+ $('.niccfg',section_networks).attr("disabled","disabled");
+ $('.network',section_networks).show();
+ $('.network',section_networks).removeAttr("disabled");
+ break;
+ case "niccfg":
+ $('.network',section_networks).hide();
+ $('.network',section_networks).attr("disabled","disabled");
+ $('.niccfg',section_networks).show();
+ $('.niccfg',section_networks).removeAttr("disabled");
+ break;
+ }
//hide_disabled(section_networks);
- });
+ });
- //The filter to add a new network checks that we have selected a
- //network, or that the ip or mac are set
- //TODO: Improve this check
+ //The filter to add a new network checks that we have selected a
+ //network, or that the ip or mac are set
+ //TODO: Improve this check
var nicFilter = function(){
return mandatory_filter(section_networks);
};
- $('#add_nic_button',section_networks).click(function(){
- box_add_element(section_networks,'#nics_box',nicFilter);
- return false;
- });
- $('#remove_nic_button',section_networks).click(function(){
- box_remove_element(section_networks,'#nics_box');
- return false;
- });
+ $('#add_nic_button',section_networks).click(function(){
+ box_add_element(section_networks,'#nics_box',nicFilter);
+ return false;
+ });
+ $('#remove_nic_button',section_networks).click(function(){
+ box_remove_element(section_networks,'#nics_box');
+ return false;
+ });
- };
+ };
//Sets up the input section - basicly enabling adding and removing from box
- var inputs_setup = function() {
- $('fieldset',section_inputs).hide();
+ var inputs_setup = function() {
+ $('fieldset',section_inputs).hide();
- $('#add_inputs',section_inputs).click(function(){
- $('fieldset',section_inputs).toggle();
- return false;
- });
+ $('#add_inputs',section_inputs).click(function(){
+ $('fieldset',section_inputs).toggle();
+ return false;
+ });
- $('#add_input_button',section_inputs).click(function(){
- //no filter
- box_add_element(section_inputs,'#inputs_box',True);
- return false;
- });
- $('#remove_input_button',section_inputs).click(function(){
- box_remove_element(section_inputs,'#inputs_box');
- return false;
- });
- };
+ $('#add_input_button',section_inputs).click(function(){
+ //no filter
+ box_add_element(section_inputs,'#inputs_box',True);
+ return false;
+ });
+ $('#remove_input_button',section_inputs).click(function(){
+ box_remove_element(section_inputs,'#inputs_box');
+ return false;
+ });
+ };
//Set up the graphics section
- var graphics_setup = function(){
- $('fieldset',section_graphics).hide();
+ var graphics_setup = function(){
+ $('fieldset',section_graphics).hide();
$('.vm_param',section_graphics).hide();
$('select#TYPE',section_graphics).parent().show();
- $('#add_graphics',section_graphics).click(function(){
- $('fieldset',section_graphics).toggle();
+ $('#add_graphics',section_graphics).click(function(){
+ $('fieldset',section_graphics).toggle();
return false;
- });
+ });
//Chrome workaround
$('select#TYPE',section_graphics).change(function(){
$(this).trigger("click");
});
- $('select#TYPE',section_graphics).click(function(){
- g_type = $(this).val();
- switch (g_type) {
- case "vnc":
- $('#LISTEN',section_graphics).parent().show();
- $('#PORT',section_graphics).parent().show();
- $('#PASSWD',section_graphics).parent().show();
- $('#KEYMAP',section_graphics).parent().show();
- $('#PORT',section_graphics).parent().removeAttr("disabled");
- $('#PASSWD',section_graphics).parent().removeAttr("disabled");
- $('#KEYMAP',section_graphics).parent().removeAttr("disabled");
- break;
- case "sdl":
- $('#LISTEN',section_graphics).parent().show();
- $('#PORT',section_graphics).parent().hide();
- $('#PASSWD',section_graphics).parent().hide();
- $('#KEYMAP',section_graphics).parent().hide();
- $('#PORT',section_graphics).parent().attr("disabled","disabled");
- $('#PASSWD',section_graphics).parent().attr("disabled","disabled");
- $('#KEYMAP',section_graphics).parent().attr("disabled","disabled");
- break;
- default:
- $('#LISTEN',section_graphics).parent().hide();
- $('#PORT',section_graphics).parent().hide();
- $('#PASSWD',section_graphics).parent().hide();
- $('#KEYMAP',section_graphics).parent().hide();
+ $('select#TYPE',section_graphics).click(function(){
+ g_type = $(this).val();
+ switch (g_type) {
+ case "vnc":
+ $('#LISTEN',section_graphics).parent().show();
+ $('#PORT',section_graphics).parent().show();
+ $('#PASSWD',section_graphics).parent().show();
+ $('#KEYMAP',section_graphics).parent().show();
+ $('#PORT',section_graphics).parent().removeAttr("disabled");
+ $('#PASSWD',section_graphics).parent().removeAttr("disabled");
+ $('#KEYMAP',section_graphics).parent().removeAttr("disabled");
+ break;
+ case "sdl":
+ $('#LISTEN',section_graphics).parent().show();
+ $('#PORT',section_graphics).parent().hide();
+ $('#PASSWD',section_graphics).parent().hide();
+ $('#KEYMAP',section_graphics).parent().hide();
+ $('#PORT',section_graphics).parent().attr("disabled","disabled");
+ $('#PASSWD',section_graphics).parent().attr("disabled","disabled");
+ $('#KEYMAP',section_graphics).parent().attr("disabled","disabled");
+ break;
+ default:
+ $('#LISTEN',section_graphics).parent().hide();
+ $('#PORT',section_graphics).parent().hide();
+ $('#PASSWD',section_graphics).parent().hide();
+ $('#KEYMAP',section_graphics).parent().hide();
- }
- });
+ }
+ });
- }
+ }
//Set up the context section - TODO: Apply improvements here...
- var context_setup = function(){
- $('fieldset',section_context).hide();
+ var context_setup = function(){
+ $('fieldset',section_context).hide();
- $('#add_context',section_context).click(function(){
- $('fieldset',section_context).toggle();
- return false;
- });
+ $('#add_context',section_context).click(function(){
+ $('fieldset',section_context).toggle();
+ return false;
+ });
$('#add_context_button', section_context).click(function(){
var name = $('#var_name',section_context).val();
@@ -1580,91 +1580,91 @@ function setupCreateTemplateDialog(){
return false;
}
option= '';
+ name+'='+value+
+ '';
$('select#context_box',section_context).append(option);
return false;
});
$('#remove_context_button', section_context).click(function(){
- box_remove_element(section_context,'#context_box');
- return false;
+ box_remove_element(section_context,'#context_box');
+ return false;
});
- };
+ };
// Set up the placement section
- var placement_setup = function(){
- $('fieldset',section_placement).hide();
+ var placement_setup = function(){
+ $('fieldset',section_placement).hide();
- $('#add_placement',section_placement).click(function(){
- $('fieldset',section_placement).toggle();
- return false;
- });
+ $('#add_placement',section_placement).click(function(){
+ $('fieldset',section_placement).toggle();
+ return false;
+ });
- };
+ };
// Set up the raw section
- var raw_setup = function(){
- $('fieldset',section_raw).hide();
+ var raw_setup = function(){
+ $('fieldset',section_raw).hide();
- $('#add_raw',section_raw).click(function(){
- $('fieldset',section_raw).toggle();
- return false;
- });
- };
+ $('#add_raw',section_raw).click(function(){
+ $('fieldset',section_raw).toggle();
+ return false;
+ });
+ };
//set up the custom variables section
var custom_variables_setup = function(){
$('fieldset',section_custom_var).hide();
$('#add_custom_var',section_custom_var).click(function(){
- $('fieldset',section_custom_var).toggle();
- return false;
+ $('fieldset',section_custom_var).toggle();
+ return false;
});
$('#add_custom_var_button', section_custom_var).click(
- function(){
- var name = $('#custom_var_name',section_custom_var).val();
- var value = $('#custom_var_value',section_custom_var).val();
- if (!name.length || !value.length) {
- notifyError("Custom variable name and value must be\
- filled in");
+ function(){
+ var name = $('#custom_var_name',section_custom_var).val();
+ var value = $('#custom_var_value',section_custom_var).val();
+ if (!name.length || !value.length) {
+ notifyError("Custom variable name and value must be\
+filled in");
+ return false;
+ }
+ option= '';
+ $('select#custom_var_box',section_custom_var).append(option);
return false;
- }
- option= '';
- $('select#custom_var_box',section_custom_var).append(option);
- return false;
- });
+ });
$('#remove_custom_var_button', section_custom_var).click(
function(){
box_remove_element(section_custom_var,'#custom_var_box');
return false;
- });
+ });
}
//***CREATE VM DIALOG MAIN BODY***
$('div#dialogs').append('');
- //Insert HTML in place
- $('#create_template_dialog').html(create_template_tmpl);
+ //Insert HTML in place
+ $('#create_template_dialog').html(create_template_tmpl);
//Enable tabs
- $('#template_create_tabs').tabs({
+ $('#template_create_tabs').tabs({
select:vmTabChange
- });
+ });
- //Prepare jquery dialog
+ //Prepare jquery dialog
var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window
- $('#create_template_dialog').dialog({
- autoOpen: false,
- modal: true,
- width: 700,
+ $('#create_template_dialog').dialog({
+ autoOpen: false,
+ modal: true,
+ width: 700,
height: height
- });
+ });
// Enhace buttons
$('#create_template_dialog button').button();
@@ -1674,37 +1674,37 @@ function setupCreateTemplateDialog(){
//Enable different icon for folded/unfolded categories
iconToggle(); //toogle +/- buttons
- //Sections, used to stay within their scope
- var section_capacity = $('#capacity');
- var section_os_boot = $('#os_boot_opts');
+ //Sections, used to stay within their scope
+ var section_capacity = $('#capacity');
+ var section_os_boot = $('#os_boot_opts');
var section_features = $('#features');
- var section_disks = $('#disks');
- var section_networks = $('#networks');
- var section_inputs = $('#inputs');
- var section_graphics = $('#graphics');
- var section_context = $('#context');
- var section_placement = $('#placement');
- var section_raw = $('#raw');
+ var section_disks = $('#disks');
+ var section_networks = $('#networks');
+ var section_inputs = $('#inputs');
+ var section_graphics = $('#graphics');
+ var section_context = $('#context');
+ var section_placement = $('#placement');
+ var section_raw = $('#raw');
var section_custom_var = $('#custom_var');
- //Different selector for items of kvm and xen (mandatory and optional)
- var items = '.vm_param input,.vm_param select';
- var kvm_man_items = '.kvm input,.kvm select';
- var kvm_opt_items = '.kvm_opt input, .kvm_opt select';
- var kvm_items = kvm_man_items +','+kvm_opt_items;
- var xen_man_items = '.xen input,.xen select';
- var xen_opt_items = '.xen_opt input, .xen_opt select';
- var xen_items = xen_man_items +','+ xen_opt_items;
+ //Different selector for items of kvm and xen (mandatory and optional)
+ var items = '.vm_param input,.vm_param select';
+ var kvm_man_items = '.kvm input,.kvm select';
+ var kvm_opt_items = '.kvm_opt input, .kvm_opt select';
+ var kvm_items = kvm_man_items +','+kvm_opt_items;
+ var xen_man_items = '.xen input,.xen select';
+ var xen_opt_items = '.xen_opt input, .xen_opt select';
+ var xen_items = xen_man_items +','+ xen_opt_items;
var vmware_man_items = '.vmware input,.vmware select';
- var vmware_opt_items = '.vmware_opt input, .vmware_opt select';
- var vmware_items = vmware_man_items +','+ vmware_opt_items;
+ var vmware_opt_items = '.vmware_opt input, .vmware_opt select';
+ var vmware_items = vmware_man_items +','+ vmware_opt_items;
- //Starting template type, optional items class and mandatory items class
- var templ_type = "kvm";
- var opt_class=".kvm_opt";
- var man_class=".kvm";
+ //Starting template type, optional items class and mandatory items class
+ var templ_type = "kvm";
+ var opt_class=".kvm_opt";
+ var man_class=".kvm";
- enable_kvm(); //enable all kvm options
+ enable_kvm(); //enable all kvm options
//Fold/unfold all sections button
$('#fold_unfold_vm_params').toggle(
@@ -1719,75 +1719,75 @@ function setupCreateTemplateDialog(){
});
//initialise all sections
- capacity_setup();
- os_boot_setup();
+ capacity_setup();
+ os_boot_setup();
features_setup();
- disks_setup();
- networks_setup();
- inputs_setup();
- graphics_setup();
- context_setup();
- placement_setup();
- raw_setup();
+ disks_setup();
+ networks_setup();
+ inputs_setup();
+ graphics_setup();
+ context_setup();
+ placement_setup();
+ raw_setup();
custom_variables_setup();
//Process form
- $('button#create_template_form_easy').click(function(){
- //validate form
+ $('button#create_template_form_easy').click(function(){
+ //validate form
- var vm_json = {};
+ var vm_json = {};
var name,value,boot_method;
- //process capacity options
- var scope = section_capacity;
+ //process capacity options
+ var scope = section_capacity;
- if (!mandatory_filter(scope)){
- notifyError("There are mandatory fields missing in the capacity section");
- return false;
- };
- addSectionJSON(vm_json,scope);
+ if (!mandatory_filter(scope)){
+ notifyError("There are mandatory fields missing in the capacity section");
+ return false;
+ };
+ addSectionJSON(vm_json,scope);
- //process os_boot_opts
- scope= section_os_boot;
- switch (templ_type){
- case "xen":
- boot_method = $('#boot_method option:selected',scope).val();
- if (!boot_method.length){
- notifyError("Xen templates must specify a boot method");
- return false;}
- };
+ //process os_boot_opts
+ scope= section_os_boot;
+ switch (templ_type){
+ case "xen":
+ boot_method = $('#boot_method option:selected',scope).val();
+ if (!boot_method.length){
+ notifyError("Xen templates must specify a boot method");
+ return false;}
+ };
- if (!mandatory_filter(scope)){
- notifyError("There are mandatory fields missing in the OS Boot options section");
- return false;
- };
+ if (!mandatory_filter(scope)){
+ notifyError("There are mandatory fields missing in the OS Boot options section");
+ return false;
+ };
vm_json["OS"] = {};
- addSectionJSON(vm_json["OS"],scope);
+ addSectionJSON(vm_json["OS"],scope);
//Fetch pae and acpi options
scope = section_features;
vm_json["FEATURES"] = {};
addSectionJSON(vm_json["FEATURES"],scope);
- //process disks -> fetch from box
- scope = section_disks;
- vm_json["DISK"] = [];
- addBoxJSON(vm_json["DISK"],scope,'#disks_box');
+ //process disks -> fetch from box
+ scope = section_disks;
+ vm_json["DISK"] = [];
+ addBoxJSON(vm_json["DISK"],scope,'#disks_box');
- //process nics -> fetch from box
- scope = section_networks;
- vm_json["NIC"] = [];
- addBoxJSON(vm_json["NIC"],scope,'#nics_box');
+ //process nics -> fetch from box
+ scope = section_networks;
+ vm_json["NIC"] = [];
+ addBoxJSON(vm_json["NIC"],scope,'#nics_box');
- //process inputs -> fetch from box
- scope = section_inputs;
- vm_json["INPUT"] = [];
- addBoxJSON(vm_json["INPUT"],scope,'#inputs_box');
+ //process inputs -> fetch from box
+ scope = section_inputs;
+ vm_json["INPUT"] = [];
+ addBoxJSON(vm_json["INPUT"],scope,'#inputs_box');
- //process graphics -> fetch fields with value
- scope = section_graphics;
- vm_json["GRAPHICS"] = {};
- addSectionJSON(vm_json["GRAPHICS"],scope);
+ //process graphics -> fetch fields with value
+ scope = section_graphics;
+ vm_json["GRAPHICS"] = {};
+ addSectionJSON(vm_json["GRAPHICS"],scope);
//context
scope = section_context;
@@ -1808,10 +1808,10 @@ function setupCreateTemplateDialog(){
$('input#RANK',scope).val(rank);
addSectionJSON(vm_json,scope);
- //raw -> if value set type to driver and fetch
- scope = section_raw;
- vm_json["RAW"] = {};
- addSectionJSON(vm_json["RAW"],scope);
+ //raw -> if value set type to driver and fetch
+ scope = section_raw;
+ vm_json["RAW"] = {};
+ addSectionJSON(vm_json["RAW"],scope);
//custom vars
scope = section_custom_var;
@@ -1831,30 +1831,28 @@ function setupCreateTemplateDialog(){
Sunstone.runAction("Template.create",vm_json);
$('#create_template_dialog').dialog('close');
- return false;
- });
+ return false;
+ });
//Handle manual forms
- $('button#create_template_form_manual').click(function(){
- var template = $('#textarea_vm_template').val();
+ $('button#create_template_form_manual').click(function(){
+ var template = $('#textarea_vm_template').val();
//wrap it in the "vm" object
template = {"vmtemplate": {"template_raw": template}};
Sunstone.runAction("Template.create",template);
- $('#create_template_dialog').dialog('close');
- return false;
- });
+ $('#create_template_dialog').dialog('close');
+ return false;
+ });
//Reset form - empty boxes
- $('button#reset_vm_form').click(function(){
- $('select#disks_box option',section_disks).remove();
- $('select#nics_box option',section_networks).remove();
- $('select#inputs_box option',section_inputs).remove();
- return true;
- });
-
-
+ $('button#reset_vm_form').click(function(){
+ $('select#disks_box option',section_disks).remove();
+ $('select#nics_box option',section_networks).remove();
+ $('select#inputs_box option',section_inputs).remove();
+ return true;
+ });
}
@@ -1864,13 +1862,13 @@ function popUpCreateTemplateDialog(){
// Set the autorefresh interval for the datatable
function setTemplateAutorefresh() {
- setInterval(function(){
- var checked = $('input:checked',dataTable_templates.fnGetNodes());
+ setInterval(function(){
+ var checked = $('input:checked',dataTable_templates.fnGetNodes());
var filter = $("#datatable_templates_filter input").attr("value");
- if (!checked.length && !filter.length){
+ if (!checked.length && !filter.length){
Sunstone.runAction("Template.autorefresh");
- }
- },INTERVAL+someTime());
+ }
+ },INTERVAL+someTime());
}
//The DOM is ready at this point
diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js
index 85440944c7..8c0a860d2f 100644
--- a/src/sunstone/public/js/plugins/users-tab.js
+++ b/src/sunstone/public/js/plugins/users-tab.js
@@ -87,7 +87,11 @@ var user_actions = {
"User.autorefresh" : {
type: "custom",
call: function(){
- OpenNebula.User.list({timeout: true, success: updateUsersView, error: onError});
+ OpenNebula.User.list({
+ timeout: true,
+ success: updateUsersView,
+ error: onError
+ });
},
condition: function(){ uid == 0 },
notify: false
@@ -197,8 +201,8 @@ function deleteUserElement(req){
// Callback to add a single user element
function addUserElement(request,user_json){
- var element = userElementArray(user_json);
- addElement(element,dataTable_users);
+ var element = userElementArray(user_json);
+ addElement(element,dataTable_users);
updateUserSelect();
}
@@ -217,34 +221,34 @@ function updateUsersView(request,users_list){
// Prepare the user creation dialog
function setupCreateUserDialog(){
- $('div#dialogs').append('');
- $('#create_user_dialog').html(create_user_tmpl);
+ $('div#dialogs').append('');
+ $('#create_user_dialog').html(create_user_tmpl);
- //Prepare jquery dialog
- $('#create_user_dialog').dialog({
- autoOpen: false,
- modal:true,
- width: 400
- });
+ //Prepare jquery dialog
+ $('#create_user_dialog').dialog({
+ autoOpen: false,
+ modal:true,
+ width: 400
+ });
$('#create_user_dialog button').button();
$('#create_user_form').submit(function(){
- var user_name=$('#username',this).val();
- var user_password=$('#pass',this).val();
+ var user_name=$('#username',this).val();
+ var user_password=$('#pass',this).val();
if (!user_name.length && !user_password.length){
notifyError("User name and password must be filled in");
return false;
}
- var user_json = { "user" :
- { "name" : user_name,
- "password" : user_password }
- };
- Sunstone.runAction("User.create",user_json);
- $('#create_user_dialog').dialog('close');
- return false;
- });
+ var user_json = { "user" :
+ { "name" : user_name,
+ "password" : user_password }
+ };
+ Sunstone.runAction("User.create",user_json);
+ $('#create_user_dialog').dialog('close');
+ return false;
+ });
}
function popUpCreateUserDialog(){
diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js
index 86553419dd..6fbb349cf5 100644
--- a/src/sunstone/public/js/plugins/vms-tab.js
+++ b/src/sunstone/public/js/plugins/vms-tab.js
@@ -75,17 +75,17 @@ var vms_tab_content =
var create_vm_tmpl ='
\
\
\
';
@@ -267,12 +267,12 @@ var vm_actions = {
type: "custom",
call: function(obj) {
OpenNebula.VM.saveas(
- {data:obj,
- success: function (req) {
- Sunstone.runAction("VM.show",
- req.request.data[0][0]);
- },
- error: onError });
+ {data:obj,
+ success: function (req) {
+ Sunstone.runAction("VM.show",
+ req.request.data[0][0]);
+ },
+ error: onError });
}
},
@@ -445,9 +445,9 @@ var vm_buttons = {
text: "Deploy",
tip: "This will deploy the selected VMs on the chosen host",
select: function(){
- if (hosts_select){return hosts_select}
- else {return ""}
- },
+ if (hosts_select){return hosts_select}
+ else {return ""}
+ },
condition: True
},
"VM.migrate" : {
@@ -455,9 +455,9 @@ var vm_buttons = {
text: "Migrate",
tip: "This will migrate the selected VMs to the chosen host",
select: function(){
- if (hosts_select){return hosts_select}
- else {return ""}
- },
+ if (hosts_select){return hosts_select}
+ else {return ""}
+ },
condition: True
},
@@ -466,9 +466,9 @@ var vm_buttons = {
text: "Live migrate",
tip: "This will live-migrate the selected VMs to the chosen host",
select: function(){
- if (hosts_select){return hosts_select}
- else {return ""}
- },
+ if (hosts_select){return hosts_select}
+ else {return ""}
+ },
condition: True
},
"VM.hold" : {
@@ -596,120 +596,122 @@ function vMachineElementArray(vm_json){
//Creates a listener for the TDs of the VM table
function vMachineInfoListener(){
- $('#tbodyvmachines tr').live("click", function(e){
- if ($(e.target).is('input') || $(e.target).is('a img')) {return true;}
+ $('#tbodyvmachines tr').live("click", function(e){
+ if ($(e.target).is('input') || $(e.target).is('a img')) {return true;}
popDialogLoading();
- var aData = dataTable_vMachines.fnGetData(this);
- var id = $(aData[0]).val();
+ var aData = dataTable_vMachines.fnGetData(this);
+ var id = $(aData[0]).val();
Sunstone.runAction("VM.showinfo",id);
- return false;
- });
+ return false;
+ });
}
// Callback to refresh a single element from the list
function updateVMachineElement(request, vm_json){
- var id = vm_json.VM.ID;
- var element = vMachineElementArray(vm_json);
- updateSingleElement(element,dataTable_vMachines,'#vm_'+id)
+ var id = vm_json.VM.ID;
+ var element = vMachineElementArray(vm_json);
+ updateSingleElement(element,dataTable_vMachines,'#vm_'+id)
}
// Callback to delete a single element from the list
function deleteVMachineElement(req){
- deleteElement(dataTable_vMachines,'#vm_'+req.request.data);
+ deleteElement(dataTable_vMachines,'#vm_'+req.request.data);
}
// Callback to add an element to the list
function addVMachineElement(request,vm_json){
var id = vm_json.VM.ID;
- var element = vMachineElementArray(vm_json);
- addElement(element,dataTable_vMachines);
+ var element = vMachineElementArray(vm_json);
+ addElement(element,dataTable_vMachines);
}
// Callback to refresh the list of Virtual Machines
function updateVMachinesView(request, vmachine_list){
- vmachine_list_json = vmachine_list;
- var vmachine_list_array = [];
+ vmachine_list_json = vmachine_list;
+ var vmachine_list_array = [];
- $.each(vmachine_list,function(){
- vmachine_list_array.push( vMachineElementArray(this));
- });
+ $.each(vmachine_list,function(){
+ vmachine_list_array.push( vMachineElementArray(this));
+ });
- updateView(vmachine_list_array,dataTable_vMachines);
- updateDashboard("vms",vmachine_list_json);
+ updateView(vmachine_list_array,dataTable_vMachines);
+ updateDashboard("vms",vmachine_list_json);
}
// Refreshes the information panel for a VM
function updateVMInfo(request,vm){
- var vm_info = vm.VM;
- var info_tab = {
+ var vm_info = vm.VM;
+ var info_tab = {
title : "VM information",
- content: '
');
}
if (selected_tab){
return info_panel.tabs({selected: selected_tab});
}
return info_panel.tabs({selected: 0});
-
+
},
-
+
//adds a tab to an info panel.
"addInfoPanelTab" : function(panel_name, panel_tab_id, panel_tab_obj){
SunstoneCfg["info_panels"][panel_name][panel_tab_id] = panel_tab_obj;
},
-
+
//Replaces a tab from an info panel. Refreshes the DOM if wanted.
- "updateInfoPanelTab" : function(panel_name, panel_tab_id,
- panel_tab_obj, refresh){
+ "updateInfoPanelTab" : function(panel_name, panel_tab_id,
+ panel_tab_obj, refresh){
SunstoneCfg["info_panels"][panel_name][panel_tab_id] = panel_tab_obj;
if (refresh){
var tab_content = panel_tab_obj.content;
$('div#'+panel_name+' div#'+panel_tab_id).html(tab_content);
}
},
-
+
//Removes a tab from an info panel configuration.
"removeInfoPanelTab" : function(panel_name,panel_tab_id){
delete SunstoneCfg["info_panels"][panel_name][panel_tab_id];
},
-
+
//Runs a predefined action. Wraps the calls to opennebula.js and
//can be use to run action depending on conditions and notify them
//if desired.
"runAction" : function(action, data_arg, extra_param){
-
+
var actions = SunstoneCfg["actions"];
if (!actions[action]){
notifyError("Action "+action+" not defined");
return;
}
-
+
var action_cfg = actions[action];
var notify = action_cfg.notify;
-
+
var condition = action_cfg["condition"];
-
+
//Is the condition to run the action met?
//Should we inform if it is not met?
if (condition && !condition()){
@@ -171,24 +171,24 @@ var Sunstone = {
}
return;
}
-
+
var call = action_cfg["call"];
var callback = action_cfg["callback"];
var err = action_cfg["error"];
-
-
+
+
//Time to close any confirmation dialogs, as the execution may have
//come from them.
$('div#confirm_with_select_dialog').dialog("close");
$('div#confirm_dialog').dialog("close");
-
-
+
+
//We ease the use of:
// * "create" calls to opennebula.js
// * "single" element calls to opennebula.js
// * "list" (get the pool of elements) calls to opennebula.js
- // * "monitor_global" (returns monitoring information from a pool of elements
- // * "monitor_single" (returns monitoring information from 1 element to create graphs)
+ // * "monitor_global" (returns monitoring info from a pool of elements
+ // * "monitor_single" (returns monitoring info from 1 element)
// * "multiple" - actions to be run on a given list of elements
// (with maybe an extra parameter).
// * The default actions. Simple call the the pre-defined "call"
@@ -201,7 +201,13 @@ var Sunstone = {
break;
case "single":
if (extra_param){
- call({data:{id:data_arg,extra_param:extra_param}, success: callback,error:err});
+ call({
+ data:{
+ id:data_arg,
+ extra_param:extra_param
+ },
+ success: callback,error:err
+ });
} else {
call({data:{id:data_arg}, success: callback,error:err});
};
@@ -210,23 +216,40 @@ var Sunstone = {
call({success: callback, error:err});
break;
case "monitor_global":
- call({timeout: true, success: callback, error:err, data: {monitor: data_arg}});
+ call({
+ timeout: true,
+ success: callback,
+ error:err,
+ data: {monitor: data_arg}});
break;
case "monitor":
case "monitor_single":
- call({timeout: true, success: callback, error:err, data: {id:data_arg, monitor: extra_param}});
+ call({
+ timeout: true,
+ success: callback,
+ error:err,
+ data: {id:data_arg, monitor: extra_param}});
break;
case "multiple":
//run on the list of nodes that come on the data
$.each(data_arg,function(){
if (extra_param){
- call({data:{id:this,extra_param:extra_param}, success: callback, error: err});
+ call({
+ data:{
+ id:this,
+ extra_param:extra_param
+ },
+ success: callback,
+ error: err});
} else {
- call({data:{id:this}, success: callback, error:err});
+ call({
+ data:{id:this},
+ success: callback,
+ error:err});
}
});
break;
- default:
+ default:
//This action is complemente handled by the "call" function.
//we pass any data if present.
if (data_arg && extra_param) {call(data_arg,extra_param);}
@@ -237,45 +260,24 @@ var Sunstone = {
if (notify) {
notifySubmit(action,data_arg,extra_param);
}
-
-
+
+
},
-
- //Runs a predefined action on the selected nodes of a datatable.
- //Optionally they are run with an extra_parameter.
- //If no datatable is provided, it simply runs the action.
- //~ "runActionOnDatatableNodes": function(action,dataTable,extra_param){
- //~ if (dataTable != null){
- //~
- //~ //Which rows of the datatable are checked?
- //~ var nodes = $('input:checked',dataTable.fnGetNodes());
- //~ var data = [];
- //~ $.each(nodes,function(){
- //~ data.push($(this).val());
- //~ });
- //~ Sunstone.runAction(action,data,extra_param);
- //~
- //~ } else {
- //~ Sunstone.runAction(action,extra_param);
- //~ };
- //~ },
- //~
+
//returns a button object from the desired tab
"getButton" : function(tab_id,button_name){
- var button = null;
- var buttons = SunstoneCfg["tabs"][tab_id]["buttons"];
- button = buttons[button_name];
- //not found, is it in the list then?
- if (!button && buttons["action_list"])
- {
- button = buttons["action_list"]["actions"][button_name];
- }
- return button;
+ var button = null;
+ var buttons = SunstoneCfg["tabs"][tab_id]["buttons"];
+ button = buttons[button_name];
+ //not found, is it in the list then?
+ if (!button && buttons["action_list"])
+ {
+ button = buttons["action_list"]["actions"][button_name];
+ }
+ return button;
} //end sunstone methods
-
+
};
-
-
@@ -284,58 +286,61 @@ var Sunstone = {
$(document).ready(function(){
readCookie();
setLogin();
-
+
//Insert the tabs in the DOM and their buttons.
insertTabs();
insertButtons();
-
+
//Enhace the look of select buttons
initListButtons();
-
+
//Prepare the standard confirmation dialogs
setupConfirmDialogs();
//This dialog is shared to update templates
setupTemplateUpdateDialog();
-
+
//Listen for .action_buttons
- //An action buttons runs a predefined action. If it has type
+ //An action buttons runs a predefined action. If it has type
//"multiple" it runs that action on the elements of a datatable.
$('.action_button').live("click",function(){
-
+
var table = null;
var value = $(this).attr("value");
var action = SunstoneCfg["actions"][value];
- if (!action) { notifyError("Action "+value+" not defined."); return false;};
+ if (!action) {
+ notifyError("Action "+value+" not defined.");
+ return false;
+ };
switch (action.type){
- case "multiple": //find the datatable
- var nodes = action.elements();
- Sunstone.runAction(value,nodes);
- break;
- default:
- Sunstone.runAction(value);
+ case "multiple": //find the datatable
+ var nodes = action.elements();
+ Sunstone.runAction(value,nodes);
+ break;
+ default:
+ Sunstone.runAction(value);
}
return false;
});
-
-
+
+
//Listen .confirm_buttons. These buttons show a confirmation dialog
//before running the action.
$('.confirm_button').live("click",function(){
popUpConfirmDialog(this);
return false;
});
-
+
//Listen .confirm_buttons. These buttons show a confirmation dialog
//with a select box before running the action.
$('.confirm_with_select_button').live("click",function(){
popUpConfirmWithSelectDialog(this);
return false;
});
-
+
//Jquery-enhace the buttons in the DOM
$('button').button();
-
+
//Close overlay dialogs when clicking outside of them.
$(".ui-widget-overlay").live("click", function (){
$("div:ui-dialog:visible").dialog("close");
@@ -345,10 +350,10 @@ $(document).ready(function(){
$('*:not(.action_list,.list_button)').click(function(){
$('.action_list:visible').hide();
});
-
+
//Start with the dashboard (supposing we have one).
showTab('#dashboard_tab');
-
+
});
@@ -364,7 +369,7 @@ function readCookie(){
});
}
-//sets the user info in the top bar and creates a listner in the
+//sets the user info in the top bar and creates a listner in the
//signout button
function setLogin(){
//This two variables can be used anywhere
@@ -373,10 +378,11 @@ function setLogin(){
$("#user").html(username);
$("#logout").click(function(){
- OpenNebula.Auth.logout({success:function(){
- window.location.href = "/login";
- }
- });
+ OpenNebula.Auth.logout({
+ success:function(){
+ window.location.href = "/login";
+ }
+ });
return false;
});
}
@@ -400,7 +406,7 @@ function insertTab(tab_name){
if (condition && !condition()) {return;}
$("div.inner-center").append('');
$('div#'+tab_name).html(tab_info.content);
-
+
$('ul#navigation').append('
');
}
@@ -419,11 +425,11 @@ function insertButtonsInTab(tab_name){
var button_code="";
var sel_obj=null;
var condition=null;
-
+
//Check if we have included an appropiate space our tab to
//insert them (an .action_blocks div)
if ($('div#'+tab_name+' div.action_blocks').length){
-
+
//for every button defined for this tab...
for (button_name in buttons){
button_code = "";
@@ -431,7 +437,7 @@ function insertButtonsInTab(tab_name){
condition = button.condition;
//if we meet the condition we proceed. Otherwise we skip it.
if (condition && !condition()) { continue; }
-
+
//depending on the type of button we generate different
//code. There are 4 possible types:
/*
@@ -441,7 +447,7 @@ function insertButtonsInTab(tab_name){
* default: generally buttons have the "_button" class.
*/
switch (button.type) {
- case "select":
+ case "select":
button_code = '';
break;
- case "image":
+ case "image":
button_code = '';
break;
- case "create_dialog":
+ case "create_dialog":
button_code = '';
break;
- default:
+ default:
button_code = '';
-
+
}
-
+
if (button.alwaysActive) {
button_code = $(button_code).addClass("alwaysActive");
}
-
+
$('div#'+tab_name+' .action_blocks').append(button_code);
-
+
}//for each button in tab
$('.top_button').button();
}//if tab exists
}
-//Converts selects into buttons which show a list of actions when
-//clicked. This lists have two parts, one for the last action run, and
+//Converts selects into buttons which show a list of actions when
+//clicked. This lists have two parts, one for the last action run, and
//another containing a list of actions that can be folded/unfolded.
function initListButtons(){
- //for each multi_action select
- $('.multi_action_slct').each(function(){
- //prepare replacement buttons
- var buttonset = $('Previous action').button();
- button1.attr("disabled","disabled");
- var button2 = $('').button({
- text:false,
- icons: { primary: "ui-icon-triangle-1-s" }
- });
- buttonset.append(button1);
- buttonset.append(button2);
- buttonset.buttonset();
-
- //prepare list
- var options = $('option', $(this));
- var list = $('
');
- $.each(options,function(){
- var classes = $(this).attr("class");
- var item = $('');
- var a = $(''+$(this).text()+'');
- a.val($(this).val());
- item.html(a);
- list.append(item);
- });
- list.css({
- "display":"none"
- });
-
-
- //replace the select and insert the buttons
- $(this).before(buttonset);
- $(this).parents('.action_blocks').append(list);
- $(this).remove();
- //$(this).replaceWith(list);
+ //for each multi_action select
+ $('.multi_action_slct').each(function(){
+ //prepare replacement buttons
+ var buttonset = $('Previous action').button();
+ button1.attr("disabled","disabled");
+ var button2 = $('').button({
+ text:false,
+ icons: { primary: "ui-icon-triangle-1-s" }
+ });
+ buttonset.append(button1);
+ buttonset.append(button2);
+ buttonset.buttonset();
+ //prepare list
+ var options = $('option', $(this));
+ var list = $('
');
+ $.each(options,function(){
+ var classes = $(this).attr("class");
+ var item = $('');
+ var a = $(''+$(this).text()+'');
+ a.val($(this).val());
+ item.html(a);
+ list.append(item);
+ });
+ list.css({
+ "display":"none"
});
+ $(this).before(buttonset);
+ $(this).parents('.action_blocks').append(list);
+ $(this).remove();
- //below the listeners for events on these buttons and list
+ });
- //enable run the last action button
- $('.action_list li a').click(function(){
- //enable run last action button
- var prev_action_button = $('.last_action_button',$(this).parents('.action_blocks'));
- prev_action_button.val($(this).val());
- prev_action_button.removeClass("confirm_with_select_button");
- prev_action_button.removeClass("confirm_button");
- prev_action_button.removeClass("action_button");
- prev_action_button.addClass($(this).attr("class"));
- prev_action_button.button("option","label",$(this).text());
- prev_action_button.button("enable");
- $(this).parents('ul').hide("blind",100);
- //return false;
- });
+ //below the listeners for events on these buttons and list
+ //enable run the last action button
+ $('.action_list li a').click(function(){
+ //enable run last action button
+ var prev_action_button = $('.last_action_button',$(this).parents('.action_blocks'));
+ prev_action_button.val($(this).val());
+ prev_action_button.removeClass("confirm_with_select_button");
+ prev_action_button.removeClass("confirm_button");
+ prev_action_button.removeClass("action_button");
+ prev_action_button.addClass($(this).attr("class"));
+ prev_action_button.button("option","label",$(this).text());
+ prev_action_button.button("enable");
+ $(this).parents('ul').hide("blind",100);
+ //return false;
+ });
//Show the list of actions in place
$('.list_button').click(function(){
@@ -551,93 +552,90 @@ function initListButtons(){
//Prepares the standard confirm dialogs
function setupConfirmDialogs(){
-
+
//add div to the main body if it isn't present.
if (!($('div#confirm_dialog').length)){
$('div#dialogs').append('');
};
//add the HTML with the standard question and buttons.
- $('div#confirm_dialog').html(
- '
\
-
You have to confirm this action.
\
- \
-
Do you want to proceed?
\
- \
-
\
- \
- \
-
\
-
');
-
+ $('div#confirm_dialog').html(
+ '
\
+
You have to confirm this action.
\
+ \
+
Do you want to proceed?
\
+ \
+
\
+ \
+ \
+
\
+
');
+
//prepare the jquery dialog
- $('div#confirm_dialog').dialog({
- resizable:false,
- modal:true,
- width:300,
- heigth:200,
- autoOpen:false
- });
+ $('div#confirm_dialog').dialog({
+ resizable:false,
+ modal:true,
+ width:300,
+ heigth:200,
+ autoOpen:false
+ });
//enhace the button look
$('div#confirm_dialog button').button();
-
+
//same for the confirm with select dialog.
if (!($('div#confirm_with_select_dialog').length)){
$('div#dialogs').append('');
};
- $('div#confirm_with_select_dialog').html(
- '
');
+
//prepare the jquery dialog
- $('div#confirm_with_select_dialog').dialog({
- resizable:false,
- modal:true,
- width:300,
- heigth:300,
- autoOpen:false
- });
-
+ $('div#confirm_with_select_dialog').dialog({
+ resizable:false,
+ modal:true,
+ width:300,
+ heigth:300,
+ autoOpen:false
+ });
+
$('div#confirm_with_select_dialog button').button();
-
+
//if a cancel button is pressed, we close the dialog.
$('button.confirm_cancel').click(function(){
- $('div#confirm_with_select_dialog').dialog("close");
+ $('div#confirm_with_select_dialog').dialog("close");
$('div#confirm_dialog').dialog("close");
- return false;
- });
-
+ return false;
+ });
+
//when we proceed with a "confirm with select" we need to
//find out if we are running an action with a parametre on a datatable
- //items or if its just an action
+ //items or if its just an action
$('button#confirm_with_select_proceed').click(function(){
var value = $(this).val();
var action = SunstoneCfg["actions"][value];
var param = $('select#confirm_select').val();
if (!action) { notifyError("Action "+value+" not defined."); return false;};
switch (action.type){
- case "multiple": //find the datatable
- var nodes = action.elements();
- Sunstone.runAction(value,nodes,param);
- break;
- default:
- Sunstone.runAction(value,param);
- break;
+ case "multiple": //find the datatable
+ var nodes = action.elements();
+ Sunstone.runAction(value,nodes,param);
+ break;
+ default:
+ Sunstone.runAction(value,param);
+ break;
}
return false;
-
});
-
}
//Popup a confirmation dialog.
@@ -666,9 +664,7 @@ function popUpConfirmWithSelectDialog(target_elem){
var select_var = button.select();
$('select#confirm_select').html(select_var);
$('div#confirm_with_select_tip').text(tip);
-
+
$('button#confirm_with_select_proceed').val(value);
$('div#confirm_with_select_dialog').dialog("open");
}
-
-