Custom query columns: checkboxes replaced by two selects that let the user specify columns order.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@784 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-10-01 11:39:34 +00:00
parent 96b4ac12cb
commit 514cdacc87
8 changed files with 86 additions and 10 deletions

View File

@ -46,7 +46,7 @@ class IssuesController < ApplicationController
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, 25, params['page']
@issues = Issue.find :all, :order => sort_clause,
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
:conditions => @query.statement,
:limit => @issue_pages.items_per_page,
:offset => @issue_pages.current.offset

View File

@ -250,7 +250,7 @@ class ProjectsController < ApplicationController
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
@issues = Issue.find :all, :order => sort_clause,
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
:conditions => @query.statement,
:limit => @issue_pages.items_per_page,
:offset => @issue_pages.current.offset

View File

@ -211,7 +211,8 @@ class Query < ActiveRecord::Base
if has_default_columns?
available_columns.select {|c| c.default? }
else
available_columns.select {|c| column_names.include?(c.name) }
# preserve the column_names order
column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
end
end

View File

@ -1,7 +1,27 @@
<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
<legend><%= l(:field_column_names) %></legend>
<% query.available_columns.each do |column| %>
<label><%= check_box_tag 'query[column_names][]', column.name, query.has_column?(column) %> <%= l("field_#{column.name}") %></label><br />
<% end %>
<%= hidden_field_tag 'query[column_names][]', '' %>
<table margin=0>
<tr>
<td><%= select_tag 'available_columns',
options_for_select((query.available_columns - query.columns).collect {|column| [l("field_#{column.name}"), column.name]}),
:multiple => true, :size => 10, :style => "width:150px" %>
</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.available_columns, this.form.selected_columns);" /><br />
<input type="button" value="&lt;--"
onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
</td>
<td><%= select_tag 'query[column_names][]',
options_for_select(@query.columns.collect {|column| [l("field_#{column.name}"), column.name]}),
:id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
</td>
</tr>
</table>
<% end %>
<% content_for :header_tags do %>
<%= javascript_include_tag 'select_list_move' %>
<% end %>

View File

@ -12,9 +12,9 @@
<p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
<%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
:onchange => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
:onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
</div>
<%= render :partial => 'queries/columns', :locals => {:query => query}%>
<%= render :partial => 'queries/filters', :locals => {:query => query}%>
<%= render :partial => 'queries/columns', :locals => {:query => query}%>
</div>

View File

@ -1,6 +1,6 @@
<h2><%= l(:label_query) %></h2>
<% form_tag({:action => 'edit', :id => @query}) do %>
<% form_tag({:action => 'edit', :id => @query}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>

View File

@ -1,6 +1,6 @@
<h2><%= l(:label_query_new) %></h2>
<% form_tag({:action => 'new', :project_id => @query.project}) do %>
<% form_tag({:action => 'new', :project_id => @query.project}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>

View File

@ -0,0 +1,55 @@
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}
function deleteOption(theSel, theIndex)
{
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}
function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.length;
var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;
var i;
for(i=selLength-1; i>=0; i--)
{
if(theSelFrom.options[i].selected)
{
selectedText[selectedCount] = theSelFrom.options[i].text;
selectedValues[selectedCount] = theSelFrom.options[i].value;
deleteOption(theSelFrom, i);
selectedCount++;
}
}
for(i=selectedCount-1; i>=0; i--)
{
addOption(theSelTo, selectedText[i], selectedValues[i]);
}
if(NS4) history.go(0);
}
function selectAllOptions(id)
{
var select = $(id);
for (var i=0; i<select.options.length; i++) {
select.options[i].selected = true;
}
}