diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index d47c582ca8..23abbc1a6e 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -801,7 +801,7 @@ var OpenNebula = { var callback = params.success; var callback_error = params.error; var id = params.data.id; - var host = params.data.host_id; + var host = params.data.extra_param; var method = "deploy"; var action = OpenNebula.Helper.action(method, {"host_id": host}); @@ -864,7 +864,7 @@ var OpenNebula = { var callback = params.success; var callback_error = params.error; var id = params.data.id; - var host = params.data.host_id; + var host = params.data.extra_param; var method = "livemigrate"; var action = OpenNebula.Helper.action(method,{"host_id": host}); @@ -896,7 +896,7 @@ var OpenNebula = { var callback = params.success; var callback_error = params.error; var id = params.data.id; - var host = params.data.host_id; + var host = params.data.extra_param; var method = "migrate"; var action = OpenNebula.Helper.action(method,{"host_id": host}); @@ -1279,7 +1279,7 @@ var OpenNebula = { var callback = params.success; var callback_error = params.error; var host_id = params.data.id; - var cluster_id = params.data.cluster_id; + var cluster_id = params.data.extra_param; var method = "add_host"; var action = OpenNebula.Helper.action(method, { @@ -1313,7 +1313,7 @@ var OpenNebula = { var callback = params.success; var callback_error = params.error; var host_id = params.data.id; - var cluster_id = params.data.cluster_id; + var cluster_id = params.data.extra_param; var method = "remove_host"; var action = OpenNebula.Helper.action(method, { diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index f96c1c66a3..699cd95e5b 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -42,41 +42,79 @@ var hosts_select=""; var clusters_select=""; var host_list_json = {}; var cluster_list_json = {}; -var dataTable_hosts = null; - +var dataTable_hosts; //Setup actions var host_actions = { + "Host.create" : { type: "create", call : OpenNebula.Host.create, callback : addHostElement, error : onError, - notify:true, + notify:False, + }, + + "Host.list" : { + type: "list", + call: OpenNebula.Host.list, + callback: updateHostsView, + error: onError, + notify:False + }, + + "Host.show" : { + type: "single", + call: OpenNebula.Host.show, + callback: updateHostElement, + error: onError, + notify:False + }, + + "Host.showinfo" : { + type: "single", + call: OpenNebula.Host.show, + callback: updateHostInfo, + error: onError, + notify: False + }, + + "Host.refresh" : { + type: "custom", + call: function(){ + waitingNodes(dataTable_hosts); + Sunstone.runAction("Host.list"); + }, + callback: function(){}, + error: onError, + notify: False }, "Host.enable" : { type: "multiple", call : OpenNebula.Host.enable, callback : host_update_callback, + dataTable: function() { return dataTable_hosts }, error : onError, - notify:true, + notify:True, }, "Host.disable" : { type: "multiple", call : OpenNebula.Host.disable, callback : host_update_callback, + dataTable: function() { return dataTable_hosts }, error : onError, - notify:true, + notify:True, }, "Host.delete" : { type: "multiple", call : OpenNebula.Host.create, callback : deleteHostElement, + dataTable: function() { return dataTable_hosts }, error : onError, - notify:true, + notify:True, }, "Host.list" : { @@ -87,33 +125,40 @@ var host_actions = { }, callback: function(){}, error: onError, - notify:true, + notify:True, }, - + "Cluster.create" : { type: "create", call : OpenNebula.Cluster.create, callback : function(){ - OpenNebula.Cluster.list({success: updateClustersView, error: onError}); + //OpenNebula.Cluster.list({success: updateClustersView, error: onError}); + Sunstone.runAction("Cluster.list"); }, error : onError, - notify:true, + notify:True, }, "Cluster.delete" : { - type: "multiple", - call : OpenNebula.Host.create, - callback : addHostElement, + type: "single", + call : OpenNebula.Cluster.delete, + callback : function(){ + //OpenNebula.Cluster.list({success: updateClustersView, error: onError}); + Sunstone.runAction("Cluster.list"); + }, error : onError, - notify:true, + notify:True, }, "Cluster.addhost" : { type: "multiple", call : OpenNebula.Cluster.addhost, - callback : updateHostElement, + callback : function(req){ + Sunstone.runAction("Host.show",req.request.data); + }, + dataTable: function() { return dataTable_hosts }, error : onError, - notify:true, + notify:True, }, "Cluster.removehost" : { @@ -121,63 +166,70 @@ var host_actions = { call : OpenNebula.Cluster.removehost, callback : deleteHostElement, error : onError, - notify:true, + notify:True, } }; -var host_buttons = [ - { +var host_buttons = { + "Host.refresh" : { + type: "image", + text: "Refresh list", + img: "/images/Refresh-icon.png", + condition: True + }, + + "Host.create" : { type: "create", text: "+ New host", - action: "Host.create", condition :True }, - { + "Host.enable" : { type: "action", text: "Enable", - action: "Host.enable", condition : True }, - { + "Host.disable" : { type: "confirm", text: "Disable", - action: "Host.disable", - tip: "Confirm disable", + tip: "This will disable the selected hosts.", condition : True }, - { + "Cluster.create" : { type: "create", text: "+ New Cluster", - action: "Cluster.create", condition : True }, - { - type: "action", + "Cluster.delete" : { + type: "confirm_with_select", text: "Delete cluster", - action: "Cluster.delete", + select: function(){return clusters_select}, + tip: "Select the cluster you want to remove", condition : True }, - { + "action_list" : { //Special button type: "select", - action: [{ type: "confirm_with_select", - text: "Add host to cluster", - value: "Cluster.addhost", - select: "cluster_select", - tip: "Select the cluster in which you would like to place the hosts", - condition: True}, - { type: "action", - text: "Remove host from cluster", - value: "Cluster.removehost", - condition: True}], + actions: { "Cluster.addhost": { + type: "confirm_with_select", + text: "Add host to cluster", + select: function(){return clusters_select;}, + tip: "Select the cluster in which you would like to place the hosts", + condition: True + }, + "Cluster.removehost" : { + type: "action", + text: "Remove host from cluster", + value: "Cluster.removehost", + condition: True + }}, condition : True }, - { + "Host.delete" : { type: "action", text: "Delete host", - value: "Host.delete", condition : True - }]; + } + }; for (action in host_actions){ Sunstone.addAction(action,host_actions[action]); @@ -265,7 +317,8 @@ function hostInfoListener(){ popDialogLoading(); aData = dataTable_hosts.fnGetData(this); id = $(aData[0]).val(); - OpenNebula.Host.show({data:{id:id},success: updateHostInfo,error: onError}); + Sunstone.runAction("Host.showinfo",id); + //OpenNebula.Host.show({data:{id:id},success: updateHostInfo,error: onError}); return false; }); } @@ -337,7 +390,7 @@ function updateClustersView(request, cluster_list){ //~ }); //~ updateView(cluster_list_array,dataTable_clusters); updateClusterSelect(cluster_list); - updateDashboard("clusters"); + updateDashboard("clusters",cluster_list); } @@ -443,7 +496,8 @@ $(document).ready(function(){ addElement([ spinner, '','','','','','',''],dataTable_hosts); - OpenNebula.Host.list({success: updateHostsView,error: onError}); + //OpenNebula.Host.list({success: updateHostsView,error: onError}); + Sunstone.runAction("Host.list"); //set refresh interval setInterval(function(){ @@ -455,5 +509,7 @@ $(document).ready(function(){ },60000); initCheckAllBoxes(dataTable_hosts); + tableCheckboxesListener(dataTable_hosts); + hostInfoListener(); }); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index be4789d287..3fba713610 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -143,7 +143,7 @@ function tableCheckboxesListener(dataTable){ if (last_action_b.length && last_action_b.val().length){ last_action_b.button("disable"); }; - $('.new_button',context).button("enable"); + $('.create_button',context).button("enable"); //listen to changes $('input',dataTable).live("change",function(){ @@ -326,6 +326,13 @@ function onError(request,error_json) { return true; } +function waitingNodes(dataTable){ + nodes = dataTable.fnGetData(); + for (var i=0;i'+this.text+''; - break; - case "action": - button_code += ''; - case "confirm": - button_code += ''; - case "confirm_with_select": - button_code += ''; - } - + var sel_obj; + for (sel_name in button.actions){ + sel_obj = button["actions"][sel_name]; + if (sel_obj.condition()){ + button_code += ''; }; - }); + }; button_code += ''; break; - case "confirm_with_select": - button_code = ''; + case "image": + button_code = ''+button.text+''; break; - case "action": - case "create": - case "confirm": default: - button_code = ''; + button_code = ''; - } + } } $('div#'+tab+' .action_blocks').append(button_code); - }); - } - } + }//for each button in tab + }//if tab exists + }//for each tab } @@ -482,8 +492,8 @@ function setupConfirmDialogs(){
Do you want to proceed?
\
\
\ - \ - \ + \ + \
\ '); @@ -508,8 +518,8 @@ function setupConfirmDialogs(){ \
\ - \ - \ + \ + \
\ '); @@ -530,25 +540,46 @@ function setupConfirmDialogs(){ return false; }); + $('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 + table = SunstoneCfg["actions"][value].dataTable(); + Sunstone.runActionOnDatatableNodes(value,table,param); + break; + default: + Sunstone.runAction(action,param); + break; + } + return false; + + }); + } function popUpConfirmDialog(target_elem){ - button = $(target_elem); - value = button.val(); - action = SunstoneCfg["actions"][value]; - + var value = $(target_elem).val(); + var tab_id = $(target_elem).parents('.tab').attr('id'); + var button = Sunstone.getButton(tab_id,value); + var tip = button.tip; + $('button#confirm_proceed').val(value); + $('div#confirm_tip').text(tip); + $('div#confirm_dialog').dialog("open"); } function popUpConfirmWithSelectDialog(target_elem){ - var button = $(target_elem); - var value = button.val(); - var action = SunstoneCfg["actions"][value]; - var select_var = eval(button.attr("select_id")); - var tip = button.attr(tip); + var value = $(target_elem).val(); + var tab_id = $(target_elem).parents('.tab').attr('id'); + var button = Sunstone.getButton(tab_id,value); + var tip = button.tip; + var select_var = button.select(); $('select#confirm_select').html(select_var); $('div#confirm_with_select_tip').text(tip); - $('button#confirm_with_select_proceed').val(val); + $('button#confirm_with_select_proceed').val(value); $('div#confirm_with_select_dialog').dialog("open");