From dda5860dc7952a7771d37e31ed3caa65cfa56d62 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 19 Jun 2013 18:21:41 +0200 Subject: [PATCH] Add batch-action params to sunstone --- .../public/js/apptools-appflow-services.js | 352 +++++++++++------- 1 file changed, 219 insertions(+), 133 deletions(-) diff --git a/flow/sunstone/public/js/apptools-appflow-services.js b/flow/sunstone/public/js/apptools-appflow-services.js index 3d02fd4db9..d3f6fb7860 100644 --- a/flow/sunstone/public/js/apptools-appflow-services.js +++ b/flow/sunstone/public/js/apptools-appflow-services.js @@ -103,105 +103,105 @@ var Role = { OpenNebula.Action.simple_action(params, Service.resource, "hold", - null, + generate_batch_action_params(), Role.path); }, "release" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "release", - null, + generate_batch_action_params(), Role.path); }, "suspend" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "suspend", - null, + generate_batch_action_params(), Role.path); }, "resume" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "resume", - null, + generate_batch_action_params(), Role.path); }, "stop" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "stop", - null, + generate_batch_action_params(), Role.path); }, "restart" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "restart", - null, + generate_batch_action_params(), Role.path); }, "reset" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "reset", - null, + generate_batch_action_params(), Role.path); }, "resubmit" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "resubmit", - null, + generate_batch_action_params(), Role.path); }, "reboot" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "reboot", - null, + generate_batch_action_params(), Role.path); }, "poweroff" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "poweroff", - null, + generate_batch_action_params(), Role.path); }, "poweroff_hard" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "poweroff_hard", - null, + generate_batch_action_params(), Role.path); }, "snapshot_create" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "snapshot_create", - null, + generate_batch_action_params(), Role.path); }, "shutdown" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "shutdown", - null, + generate_batch_action_params(), Role.path); }, "cancel" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "cancel", - null, + generate_batch_action_params(), Role.path); }, "del" : function(params){ OpenNebula.Action.simple_action(params, Role.resource, "delete", - null, + generate_batch_action_params(), Role.path); }, "recover" : function(params){ @@ -213,6 +213,14 @@ var Role = { }, } +var generate_batch_action_params = function(){ + var action_obj = { + "period" : $("#batch_action_period").val(), + "number" : $("#batch_action_number").val()}; + + return action_obj; +} + var role_actions = { "Role.hold" : { type: "multiple", @@ -374,7 +382,7 @@ var role_buttons = { type: "action", text: tr("Hold"), tip: tr("This will hold selected pending VMs from being deployed"), - layout: "vmsplanification_buttons", + layout: "vmsplanification_buttons" }, "Role.release" : { type: "action", @@ -505,7 +513,6 @@ var service_tab_content = '\ \ '; - var dataTable_services; var service_actions = { @@ -613,16 +620,14 @@ var service_buttons = { text: tr("Change owner"), select: users_sel, tip: tr("Select the new owner")+":", - layout: "user_select", - condition: mustBeAdmin + layout: "user_select" }, "Service.chgrp" : { type: "confirm_with_select", text: tr("Change group"), select: groups_sel, tip: tr("Select the new group")+":", - layout: "user_select", - condition: mustBeAdmin + layout: "user_select" }, "Service.shutdown" : { type: "action", @@ -771,11 +776,32 @@ function updateServiceInfo(request,elem){ title : "Roles", content : '
\
\ -
\ +
\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +
'+ tr("Period") +'
\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +
'+ tr("VMs per period") +'
\ +
\ +
\ +
\ +
\
\
\
\ -
\ \ \ \ @@ -855,115 +881,64 @@ function updateServiceInfo(request,elem){ this.vm_template, this.parents ? this.parents.join(', ') : '-' ]) + }); - var info_str = "
\ - "+tr("Role")+" - "+this.name+""; + updateView(role_elements ,servicerolesDataTable); - info_str += "
\ -
\ - \ - \ - \ - "; + insertButtonsInTab("apptools-appflow-services", "service_roles_tab", role_buttons) + $('li#service_roles_tabTab', $("#dialog")).foundationButtons(); + $('li#service_roles_tabTab', $("#dialog")).foundationButtons(); - if (this.min_vms) { - info_str += "\ - \ - \ - "; - } - if (this.max_vms) { - info_str += "\ - \ - \ - "; - } - if (this.cooldown) { - info_str += "\ - \ - \ - "; + initCheckAllBoxes(servicerolesDataTable); + tableCheckboxesListener(servicerolesDataTable); + + $('tbody tr',servicerolesDataTable).live("click",function(e){ + var aData = servicerolesDataTable.fnGetData(this); + var role_name = $(aData[0]).val(); + + var role_index = servicerolesDataTable.fnGetPosition(this); + + if ($("#service_info_panel_resize_75").attr('visibility') != 'hidden') { + $("#service_info_panel_resize_75").click(); } - info_str += "\ -
"+tr("Min VMs")+""+this.min_vms+"
"+tr("Max VMs")+""+this.max_vms+"
"+tr("Cooldown")+""+this.cooldown+"
"; - - - info_str += "
\ -
"; - - if (this.elasticity_policies && this.elasticity_policies.length > 0) { - info_str += '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; - - $.each(this.elasticity_policies, function(){ - info_str += '\ - \ - \ - \ - \ - \ - \ - ' + if(last_selected_row) { + last_selected_row.children().each(function(){ + $(this).removeClass('markrowselected'); }); - - info_str += '\ -
'+tr("Elasticity policies")+'
'+tr("Type")+''+tr("Adjust")+''+tr("Expression")+''+tr("# Periods")+''+tr("Step")+''+tr("Cooldown")+'
'+this.type+''+this.adjust+''+this.expression+''+this.period+''+this.period_number+''+this.cooldown+'
'; } - if (this.scheduled_policies && this.scheduled_policies.length > 0) { - info_str += '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; + last_selected_row = $(this); + $(this).children().each(function(){ + $(this).addClass('markrowselected'); + }); - $.each(this.scheduled_policies, function(){ - info_str += '\ - \ - '; + generate_role_div(role_index); - if (this['start_time']) { - info_str += ''; - info_str += ''; - } else if (this['recurrence']) { - info_str += ''; - info_str += ''; - } - }); + //if($(this).is(":checked")) + //{ + // $(this).parents('tr').children().each(function(){$(this).addClass('markrowchecked');}); + //} + //else + //{ + // $(this).parents('tr').children().removeClass('markrowchecked'); + // $(this).parents('tr').children().removeClass('markrowselected'); + //} +// + //recountCheckboxes(datatable); + }); - info_str += '\ -
'+tr("Scheduled policies")+'
'+tr("Type")+''+tr("Adjust")+''+tr("Time format")+''+tr("Time expression")+'
'+this.type+''+this.adjust+'start_time'+this.start_time+'recurrence'+this.recurrence+'
'; - } - - info_str += '
\ + var generate_role_div = function(role_index) { + var role = roles[role_index] + var info_str = '
\ + '+tr("Role")+' - '+role.name+'\ +
\ +
\ +
\ +
\
\ - \ +
\ +
\ \ \ \ @@ -985,11 +960,124 @@ function updateServiceInfo(request,elem){
\
'; - info_str += "
" - $(info_str).appendTo(context); + info_str += "
\ + \ + \ + \ + \ + "; + + info_str += "\ + \ + \ + "; + info_str += "\ + \ + \ + "; + + if (role.min_vms) { + info_str += "\ + \ + \ + "; + } + if (role.max_vms) { + info_str += "\ + \ + \ + "; + } + if (role.cooldown) { + info_str += "\ + \ + \ + "; + } + + info_str += "\ +
"+tr("Information")+"
"+tr("State")+""+Role.state(role.state)+"
"+tr("Cardinality")+""+role.cardinality+"
"+tr("Min VMs")+""+role.min_vms+"
"+tr("Max VMs")+""+role.max_vms+"
"+tr("Cooldown")+""+role.cooldown+"
"; + + + info_str += "
\ +
"; + + if (role.elasticity_policies && role.elasticity_policies.length > 0) { + info_str += '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + + $.each(role.elasticity_policies, function(){ + info_str += '\ + \ + \ + \ + \ + \ + \ + ' + }); + + info_str += '\ +
'+tr("Elasticity policies")+'
'+tr("Type")+''+tr("Adjust")+''+tr("Expression")+''+tr("# Periods")+''+tr("Step")+''+tr("Cooldown")+'
'+this.type+''+this.adjust+''+this.expression+''+this.period+''+this.period_number+''+this.cooldown+'
'; + } + + if (role.scheduled_policies && role.scheduled_policies.length > 0) { + info_str += '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + + $.each(role.scheduled_policies, function(){ + info_str += '\ + \ + '; + + if (this['start_time']) { + info_str += ''; + info_str += ''; + } else if (this['recurrence']) { + info_str += ''; + info_str += ''; + } + }); + + info_str += '\ +
'+tr("Scheduled policies")+'
'+tr("Type")+''+tr("Adjust")+''+tr("Time format")+''+tr("Time expression")+'
'+this.type+''+this.adjust+'start_time'+this.start_time+'recurrence'+this.recurrence+'
'; + } + + info_str += '
\ + ' + + context.html(info_str); var vms = []; - var servicevmsDataTable = $('#datatable_service_vms_'+this.name, context).dataTable({ + var servicevmsDataTable = $('#datatable_service_vms_'+role.name, context).dataTable({ "aoColumnDefs": [ { "bSortable": false, "aTargets": [0,6,7,9,11] }, { "sWidth": "35px", "aTargets": [0] }, @@ -997,8 +1085,8 @@ function updateServiceInfo(request,elem){ ] }); - if (this.nodes) { - $.each(this.nodes, function(){ + if (role.nodes) { + $.each(role.nodes, function(){ var vm_info = this.vm_info; if (vm_info) { vms.push([""].concat(vMachineElementArray(vm_info).slice(1))); @@ -1007,16 +1095,13 @@ function updateServiceInfo(request,elem){ updateView(vms, servicevmsDataTable); } - }); - updateView(role_elements ,servicerolesDataTable); - insertButtonsInTab("apptools-appflow-services", "service_roles_tab", role_buttons) - $('li#service_roles_tabTab', $("#dialog")).foundationButtons(); - $('li#service_roles_tabTab', $("#dialog")).foundationButtons(); + //insertButtonsInTab("apptools-appflow-services", "service_roles_tab", role_buttons) + //$('li#service_roles_tabTab', $("#dialog")).foundationButtons(); + //$('li#service_roles_tabTab', $("#dialog")).foundationButtons(); + } + //setupActionButtons($('li#service_roles_tabTab', $("#dialog"))); - - initCheckAllBoxes(servicerolesDataTable); - tableCheckboxesListener(servicerolesDataTable); } @@ -1040,6 +1125,7 @@ function updateServiceInfo(request,elem){ //}); + setupTips($("#roles_form")); } // Set the autorefresh interval for the datatable