From 683429affae618506648d7a89dfba2c73cc51fd4 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 13 Jun 2011 18:02:43 +0200 Subject: [PATCH] Feature #407: Code clean up Tabs removed, whitespaces removed, corrected indentation etc... --- .../public/js/plugins/dashboard-tab.js | 21 +- src/sunstone/public/js/plugins/groups-tab.js | 69 +- src/sunstone/public/js/plugins/hosts-tab.js | 142 +-- src/sunstone/public/js/plugins/images-tab.js | 425 +++---- .../public/js/plugins/templates-tab.js | 1110 ++++++++--------- src/sunstone/public/js/plugins/users-tab.js | 46 +- src/sunstone/public/js/plugins/vms-tab.js | 351 +++--- src/sunstone/public/js/plugins/vnets-tab.js | 313 +++-- src/sunstone/public/js/sunstone-util.js | 17 +- src/sunstone/public/js/sunstone.js | 444 ++++--- 10 files changed, 1471 insertions(+), 1467 deletions(-) diff --git a/src/sunstone/public/js/plugins/dashboard-tab.js b/src/sunstone/public/js/plugins/dashboard-tab.js index 2069cec394..ac5b375c36 100644 --- a/src/sunstone/public/js/plugins/dashboard-tab.js +++ b/src/sunstone/public/js/plugins/dashboard-tab.js @@ -184,23 +184,26 @@ function plot_global_graph(data,info){ }; var options = { - legend : { show : true, - noColumns: labels_arr.length, - container: $('#'+id+'_legend')}, - xaxis : { mode: "time", - timeformat: "%h:%M" - }, + legend : { + show : true, + noColumns: labels_arr.length, + container: $('#'+id+'_legend') + }, + xaxis : { + mode: "time", + timeformat: "%h:%M" + }, yaxis : { labelWidth: 40 } } switch (id){ case "graph3": case "graph5": - options["yaxis"]["tickFormatter"] = function(val,axis) { return humanize_size(val); } + options["yaxis"]["tickFormatter"] = function(val,axis) { + return humanize_size(val); + } } - - $.plot($('#'+id+'_graph'),series,options); } diff --git a/src/sunstone/public/js/plugins/groups-tab.js b/src/sunstone/public/js/plugins/groups-tab.js index 36595da461..a3191eda6c 100644 --- a/src/sunstone/public/js/plugins/groups-tab.js +++ b/src/sunstone/public/js/plugins/groups-tab.js @@ -19,7 +19,7 @@ var group_list_json = {}; var dataTable_groups; -var groups_tab_content = +var groups_tab_content = '
\
\
\ @@ -40,16 +40,16 @@ var groups_tab_content = var create_group_tmpl = '\
\ -
\ - \ -
\ -
\ +
\ + \ +
\ +
\
\
\ -
\ - \ - \ -
\ +
\ + \ + \ +
\
\
'; @@ -67,7 +67,7 @@ var group_actions = { type: "custom", call: popUpCreateGroupDialog }, - + "Group.list" : { type: "list", call: OpenNebula.Group.list, @@ -79,7 +79,7 @@ var group_actions = { // type: "custom", // call: updateGroupInfo // }, - + "Group.autorefresh" : { type: "custom", call: function () { @@ -97,7 +97,7 @@ var group_actions = { error: onError, notify: false }, - + "Group.delete" : { type: "multiple", call : OpenNebula.Group.delete, @@ -106,7 +106,7 @@ var group_actions = { elements: function() { return getSelectedNodes(dataTable_groups); }, notify:true }, - + "Group.chown" : { type: "multiple", call : OpenNebula.Group.chown, @@ -115,7 +115,7 @@ var group_actions = { error : onError, notify:true }, - + } var group_buttons = { @@ -157,24 +157,25 @@ Sunstone.addMainTab('groups_tab',groups_tab); function groupElementArray(group_json){ var group = group_json.GROUP; - return [ '', - group.ID, - getUserName(group.UID), - group.NAME ]; + return [ + '', + group.ID, + getUserName(group.UID), + group.NAME ]; } function groupInfoListener(){ $('#tbodygroups tr').live("click",function(e){ - //do nothing if we are clicking a checkbox! - if ($(e.target).is('input')) {return true;} - var aData = dataTable_groups.fnGetData(this); - var id = $(aData[0]).val(); + //do nothing if we are clicking a checkbox! + if ($(e.target).is('input')) {return true;} + var aData = dataTable_groups.fnGetData(this); + var id = $(aData[0]).val(); Sunstone.runAction("Group.showinfo",id); - return false; + return false; }); } -function updateGroupSelect(){ +function updateGroupSelect(){ groups_select = makeSelectOptions(dataTable_groups,1,3,-1,"",-1); } @@ -216,19 +217,19 @@ function setupCreateGroupDialog(){ $('div#dialogs').append('
'); $('#create_group_dialog').html(create_group_tmpl); $('#create_group_dialog').dialog({ - autoOpen: false, - modal: true, - width: 400 + autoOpen: false, + modal: true, + width: 400 }); - + $('#create_group_dialog button').button(); - + $('#create_group_form').submit(function(){ - var name=$('#name',this).val(); - var group_json = { "group" : { "name" : name }}; + var name=$('#name',this).val(); + var group_json = { "group" : { "name" : name }}; Sunstone.runAction("Group.create",group_json); - $('#create_group_dialog').dialog('close'); - return false; + $('#create_group_dialog').dialog('close'); + return false; }); } @@ -273,5 +274,3 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_groups); tableCheckboxesListener(dataTable_groups); }) - - diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 8d1d65e550..e2ec4c281e 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -33,8 +33,7 @@ var host_graphs = [ ] - -var hosts_tab_content = +var hosts_tab_content = '
\
\
\ @@ -64,37 +63,37 @@ var create_host_tmpl =

Drivers

\
\
\ - \ - \ + \ + \
\
\ \ \ + \ + \ + \ + \ + \
\
\ \ \ + \ + \ + \ + \
\
\
\
\ -
\ -
\ -
\ +
\ +
\ + \
\
'; @@ -104,7 +103,7 @@ var dataTable_hosts; //Setup actions var host_actions = { - + "Host.create" : { type: "create", call : OpenNebula.Host.create, @@ -245,7 +244,7 @@ var host_info_panel = { title: "Host information", content:"" }, - + "host_template_tab" : { title: "Host template", content: "" @@ -262,17 +261,16 @@ var hosts_tab = { content: hosts_tab_content, buttons: host_buttons, condition: True -} +} Sunstone.addActions(host_actions); Sunstone.addMainTab('hosts_tab',hosts_tab); Sunstone.addInfoPanel("host_info_panel",host_info_panel); - //Creates an array to be added to the dataTable from the JSON of a host. function hostElementArray(host_json){ - + var host = host_json.HOST; //Calculate some values @@ -314,26 +312,27 @@ function hostElementArray(host_json){ '; - return [ '', - host.ID, - host.NAME, - host.HOST_SHARE.RUNNING_VMS, //rvm - pb_cpu, - pb_mem, - OpenNebula.Helper.resource_state("host_simple",host.STATE) ]; + return [ + '', + host.ID, + host.NAME, + host.HOST_SHARE.RUNNING_VMS, //rvm + pb_cpu, + pb_mem, + OpenNebula.Helper.resource_state("host_simple",host.STATE) ]; } //Listen to clicks on the tds of the tables and shows the info dialogs. function hostInfoListener(){ $('#tbodyhosts tr').live("click",function(e){ - //do nothing if we are clicking a checkbox! - if ($(e.target).is('input')) {return true;} + //do nothing if we are clicking a checkbox! + if ($(e.target).is('input')) {return true;} popDialogLoading(); - var aData = dataTable_hosts.fnGetData(this); - var id = $(aData[0]).val(); + var aData = dataTable_hosts.fnGetData(this); + var id = $(aData[0]).val(); Sunstone.runAction("Host.showinfo",id); - return false; + return false; }); } @@ -370,8 +369,8 @@ function updateHostsView (request,host_list){ var host_list_array = []; $.each(host_list,function(){ - //Grab table data from the host_list - host_list_array.push(hostElementArray(this)); + //Grab table data from the host_list + host_list_array.push(hostElementArray(this)); }); updateView(host_list_array,dataTable_hosts); @@ -482,30 +481,33 @@ function setupCreateHostDialog(){ $('div#dialogs').append('
'); $('div#create_host_dialog').html(create_host_tmpl); $('#create_host_dialog').dialog({ - autoOpen: false, - modal: true, - width: 500 - }); - + autoOpen: false, + modal: true, + width: 500 + }); + $('#create_host_dialog button').button(); - + //Handle the form submission $('#create_host_form').submit(function(){ if (!($('#name',this).val().length)){ notifyError("Host name missing!"); return false; } - var host_json = { "host": { "name": $('#name',this).val(), - "tm_mad": $('#tm_mad :selected',this).val(), - "vm_mad": $('#vmm_mad :selected',this).val(), - "im_mad": $('#im_mad :selected',this).val()}} + var host_json = { + "host": { + "name": $('#name',this).val(), + "tm_mad": $('#tm_mad :selected',this).val(), + "vm_mad": $('#vmm_mad :selected',this).val(), + "im_mad": $('#im_mad :selected',this).val() + } + } - //Create the OpenNebula.Host. - //If it's successfull we refresh the list. + //Create the OpenNebula.Host. + //If it's successfull we refresh the list. Sunstone.runAction("Host.create",host_json); - //OpenNebula.Host.create({data: host_json, success: addHostElement, error: onError}); - $('#create_host_dialog').dialog('close'); - return false; + $('#create_host_dialog').dialog('close'); + return false; }); } @@ -527,35 +529,35 @@ function setHostAutorefresh() { } //This is executed after the sunstone.js ready() is run. -//Here we can basicly init the host datatable, preload it +//Here we can basicly init the host datatable, preload it //and add specific listeners $(document).ready(function(){ //prepare host datatable dataTable_hosts = $("#datatable_hosts").dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "bAutoWidth":false, - "sPaginationType": "full_numbers", - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,4] }, - { "sWidth": "35px", "aTargets": [1] }, - { "sWidth": "200px", "aTargets": [5,6] } - ] + "bJQueryUI": true, + "bSortClasses": false, + "bAutoWidth":false, + "sPaginationType": "full_numbers", + "aoColumnDefs": [ + { "bSortable": false, "aTargets": ["check"] }, + { "sWidth": "60px", "aTargets": [0,3] }, + { "sWidth": "35px", "aTargets": [1] }, + { "sWidth": "200px", "aTargets": [4,5] } + ] }); - + //preload it dataTable_hosts.fnClearTable(); addElement([ spinner, '','','','','',''],dataTable_hosts); Sunstone.runAction("Host.list"); - + setupCreateHostDialog(); - + setHostAutorefresh(); - + initCheckAllBoxes(dataTable_hosts); tableCheckboxesListener(dataTable_hosts); hostInfoListener(); diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index b78289cd7f..bb6938ee11 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -47,111 +47,111 @@ var create_image_tmpl =
  • Advanced mode
  • \ \
    \ -
    \ -

    Fields marked with are mandatory
    \ -

    \ -
    \ - \ - \ -
    Name that the Image will get. Every image must have a unique name.
    \ -
    \ -
    \ - \ - \ -
    Human readable description of the image for other users.
    \ -
    \ -
    \ -
    \ -
    \ - \ - \ -
    Type of the image, explained in detail in the following section. If omitted, the default value is the one defined in oned.conf (install default is OS).
    \ -
    \ -
    \ - \ - \ -
    Public scope of the image
    \ -
    \ -
    \ - \ - \ -
    Persistence of the image
    \ -
    \ -
    \ - \ - \ -
    Prefix for the emulated device this image will be mounted at. For instance, “hd”, “sd”. If omitted, the default value is the one defined in oned.conf (installation default is “hd”).
    \ -
    \ -
    \ - \ - \ -
    Type of disk device to emulate.
    \ -
    \ -
    \ -
    \ -
    \ - \ - \ -
    \ - \ -
    \ - \ - \ -
    Please choose path if you have a file-based image. Choose source otherwise or create an empty datablock disk.

    \ -
    \ -
    \ - \ - \ -
    Path to the original file that will be copied to the image repository. If not specified for a DATABLOCK type image, an empty image will be created.
    \ -
    \ -
    \ - \ - \ -
    Source to be used in the DISK attribute. Useful for not file-based images.
    \ -
    \ -
    \ - \ - \ -
    Size of the datablock in MB.
    \ -
    \ -
    \ - \ - \ -
    Type of file system to be built. This can be any value understood by mkfs unix command.
    \ -
    \ -
    \ -
    \ -
    \ - \ - \ -
    \ -
    \ -
    \ -
    \ -
    \ -
    \ -
    \ -

    Write the image template here

    \ - \ + \ +

    Fields marked with are mandatory
    \ +

    \ +
    \ + \ + \ +
    Name that the Image will get. Every image must have a unique name.
    \ +
    \ +
    \ + \ + \ +
    Human readable description of the image for other users.
    \ +
    \
    \
    \ -
    \ - \ +
    \ + \ + \ +
    Type of the image, explained in detail in the following section. If omitted, the default value is the one defined in oned.conf (install default is OS).
    \ +
    \ +
    \ + \ + \ +
    Public scope of the image
    \ +
    \ +
    \ + \ + \ +
    Persistence of the image
    \ +
    \ +
    \ + \ + \ +
    Prefix for the emulated device this image will be mounted at. For instance, “hd”, “sd”. If omitted, the default value is the one defined in oned.conf (installation default is “hd”).
    \ +
    \ +
    \ + \ + \ +
    Type of disk device to emulate.
    \ +
    \ +
    \ +
    \ +
    \ + \ + \ +
    \ + \ +
    \ + \ + \ +
    Please choose path if you have a file-based image. Choose source otherwise or create an empty datablock disk.

    \ +
    \ +
    \ + \ + \ +
    Path to the original file that will be copied to the image repository. If not specified for a DATABLOCK type image, an empty image will be created.
    \ +
    \ +
    \ + \ + \ +
    Source to be used in the DISK attribute. Useful for not file-based images.
    \ +
    \ +
    \ + \ + \ +
    Size of the datablock in MB.
    \ +
    \ +
    \ + \ + \ +
    Type of file system to be built. This can be any value understood by mkfs unix command.
    \ +
    \ +
    \ +
    \ +
    \ + \ \ -
    \ -
    \ - \ +
    \ + \ + \ + \ +
    \ +
    \ +
    \ +

    Write the image template here

    \ + \ +
    \ +
    \ +
    \ + \ + \ +
    \ +
    \ +
    \
    \ '; @@ -244,9 +244,9 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.disable" : { + "Image.disable" : { type: "multiple", call: OpenNebula.Image.disable, callback: function (req) { @@ -255,9 +255,9 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.persistent" : { + "Image.persistent" : { type: "multiple", call: OpenNebula.Image.persistent, callback: function (req) { @@ -266,9 +266,9 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.nonpersistent" : { + "Image.nonpersistent" : { type: "multiple", call: OpenNebula.Image.nonpersistent, callback: function (req) { @@ -277,9 +277,9 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.publish" : { + "Image.publish" : { type: "multiple", call: OpenNebula.Image.publish, callback: function (req) { @@ -288,9 +288,9 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.unpublish" : { + "Image.unpublish" : { type: "multiple", call: OpenNebula.Image.unpublish, callback: function (req) { @@ -299,16 +299,16 @@ var image_actions = { elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, - "Image.delete" : { + "Image.delete" : { type: "multiple", call: OpenNebula.Image.delete, callback: deleteImageElement, elements: function() { return getSelectedNodes(dataTable_images); }, error: onError, notify: true - }, + }, "Image.chown" : { type: "multiple", @@ -513,6 +513,7 @@ function updateImagesView(request, images_list){ function popUpImageTemplateUpdateDialog(){ $('#template_update_dialog #template_update_button').val("Image"); $('#template_update_dialog #template_update_select').html(images_select); + $('#template_update_dialog #template_update_textarea').val(""); $('#template_update_dialog').dialog('open'); return false; } @@ -525,50 +526,50 @@ function updateImageInfo(request,img){ title: "Image information", content: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
    Image "'+img_info.NAME+'" information
    ID'+img_info.ID+'
    Name'+img_info.NAME+'
    Type'+OpenNebula.Helper.image_type(img_info.TYPE)+'
    Register time'+pretty_time(img_info.REGTIME)+'
    Public'+(parseInt(img_info.PUBLIC) ? "yes" : "no")+'
    Persistent'+(parseInt(img_info.PERSISTENT) ? "yes" : "no")+'
    Source'+img_info.SOURCE+'
    State'+OpenNebula.Helper.resource_state("image",img_info.STATE)+'
    ' + \ + Image "'+img_info.NAME+'" information\ + \ + \ + ID\ + '+img_info.ID+'\ + \ + \ + Name\ + '+img_info.NAME+'\ + \ + \ + Type\ + '+OpenNebula.Helper.image_type(img_info.TYPE)+'\ + \ + \ + Register time\ + '+pretty_time(img_info.REGTIME)+'\ + \ + \ + Public\ + '+(parseInt(img_info.PUBLIC) ? "yes" : "no")+'\ + \ + \ + Persistent\ + '+(parseInt(img_info.PERSISTENT) ? "yes" : "no")+'\ + \ + \ + Source\ + '+img_info.SOURCE+'\ + \ + \ + State\ + '+OpenNebula.Helper.resource_state("image",img_info.STATE)+'\ + \ + ' } var template_tab = { title: "Image template", content: '\ - '+ - prettyPrintJSON(img_info.TEMPLATE)+ - '
    Image template
    ' + Image template'+ + prettyPrintJSON(img_info.TEMPLATE)+ + '' } Sunstone.updateInfoPanelTab("image_info_panel","image_info_tab",info_tab); @@ -580,9 +581,9 @@ function updateImageInfo(request,img){ // Prepare the image creation dialog function setupCreateImageDialog(){ - $('div#dialogs').append('
    '); + $('div#dialogs').append('
    '); - //Insert HTML in place + //Insert HTML in place $('#create_image_dialog').html(create_image_tmpl); var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window @@ -600,7 +601,7 @@ function setupCreateImageDialog(){ $('#img_type option').first().attr("selected","selected"); $('#datablock_img').attr("disabled","disabled"); - //Chrome workaround + //Chrome workaround $('select#img_type').change(function(){ $(this).trigger("click"); }); @@ -608,14 +609,14 @@ function setupCreateImageDialog(){ $('select#img_type').click(function(){ var value = $(this).val(); switch (value){ - case "DATABLOCK": - $('#datablock_img').removeAttr("disabled"); - break; - default: - $('#datablock_img').attr("disabled","disabled"); - $('#path_img').attr("checked","checked"); - $('#img_source,#img_fstype,#img_size').parent().hide(); - $('#img_path').parent().show(); + case "DATABLOCK": + $('#datablock_img').removeAttr("disabled"); + break; + default: + $('#datablock_img').attr("disabled","disabled"); + $('#path_img').attr("checked","checked"); + $('#img_source,#img_fstype,#img_size').parent().hide(); + $('#img_path').parent().show(); } }); @@ -624,11 +625,11 @@ function setupCreateImageDialog(){ $('#img_path').parent().addClass("img_man"); $('#img_public').click(function(){ - $('#img_persistent').removeAttr("checked"); + $('#img_persistent').removeAttr("checked"); }); $('#img_persistent').click(function(){ - $('#img_public').removeAttr("checked"); + $('#img_public').removeAttr("checked"); }); @@ -636,24 +637,24 @@ function setupCreateImageDialog(){ $('#src_path_select input').click(function(){ var value = $(this).val(); switch (value){ - case "path": - $('#img_source,#img_fstype,#img_size').parent().hide(); - $('#img_source,#img_fstype,#img_size').parent().removeClass("img_man"); - $('#img_path').parent().show(); - $('#img_path').parent().addClass("img_man"); - break; - case "source": - $('#img_path,#img_fstype,#img_size').parent().hide(); - $('#img_path,#img_fstype,#img_size').parent().removeClass("img_man"); - $('#img_source').parent().show(); - $('#img_source').parent().addClass("img_man"); - break; - case "datablock": - $('#img_source,#img_path').parent().hide(); - $('#img_source,#img_path').parent().removeClass("img_man"); - $('#img_fstype,#img_size').parent().show(); - $('#img_fstype,#img_size').parent().addClass("img_man"); - break; + case "path": + $('#img_source,#img_fstype,#img_size').parent().hide(); + $('#img_source,#img_fstype,#img_size').parent().removeClass("img_man"); + $('#img_path').parent().show(); + $('#img_path').parent().addClass("img_man"); + break; + case "source": + $('#img_path,#img_fstype,#img_size').parent().hide(); + $('#img_path,#img_fstype,#img_size').parent().removeClass("img_man"); + $('#img_source').parent().show(); + $('#img_source').parent().addClass("img_man"); + break; + case "datablock": + $('#img_source,#img_path').parent().hide(); + $('#img_source,#img_path').parent().removeClass("img_man"); + $('#img_fstype,#img_size').parent().show(); + $('#img_fstype,#img_size').parent().addClass("img_man"); + break; } }); @@ -661,11 +662,11 @@ function setupCreateImageDialog(){ $('#create_image_form_easy').submit(function(){ var exit = false; $('.img_man',this).each(function(){ - if (!$('input',this).val().length){ - notifyError("There are mandatory parameters missing"); - exit = true; - return false; - } + if (!$('input',this).val().length){ + notifyError("There are mandatory parameters missing"); + exit = true; + return false; + } }); if (exit) { return false; } var img_json = {}; @@ -694,33 +695,33 @@ function setupCreateImageDialog(){ img_json["BUS"] = bus; switch ($('#src_path_select input:checked').val()){ - case "path": - path = $('#img_path').val(); - img_json["PATH"] = path; - break; - case "source": - source = $('#img_source').val(); - img_json["SOURCE"] = source; - break; + case "path": + path = $('#img_path').val(); + img_json["PATH"] = path; + break; + case "source": + source = $('#img_source').val(); + img_json["SOURCE"] = source; + break; case "datablock": - size = $('#img_size').val(); - fstype = $('#img_fstype').val(); - img_json["SIZE"] = size; - img_json["FSTYPE"] = fstype; - break; + size = $('#img_size').val(); + fstype = $('#img_fstype').val(); + img_json["SIZE"] = size; + img_json["FSTYPE"] = fstype; + break; } var obj = { "image" : img_json }; Sunstone.runAction("Image.register", obj); $('#create_image_dialog').dialog('close'); - return false; + return false; }); $('#create_image_form_manual').submit(function(){ - var template=$('#template',this).val(); + var template=$('#template',this).val(); Sunstone.runAction("Image.register",template); - $('#create_image_dialog').dialog('close'); - return false; + $('#create_image_dialog').dialog('close'); + return false; }); } @@ -731,13 +732,13 @@ function popUpCreateImageDialog(){ // Set the autorefresh interval for the datatable function setImageAutorefresh() { - setInterval(function(){ - var checked = $('input:checked',dataTable_images.fnGetNodes()); + setInterval(function(){ + var checked = $('input:checked',dataTable_images.fnGetNodes()); var filter = $("#datatable_images_filter input").attr("value"); - if (!checked.length && !filter.length){ + if (!checked.length && !filter.length){ Sunstone.runAction("Image.autorefresh"); - } - },INTERVAL+someTime()); + } + },INTERVAL+someTime()); } //The DOM is ready at this point diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 49eb4eb33f..4e64a2d6f0 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -649,12 +649,12 @@ var template_actions = { call: function(){ nodes = getSelectedNodes(dataTable_templates); $.each(nodes,function(){ - Sunstone.runAction("VM.create", - {vm : { - template_id: this - } - }); - }); + Sunstone.runAction("VM.create", + {vm : { + template_id: this + } + }); + }); }, notify: false }, @@ -836,6 +836,7 @@ function updateTemplatesView(request, templates_list){ function popUpTemplateTemplateUpdateDialog(){ $('#template_update_dialog #template_update_button').val("Template"); $('#template_update_dialog #template_update_select').html(templates_select); + $('#template_update_dialog #template_update_textarea').val(""); $('#template_update_dialog').dialog('open'); return false; } @@ -845,27 +846,28 @@ function updateTemplateInfo(request,template){ var template_info = template.VMTEMPLATE; var info_tab = { title: "Information", - content: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
    Template "'+template_info.NAME+'" information
    ID'+template_info.ID+'
    Name'+template_info.NAME+'
    Register time'+pretty_time(template_info.REGTIME)+'
    Public'+(parseInt(template_info.PUBLIC) ? "yes" : "no")+'
    ' + content: + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
    Template "'+template_info.NAME+'" information
    ID'+template_info.ID+'
    Name'+template_info.NAME+'
    Register time'+pretty_time(template_info.REGTIME)+'
    Public'+(parseInt(template_info.PUBLIC) ? "yes" : "no")+'
    ' }; 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: '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ + content: + '
    Virtual Machine information - '+vm_info.NAME+'
    ID'+vm_info.ID+'
    Name'+vm_info.NAME+'
    State'+OpenNebula.Helper.resource_state("vm",vm_info.STATE)+'
    LCM State'+OpenNebula.Helper.resource_state("vm_lcm",vm_info.LCM_STATE)+'
    Start time'+pretty_time(vm_info.STIME)+'
    Deploy ID'+(typeof(vm_info.DEPLOY_ID) == "object" ? "-" : vm_info.DEPLOY_ID)+'
    \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \
    Virtual Machine information - '+vm_info.NAME+'
    ID'+vm_info.ID+'
    Name'+vm_info.NAME+'
    State'+OpenNebula.Helper.resource_state("vm",vm_info.STATE)+'
    LCM State'+OpenNebula.Helper.resource_state("vm_lcm",vm_info.LCM_STATE)+'
    Start time'+pretty_time(vm_info.STIME)+'
    Deploy ID'+(typeof(vm_info.DEPLOY_ID) == "object" ? "-" : vm_info.DEPLOY_ID)+'
    \ \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \
    Monitoring information
    Net_TX'+vm_info.NET_TX+'
    Net_RX'+vm_info.NET_RX+'
    Used Memory'+humanize_size(vm_info.MEMORY)+'
    Used CPU'+vm_info.CPU+'
    VNC Session'+vncIcon(vm_info)+'
    Monitoring information
    Net_TX'+vm_info.NET_TX+'
    Net_RX'+vm_info.NET_RX+'
    Used Memory'+humanize_size(vm_info.MEMORY)+'
    Used CPU'+vm_info.CPU+'
    VNC Session'+vncIcon(vm_info)+'
    ' } var template_tab = { title: "VM Template", - content: '\ - '+ + content: + '
    VM template
    \ + '+ prettyPrintJSON(vm_info.TEMPLATE)+ - '
    VM template
    ' + '' } var log_tab = { @@ -739,16 +741,16 @@ function updateVMInfo(request,vm){ // which is a lot. function setupCreateVMDialog(){ - $('div#dialogs').append('
    '); - //Insert HTML in place - $('#create_vm_dialog').html(create_vm_tmpl); + $('div#dialogs').append('
    '); + //Insert HTML in place + $('#create_vm_dialog').html(create_vm_tmpl); - //Prepare jquery dialog - $('#create_vm_dialog').dialog({ - autoOpen: false, - modal: true, - width: 400 - }); + //Prepare jquery dialog + $('#create_vm_dialog').dialog({ + autoOpen: false, + modal: true, + width: 400 + }); $('#create_vm_dialog button').button(); @@ -808,8 +810,8 @@ function setupSaveasDialog(){ if (!id.length || !disk_id.length || !image_name.length) { notifyError("Skipping VM "+id+ - ". No disk id or image name specified"); - } + ". No disk id or image name specified"); + } else { var obj = { vm_id: id, @@ -830,8 +832,8 @@ function setupSaveasDialog(){ }); $('#saveas_vm_dialog #vm_saveas_cancel').click(function(){ - $('#saveas_vm_dialog').dialog('close'); - return false; + $('#saveas_vm_dialog').dialog('close'); + return false; }); } @@ -913,47 +915,47 @@ function saveasDisksCallback(req,response){ //Prepares autorefresh function setVMAutorefresh(){ setInterval(function(){ - var checked = $('input:checked',dataTable_vMachines.fnGetNodes()); - var filter = $("#datatable_vmachines_filter input").attr("value"); - if (!checked.length && !filter.length){ - Sunstone.runAction("VM.autorefresh"); + var checked = $('input:checked',dataTable_vMachines.fnGetNodes()); + var filter = $("#datatable_vmachines_filter input").attr("value"); + if (!checked.length && !filter.length){ + Sunstone.runAction("VM.autorefresh"); } - },INTERVAL+someTime()); //so that not all refreshing is done at the same time + },INTERVAL+someTime()); } function updateVNCState(rfb, state, oldstate, msg) { - var s, sb, cad, klass; - s = $D('VNC_status'); - sb = $D('VNC_status_bar'); - cad = $D('sendCtrlAltDelButton'); - switch (state) { - case 'failed': - case 'fatal': - klass = "VNC_status_error"; - break; - case 'normal': - klass = "VNC_status_normal"; - break; - case 'disconnected': - case 'loaded': - klass = "VNC_status_normal"; - break; - case 'password': - klass = "VNC_status_warn"; - break; - default: - klass = "VNC_status_warn"; - } + var s, sb, cad, klass; + s = $D('VNC_status'); + sb = $D('VNC_status_bar'); + cad = $D('sendCtrlAltDelButton'); + switch (state) { + case 'failed': + case 'fatal': + klass = "VNC_status_error"; + break; + case 'normal': + klass = "VNC_status_normal"; + break; + case 'disconnected': + case 'loaded': + klass = "VNC_status_normal"; + break; + case 'password': + klass = "VNC_status_warn"; + break; + default: + klass = "VNC_status_warn"; + } - if (state === "normal") { cad.disabled = false; } - else { cad.disabled = true; } + if (state === "normal") { cad.disabled = false; } + else { cad.disabled = true; } - if (typeof(msg) !== 'undefined') { - sb.setAttribute("class", klass); - s.innerHTML = msg; - } - } + if (typeof(msg) !== 'undefined') { + sb.setAttribute("class", klass); + s.innerHTML = msg; + } +} //setups VNC application function setupVNC(){ @@ -963,18 +965,18 @@ function setupVNC(){ $('#vnc_dialog').html('\
    \ - \ - \ - \ -
    Loading
    \ - \ -
    \ -
    \ - \ - Canvas not supported.\ - \ - '); + \ + \ + \ +
    Loading
    \ + \ +
    \ + \ + \ + Canvas not supported.\ + \ +'); $('#sendCtrlAltDelButton').click(function(){ rfb.sendCtrlAltDel(); @@ -992,7 +994,6 @@ function setupVNC(){ $( "#vnc_dialog" ).bind( "dialogclose", function(event, ui) { var id = $("#vnc_dialog").attr("vm_id"); Sunstone.runAction("VM.stopvnc",id); - }); $('.vnc').live("click",function(){ @@ -1008,26 +1009,24 @@ function setupVNC(){ } function vncCallback(request,response){ - rfb = new RFB({'target': $D('VNC_canvas'), - 'encrypt': false, - 'true_color': true, - 'local_cursor': true, - 'shared': true, - 'updateState': updateVNCState}); - //fetch things from clicked element host - port - password - vnc_port = response["port"]; - - //Hopefully this is returning sunstone server address, where - //the proxy is running - vnc_host = window.location.hostname; - vnc_pw = response["password"]; - - setTimeout(function(){ - rfb.connect(vnc_host, vnc_port, vnc_pw); - $('#vnc_dialog').dialog('open'); - },4000); + rfb = new RFB({'target': $D('VNC_canvas'), + 'encrypt': false, + 'true_color': true, + 'local_cursor': true, + 'shared': true, + 'updateState': updateVNCState}); + //fetch things from clicked element host - port - password + vnc_port = response["port"]; + //Hopefully this is returning sunstone server address, where + //the proxy is running + vnc_host = window.location.hostname; + vnc_pw = response["password"]; + setTimeout(function(){ + rfb.connect(vnc_host, vnc_port, vnc_pw); + $('#vnc_dialog').dialog('open'); + },4000); } diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index bea38b260b..5e5a588d0d 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -16,7 +16,7 @@ /*Virtual networks tab plugin*/ -var vnets_tab_content = +var vnets_tab_content = '
    \
    \
    \ @@ -41,84 +41,84 @@ var vnets_tab_content = var create_vn_tmpl = '
    \ - \ -
    \ - \ -
    \ - \ -
    \ -
    \ -
    \ - \ -
    \ -
    \ -
    \ - \ - Fixed network
    \ - Ranged network
    \ -
    \ -
    \ -
    \ -
    \ -
    \ - \ -
    \ - \ - \ -
    \ - \ - \ - \ -
    \ -
    \ -
    \ -
    \ -
    \ - \ -
    \ - \ - \ -
    \ -
    \ -
    \ -
    \ - \ -
    \ -
    \ - \ - \ -
    \ -
    \ - \ -
    \ -
    \ -
    \ -

    Write the Virtual Network template here

    \ -
    \ - \ -
    \ -
    \ -
    \ -
    \ - \ - \ -
    \ -
    \ -
    \ -
    \ + \ +
    \ +
    \ +
    \ + \ +
    \ +
    \ +
    \ + \ +
    \ +
    \ +
    \ + \ + Fixed network
    \ + Ranged network
    \ +
    \ +
    \ +
    \ +
    \ +
    \ + \ +
    \ + \ + \ +
    \ + \ + \ + \ +
    \ +
    \ +
    \ +
    \ +
    \ + \ +
    \ + \ + \ +
    \ +
    \ +
    \ +
    \ + \ +
    \ +
    \ + \ + \ +
    \ +
    \ +
    \ +
    \ +
    \ +
    \ +

    Write the Virtual Network template here

    \ +
    \ + \ +
    \ +
    \ +
    \ +
    \ + \ + \ +
    \ +
    \ +
    \ +
    \
    '; var vnetworks_select=""; @@ -240,19 +240,19 @@ var vnet_buttons = { img: "/images/Refresh-icon.png", condition: True }, - + "Network.create_dialog" : { type: "create_dialog", text: "+ New", condition: True }, - + "Network.publish" : { type: "action", text: "Publish", condition: True }, - + "Network.unpublish" : { type: "action", text: "Unpublish", @@ -274,7 +274,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: True }, - + "Network.delete" : { type: "action", text: "Delete", @@ -315,132 +315,134 @@ function vNetworkElementArray(vn_json){ total_leases = network.LEASES.LEASE.length ? network.LEASES.LEASE.length : "1"; } - return ['', - network.ID, - getUserName(network.UID), - getGroupName(network.GID), - network.NAME, - parseInt(network.TYPE) ? "FIXED" : "RANGED", - network.BRIDGE, - parseInt(network.PUBLIC) ? "yes" : "no", - total_leases ]; + return [ + '', + network.ID, + getUserName(network.UID), + getGroupName(network.GID), + network.NAME, + parseInt(network.TYPE) ? "FIXED" : "RANGED", + network.BRIDGE, + parseInt(network.PUBLIC) ? "yes" : "no", + total_leases ]; } //Adds a listener to show the extended info when clicking on a row function vNetworkInfoListener(){ - $('#tbodyvnetworks tr').live("click", function(e){ - if ($(e.target).is('input')) {return true;} + $('#tbodyvnetworks tr').live("click", function(e){ + if ($(e.target).is('input')) {return true;} popDialogLoading(); - var aData = dataTable_vNetworks.fnGetData(this); - var id = $(aData[0]).val(); - Sunstone.runAction("Network.showinfo",id); - return false; - }); + var aData = dataTable_vNetworks.fnGetData(this); + var id = $(aData[0]).val(); + Sunstone.runAction("Network.showinfo",id); + return false; + }); } //updates the vnet select different options function updateNetworkSelect(){ - vnetworks_select= + vnetworks_select= makeSelectOptions(dataTable_vNetworks,1,4,7,"no",2); - //update static selectors: + //update static selectors: //in the VM creation dialog - $('div.vm_section#networks select#NETWORK_ID').html(vnetworks_select); + $('div.vm_section#networks select#NETWORK_ID').html(vnetworks_select); } //Callback to update a vnet element after an action on it function updateVNetworkElement(request, vn_json){ - id = vn_json.VNET.ID; - element = vNetworkElementArray(vn_json); - updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); + id = vn_json.VNET.ID; + element = vNetworkElementArray(vn_json); + updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); updateNetworkSelect(); } //Callback to delete a vnet element from the table function deleteVNetworkElement(req){ - deleteElement(dataTable_vNetworks,'#vnetwork_'+req.request.data); + deleteElement(dataTable_vNetworks,'#vnetwork_'+req.request.data); updateNetworkSelect(); } //Callback to add a new element function addVNetworkElement(request,vn_json){ - var element = vNetworkElementArray(vn_json); - addElement(element,dataTable_vNetworks); + var element = vNetworkElementArray(vn_json); + addElement(element,dataTable_vNetworks); updateNetworkSelect(); } //updates the list of virtual networks function updateVNetworksView(request, network_list){ - network_list_json = network_list; - var network_list_array = []; + network_list_json = network_list; + var network_list_array = []; - $.each(network_list,function(){ - network_list_array.push(vNetworkElementArray(this)); - }); + $.each(network_list,function(){ + network_list_array.push(vNetworkElementArray(this)); + }); - updateView(network_list_array,dataTable_vNetworks); - updateNetworkSelect(); + updateView(network_list_array,dataTable_vNetworks); + updateNetworkSelect(); //dependency with dashboard - updateDashboard("vnets",network_list_json); + updateDashboard("vnets",network_list_json); } //updates the information panel tabs and pops the panel up function updateVNetworkInfo(request,vn){ - var vn_info = vn.VNET; - var info_tab_content = - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
    Virtual Network '+vn_info.ID+' information
    ID'+vn_info.ID+'
    UID'+vn_info.UID+'
    Public'+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+'
    '; - - //if it is a fixed VNET we can add leases information + var vn_info = vn.VNET; + var info_tab_content = + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
    Virtual Network '+vn_info.ID+' information
    ID'+vn_info.ID+'
    UID'+vn_info.UID+'
    Public'+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+'
    '; + + //if it is a fixed VNET we can add leases information if (vn_info.TEMPLATE.TYPE == "FIXED"){ - info_tab_content += '\ - \ - \ - '+ - prettyPrintJSON(vn_info.TEMPLATE.LEASES)+ - '
    Leases information
    '; + info_tab_content += + '\ + \ + \ + '+ + prettyPrintJSON(vn_info.TEMPLATE.LEASES)+ + '
    Leases information
    '; } - - - var info_tab = { + + + var info_tab = { title: "Virtual Network information", content: info_tab_content } - + var template_tab = { title: "Virtual Network template", - content: '\ - '+ - prettyPrintJSON(vn_info.TEMPLATE)+ - '
    Virtual Network template
    ' + content: + '\ + '+ + prettyPrintJSON(vn_info.TEMPLATE)+ + '
    Virtual Network template
    ' } - + Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab); Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_template_tab",template_tab); - + Sunstone.popUpInfoPanel("vnet_info_panel"); } - //Prepares the vnet creation dialog function setupCreateVNetDialog() { $('div#dialogs').append('
    '); @@ -607,13 +609,10 @@ $(document).ready(function(){ '','','','','','','',''],dataTable_vNetworks); Sunstone.runAction("Network.list"); - setupCreateVNetDialog(); setVNetAutorefresh(); initCheckAllBoxes(dataTable_vNetworks); tableCheckboxesListener(dataTable_vNetworks); vNetworkInfoListener(); - - }); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 8eeebf589c..5d538bf702 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -496,11 +496,13 @@ function generateMonitoringDivs(graphs, id_prefix){ id_suffix=label.replace(/,/g,'_'); id = id_prefix+id_suffix; str+='\ -\ -\ -
    '+this.title+'
    \ -
    '+spinner+'
    \ -
    '; + '+this.title+'\ + \ + \ +
    '+ + spinner+ + '
    \ + '; }); return str; @@ -508,7 +510,8 @@ function generateMonitoringDivs(graphs, id_prefix){ function plot_graph(data,context,id_prefix,info){ var labels = info.monitor_resources; - var humanize = info.humanize_figures ? humanize_size : function(val){return val}; + var humanize = info.humanize_figures ? + humanize_size : function(val){ return val }; var labels_arr = labels.split(','); var id_suffix = labels.replace(/,/g,'_'); var series = []; @@ -616,4 +619,4 @@ function True(){ } function False(){ return false; -} +} \ No newline at end of file diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 28616806ba..08d24c2fe0 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -21,7 +21,7 @@ var spinner = 'retrieving'+tab.title+''); - info_panel.append('
    '+tab.content+'
    '); + tab=tabs[tab_name]; + $('ul',info_panel).append('
  • '+tab.title+'
  • '); + info_panel.append('
    '+tab.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('
  • '+tab_info.title+'
  • '); } @@ -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 = ''+button.text+''; 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( - '
        \ -
        You need to select something.
        \ - \ -
        \ - \ - \ -
        \ -
        '); - - + $('div#confirm_with_select_dialog').html( + '
        \ +
        You need to select something.
        \ + \ +
        \ + \ + \ +
        \ +
        '); + //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"); } - -