[Ovirt-devel] [patch] flexigrid select fixes

Hugh O. Brock hbrock at redhat.com
Wed Jun 4 18:21:39 UTC 2008


On Wed, Jun 04, 2008 at 01:58:48PM -0400, Scott Seago wrote:
>

> >From e9d37595e7b15f87ecd30a16235404315ef39b11 Mon Sep 17 00:00:00 2001
> From: Scott Seago <sseago at redhat.com>
> Date: Wed, 4 Jun 2008 13:55:16 -0400
> Subject: [PATCH] a couple select box/flexigrid fixes:
>  1) select boxes work properly when flexigrid is hidden (or empty) and there was a prior selection
>  2) upon adding a host/vm/etc to an empty pool, the 'nothing to see here' view is refreshed with the proper flexigrid.
> 
> 
> Signed-off-by: Scott Seago <sseago at redhat.com>
> ---
>  wui/src/app/views/hardware/show_hosts.rhtml   |    2 +-
>  wui/src/app/views/hardware/show_storage.rhtml |    2 +-
>  wui/src/app/views/hardware/show_vms.rhtml     |    2 +-
>  wui/src/app/views/host/_grid.rhtml            |    6 +-
>  wui/src/app/views/resources/_grid.rhtml       |    4 +-
>  wui/src/app/views/resources/show_vms.rhtml    |    2 +-
>  wui/src/app/views/storage/_grid.rhtml         |    6 +-
>  wui/src/app/views/user/_grid.rhtml            |    4 +-
>  wui/src/app/views/user/_show.rhtml            |    2 +-
>  wui/src/app/views/vm/_grid.rhtml              |    4 +-
>  wui/src/public/javascripts/ovirt.js           |   67 ++++++++++++++++---------
>  11 files changed, 60 insertions(+), 41 deletions(-)
> 
> diff --git a/wui/src/app/views/hardware/show_hosts.rhtml b/wui/src/app/views/hardware/show_hosts.rhtml
> index b659a4b..a98055c 100644
> --- a/wui/src/app/views/hardware/show_hosts.rhtml
> +++ b/wui/src/app/views/hardware/show_hosts.rhtml
> @@ -12,7 +12,7 @@
>  <script type="text/javascript">
>    function get_selected_hosts()
>    {
> -    return get_selected_checkboxes(document.hosts_grid_form)
> +    return get_selected_checkboxes("hosts_grid_form")
>    }
>    function validate_for_move()
>    {
> diff --git a/wui/src/app/views/hardware/show_storage.rhtml b/wui/src/app/views/hardware/show_storage.rhtml
> index 6137154..1c36bbf 100644
> --- a/wui/src/app/views/hardware/show_storage.rhtml
> +++ b/wui/src/app/views/hardware/show_storage.rhtml
> @@ -14,7 +14,7 @@
>  <script type="text/javascript">
>    function get_selected_storage()
>    {
> -    return get_selected_checkboxes(document.storage_grid_form)
> +    return get_selected_checkboxes("storage_grid_form")
>    }
>    function validate_for_move()
>    {
> diff --git a/wui/src/app/views/hardware/show_vms.rhtml b/wui/src/app/views/hardware/show_vms.rhtml
> index 34c1867..dc70f1b 100644
> --- a/wui/src/app/views/hardware/show_vms.rhtml
> +++ b/wui/src/app/views/hardware/show_vms.rhtml
> @@ -7,7 +7,7 @@
>  <script type="text/javascript">
>    function get_selected_vm_pools()
>    {
> -    return get_selected_checkboxes(document.vmpools_grid_form)
> +    return get_selected_checkboxes("vmpools_grid_form")
>    }
>    function delete_vm_pools()
>    {
> diff --git a/wui/src/app/views/host/_grid.rhtml b/wui/src/app/views/host/_grid.rhtml
> index c9af220..0ce2a06 100644
> --- a/wui/src/app/views/host/_grid.rhtml
> +++ b/wui/src/app/views/host/_grid.rhtml
> @@ -1,8 +1,8 @@
>  <%= render :partial => 'graph/load_graph.rhtml' %>
>  
> -<% hosts_per_page = 30 %>
> +<% hosts_per_page = 40 %>
>  <div id="<%= table_id %>_div">
> -<form name="<%= table_id %>_form">
> +<form id="<%= table_id %>_form">
>  <table id="<%= table_id %>" style="display:none"></table>
>  </form>
>  </div>
> @@ -39,7 +39,7 @@
>  	);   
>  	function <%= table_id %>checkbox(celDiv)
>  	{
> -	       $(celDiv).html('<input type="checkbox" name="grid_checkbox" value="'+$(celDiv).html()+'"/>');
> +	       $(celDiv).html('<input class="grid_checkbox" type="checkbox" name="grid_checkbox'+$(celDiv).html()+'" value="'+$(celDiv).html()+'"/>');
>  	} 
>      function <%= table_id %>_load_widget(celDiv)
>      {
> diff --git a/wui/src/app/views/resources/_grid.rhtml b/wui/src/app/views/resources/_grid.rhtml
> index ab61784..301a7aa 100644
> --- a/wui/src/app/views/resources/_grid.rhtml
> +++ b/wui/src/app/views/resources/_grid.rhtml
> @@ -2,7 +2,7 @@
>  
>  <% resources_per_page = 10 %>
>  <div id="<%= table_id %>_div">
> -<form name="<%= table_id %>_form">
> +<form id="<%= table_id %>_form">
>  <table id="<%= table_id %>" style="display:none"></table>
>  </form>
>  </div>
> @@ -31,7 +31,7 @@
>  	);   
>  	function <%= table_id %>checkbox(celDiv)
>  	{
> -	       $(celDiv).html('<input type="checkbox" name="grid_checkbox" value="'+$(celDiv).html()+'"/>');
> +	       $(celDiv).html('<input type="checkbox" name="grid_checkbox'+$(celDiv).html()+'" class="grid_checkbox" value="'+$(celDiv).html()+'"/>');
>  	} 
>      function <%= table_id %>_load_widget(celDiv)
>      {
> diff --git a/wui/src/app/views/resources/show_vms.rhtml b/wui/src/app/views/resources/show_vms.rhtml
> index 15527f3..beacddf 100644
> --- a/wui/src/app/views/resources/show_vms.rhtml
> +++ b/wui/src/app/views/resources/show_vms.rhtml
> @@ -21,7 +21,7 @@
>  <script type="text/javascript">
>    function get_selected_vms()
>    {
> -    return get_selected_checkboxes(document.vms_grid_form)
> +    return get_selected_checkboxes("vms_grid_form")
>    }
>    function delete_vms()
>    {
> diff --git a/wui/src/app/views/storage/_grid.rhtml b/wui/src/app/views/storage/_grid.rhtml
> index ce5943a..15a0331 100644
> --- a/wui/src/app/views/storage/_grid.rhtml
> +++ b/wui/src/app/views/storage/_grid.rhtml
> @@ -1,7 +1,7 @@
> -<% storage_per_page = 10 %>
> +<% storage_per_page = 40 %>
>  
>  <div id="<%= table_id %>_div">
> -<form name="<%= table_id %>_form">
> +<form id="<%= table_id %>_form">
>  <table id="<%= table_id %>" style="display:none"></table>
>  </form>
>  </div>
> @@ -29,7 +29,7 @@
>  	);   
>  	function <%= table_id %>checkbox(celDiv)
>  	{
> -	       $(celDiv).html('<input type="checkbox" name="grid_checkbox" value="'+$(celDiv).html()+'"/>');
> +	       $(celDiv).html('<input type="checkbox" name="grid_checkbox'+$(celDiv).html()+'" class="grid_checkbox" value="'+$(celDiv).html()+'"/>');
>  	} 
>  
>  </script>
> diff --git a/wui/src/app/views/user/_grid.rhtml b/wui/src/app/views/user/_grid.rhtml
> index f908167..d9ad795 100644
> --- a/wui/src/app/views/user/_grid.rhtml
> +++ b/wui/src/app/views/user/_grid.rhtml
> @@ -1,6 +1,6 @@
>  <% users_per_page = 10 %>
>  <div id="<%= table_id %>_div">
> -<form name="<%= table_id %>_form">
> +<form id="<%= table_id %>_form">
>  <table id="<%= table_id %>" style="display:none"></table>
>  </form>
>  </div>
> @@ -25,7 +25,7 @@
>  	);   
>  	function <%= table_id %>checkbox(celDiv)
>  	{
> -	       $(celDiv).html('<input type="checkbox" name="grid_checkbox" value="'+$(celDiv).html()+'"/>');
> +	       $(celDiv).html('<input type="checkbox" name="grid_checkbox'+$(celDiv).html()+'" class="grid_checkbox" value="'+$(celDiv).html()+'"/>');
>  	} 
>  
>  </script>
> diff --git a/wui/src/app/views/user/_show.rhtml b/wui/src/app/views/user/_show.rhtml
> index e93025b..79b8996 100644
> --- a/wui/src/app/views/user/_show.rhtml
> +++ b/wui/src/app/views/user/_show.rhtml
> @@ -8,7 +8,7 @@
>  <script type="text/javascript">
>    function get_selected_users()
>    {
> -    return get_selected_checkboxes(document.users_grid_form)
> +    return get_selected_checkboxes("users_grid_form")
>    }
>    function delete_users()
>    {
> diff --git a/wui/src/app/views/vm/_grid.rhtml b/wui/src/app/views/vm/_grid.rhtml
> index 93e4857..b0fc71a 100644
> --- a/wui/src/app/views/vm/_grid.rhtml
> +++ b/wui/src/app/views/vm/_grid.rhtml
> @@ -1,7 +1,7 @@
>  <%= render :partial => 'graph/load_graph.rhtml' %>
>  <% vms_per_page = 10 %>
>  <div id="<%= table_id %>_div">
> -<form name="<%= table_id %>_form">
> +<form id="<%= table_id %>_form">
>  <table id="<%= table_id %>" style="display:none"></table>
>  </form>
>  </div>
> @@ -35,7 +35,7 @@
>  	);   
>  	function <%= table_id %>checkbox(celDiv)
>  	{
> -	       $(celDiv).html('<input type="checkbox" name="grid_checkbox" value="'+$(celDiv).html()+'"/>');
> +	       $(celDiv).html('<input type="checkbox" name="grid_checkbox'+$(celDiv).html()+'" class="grid_checkbox" value="'+$(celDiv).html()+'"/>');
>  	} 
>      function <%= table_id %>_load_widget(celDiv)
>      {
> diff --git a/wui/src/public/javascripts/ovirt.js b/wui/src/public/javascripts/ovirt.js
> index dee6732..44d9154 100644
> --- a/wui/src/public/javascripts/ovirt.js
> +++ b/wui/src/public/javascripts/ovirt.js
> @@ -5,25 +5,14 @@
>  
>  
>  // returns an array of selected values for flexigrid checkboxes
> -function get_selected_checkboxes(obj_form)
> +function get_selected_checkboxes(formid)
>  {
>    var selected_array = new Array()
>    var selected_index = 0
> -  var checkboxes
> -  if (obj_form.grid_checkbox) {
> -    if (obj_form.grid_checkbox.length == undefined) {
> -      checkboxes = [obj_form.grid_checkbox]
> -    } else {
> -      checkboxes = obj_form.grid_checkbox
> -    }
> -    for(var i=0; i < checkboxes.length; i++){
> -    if(checkboxes[i].checked)
> -      {
> -        selected_array[selected_index]= checkboxes[i].value
> -        selected_index++
> -      }
> -    }
> -  }
> +  var selected = $('#'+formid+' .grid_checkbox:checkbox:checked')
> +  selected.each(function(){
> +    selected_array.push(this.value)  
> +  })
>    return selected_array
>  }
>  
> @@ -41,13 +30,18 @@ function validate_selected(selected_array, name)
>  
>  function add_hosts(url)
>  {
> -    hosts= get_selected_checkboxes(document.addhosts_grid_form)
> +    hosts= get_selected_checkboxes("addhosts_grid_form")
>      if (validate_selected(hosts, "host")) {
>        $.post(url,
>               { resource_ids: hosts.toString() },
>                function(data,status){ 
>                  jQuery(document).trigger('close.facebox');
> -                $("#hosts_grid").flexReload()
> +	        grid = $("#hosts_grid")
> +                if (grid.size()>0) {
> +                  grid.flexReload()
> +                } else {
> +		  $('.tab_nav li.current a').click()
> +                }
>  		if (data.alert) {
>  		  alert(data.alert);
>                  }
> @@ -56,13 +50,18 @@ function add_hosts(url)
>  }
>  function add_storage(url)
>  {
> -    storage= get_selected_checkboxes(document.addstorage_grid_form)
> +    storage= get_selected_checkboxes("addstorage_grid_form")
>      if (validate_selected(storage, "storage pool")) {
>        $.post(url,
>               { resource_ids: storage.toString() },
>                function(data,status){ 
>                  jQuery(document).trigger('close.facebox');
> -                $("#storage_grid").flexReload()
> +	        grid = $("#storage_grid")
> +                if (grid.size()>0) {
> +                  grid.flexReload()
> +                } else {
> +		  $('.tab_nav li.current a').click()
> +                }
>  		if (data.alert) {
>  		  alert(data.alert);
>                  }
> @@ -112,28 +111,48 @@ function afterVmPool(response, status){
>      ajax_validation(response, status)
>      if (response.success) {
>        jQuery(document).trigger('close.facebox');
> -      $("#vmpools_grid").flexReload()
> +      grid = $("#vmpools_grid")
> +      if (grid.size()>0) {
> +        grid.flexReload()
> +      } else {
> +        $('.tab_nav li.current a').click()
> +      }
>      }
>  }
>  function afterStoragePool(response, status){
>      ajax_validation(response, status)
>      if (response.success) {
>        jQuery(document).trigger('close.facebox');
> -      $("#storage_grid").flexReload()
> +      grid = $("#storage_grid")
> +      if (grid.size()>0) {
> +        grid.flexReload()
> +      } else {
> +        $('.tab_nav li.current a').click()
> +      }
>      }
>  }
>  function afterPermission(response, status){
>      ajax_validation(response, status)
>      if (response.success) {
>        jQuery(document).trigger('close.facebox');
> -      $("#users_grid").flexReload()
> +      grid = $("#users_grid")
> +      if (grid.size()>0) {
> +        grid.flexReload()
> +      } else {
> +        $('.tab_nav li.current a').click()
> +      }
>      }
>  }
>  function afterVm(response, status){
>      ajax_validation(response, status)
>      if (response.success) {
>        jQuery(document).trigger('close.facebox');
> -      $("#vms_grid").flexReload()
> +      grid = $("#vms_grid")
> +      if (grid.size()>0) {
> +        grid.flexReload()
> +      } else {
> +        $('.tab_nav li.current a').click()
> +      }
>      }
>  }
>  
> -- 
> 1.5.4.1
> 

ACK this appears to solve the problem. Committed.

--Hugh




More information about the ovirt-devel mailing list