1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

Feature #507: Action buttons, custom buttons, list buttons, confirm dialogs

and confirm with select dialogs seem to be working now.
This commit is contained in:
Hector Sanjuan 2011-03-04 17:39:28 +01:00
parent 8616344678
commit bb19299785
4 changed files with 208 additions and 114 deletions

View File

@ -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, {

View File

@ -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();
});

View File

@ -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<nodes.length;i++){
dataTable.fnUpdate(spinner,i,0);
}
};
function True(){
return true;

View File

@ -42,7 +42,7 @@ var Sunstone = {
"addAction" : function (name,action_obj) {
SunstoneCfg["actions"].name = action_obj;
SunstoneCfg["actions"][name] = action_obj;
},
"updateAction" : function(action,new_action) {
@ -69,7 +69,7 @@ var Sunstone = {
"runAction" : function(action, data_arg, extra_param){
var actions = Sunstone.actions;
var actions = SunstoneCfg["actions"];
if (!actions[action]){
notifyError("Action "+action+" not defined");
return;
@ -77,9 +77,9 @@ var Sunstone = {
var action_cfg = actions[action];
var call = action_cfg.run;
var callback = action_cfg.callback;
var err = action_cfg.callback;
var call = action_cfg["call"];
var callback = action_cfg["callback"];
var err = action_cfg["error"];
var notify = action_cfg.notify;
$('div#confirm_with_select_dialog').dialog("close");
@ -91,10 +91,10 @@ var Sunstone = {
// * Confirm and confirm with select calls
// * Calls on multiple elements
// * Other calls
switch (actions[action].type){
switch (action_cfg.type){
case "create","single":
call({data:data_arg, success: callback,error:err});
call({data:{id:data_arg}, success: callback,error:err});
break;
case "list":
call({success: callback, error:err});
@ -103,21 +103,23 @@ var Sunstone = {
//run on the list of nodes that come on the data
$.each(data_arg,function(){
if (extra_param){
//unsupported
call({data:{id:this,extra_param:extra_param}, success: callback, error: err});
} else {
call({data:this, success: callback, error:err});
call({data:{id:this}, success: callback, error:err});
}
});
break;
default:
//we have supposedly altered an action and we want it to do
//something completely different
call(data,extra_param);
if (data_arg && extra_param) {call(data_arg,extra_param);}
else if (data_arg) {call(data_arg);}
else {call();}
}
},
"runActionOnDatatableNodes": function(action,datatable){
"runActionOnDatatableNodes": function(action,dataTable,extra_param){
if (dataTable != null){
//Which rows of the datatable are checked?
@ -126,11 +128,21 @@ var Sunstone = {
$.each(nodes,function(){
data.push($(this).val());
});
runAction(action,data);
Sunstone.runAction(action,data,extra_param);
} else {
runAction(action);
Sunstone.runAction(action,extra_param);
};
},
"getButton" : function(tab_name,button_name){
var button = null;
var buttons = SunstoneCfg["tabs"][tab_name]["buttons"];
button = buttons[button_name];
if (!button && buttons["action_list"]) //not found, is it in the list then?
{
button = buttons["action_list"]["actions"][button_name];
}
return button;
}//meter coma y seguir aquí
};
@ -255,19 +267,28 @@ $(document).ready(function(){
$('.action_button').live("click",function(){
var table = null;
if ($(this).parents('table').length){
table = $(this).parents('table').dataTable();
var value = $(this).attr("value");
var action = SunstoneCfg["actions"][value];
if (!action) { notifyError("Action "+value+" not defined."); return false;};
switch (action.type){
case "multiple": //find the datatable
table = action.dataTable();
Sunstone.runActionOnDatatableNodes(value,table);
break;
default:
Sunstone.runAction(value);
}
//if no table found the action will be run as custom
Sunstone.runActionOnDatatableNodes($(this).value,table);
return false;
});
$('.confirm_button').live("click",function(){
popUpConfirmDialog(this);
return false;
});
$('.confirm_with_select_button').live("click",function(){
popUpConfirmWithSelectDialog(this)
popUpConfirmWithSelectDialog(this);
return false;
});
@ -334,52 +355,41 @@ function insertButtons(){
var buttons;
var tab_id;
var button_code;
var button_obj;
for (tab in SunstoneCfg["tabs"]){
buttons = SunstoneCfg["tabs"][tab].buttons;
content = SunstoneCfg["tabs"][tab].content;
if ($('div#'+tab+' .action_blocks').length){
$.each(buttons,function(){
for (button_name in buttons){
button_code = "";
if (this.condition()) {
switch (this.type) {
button = buttons[button_name];
if (button.condition()) {
switch (button.type) {
case "select":
button_code = '<select class="multi_action_slct">';
$.each(this.action,function(){
if (this.condition()){
switch (this.type){
case "create":
button_code += '<option class="create" value="'+this.value+'">'+this.text+'</option>';
break;
case "action":
button_code += '<option class="action_button" value="'+this.value+'">'+this.text+'</option>';
case "confirm":
button_code += '<option class="confirm_button" value="'+this.value+'">'+this.text+'</option>';
case "confirm_with_select":
button_code += '<option class="confirm_with_select_button" select_id="'+this.select+'" value="'+this.value+'">'+this.text+'</option>';
}
var sel_obj;
for (sel_name in button.actions){
sel_obj = button["actions"][sel_name];
if (sel_obj.condition()){
button_code += '<option class="'+sel_obj.type+'_button" value="'+sel_name+'">'+sel_obj.text+'</option>';
};
});
};
button_code += '</select>';
break;
case "confirm_with_select":
button_code = '<button class="confirm_with_select top_button" class="confirm_with_select_button" select_id="'+this.select+'" tip="'+this.tip+'" value="'+this.action+'">'+this.text+'</button>';
case "image":
button_code = '<img src="'+button.img+'" class="action_button" value="'+button_name+'" alt="'+button.text+'" />';
break;
case "action":
case "create":
case "confirm":
default:
button_code = '<button class="'+this.type+'_button top_button" value="'+this.action+'">'+this.text+'</button>';
button_code = '<button class="'+button.type+'_button top_button" value="'+button_name+'">'+button.text+'</button>';
}
}
}
$('div#'+tab+' .action_blocks').append(button_code);
});
}
}
}//for each button in tab
}//if tab exists
}//for each tab
}
@ -482,8 +492,8 @@ function setupConfirmDialogs(){
<div id="question">Do you want to proceed?</div>\
<br />\
<div class="form_buttons">\
<button id="proceed" class="action_button" value="">OK</button>\
<button id="cancel" value="">Cancel</button>\
<button id="confirm_proceed" class="action_button" value="">OK</button>\
<button class="confirm_cancel" value="">Cancel</button>\
</div>\
</form>');
@ -508,8 +518,8 @@ function setupConfirmDialogs(){
<select style="margin: 10px 0;" id="confirm_select">\
</select>\
<div class="form_buttons">\
<button id="action_button" value="">OK</button>\
<button id="confirm_with_select_cancel" value="">Cancel</button>\
<button id="confirm_with_select_proceed" class="" value="">OK</button>\
<button class="confirm_cancel" value="">Cancel</button>\
</div>\
</form>');
@ -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");