diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index eadd2ad7..716816e3 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 284ac565..3053bea7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/query.rb b/app/models/query.rb index 400572eb..30441d26 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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 diff --git a/app/views/queries/_columns.rhtml b/app/views/queries/_columns.rhtml index f233f8ef..b03a3277 100644 --- a/app/views/queries/_columns.rhtml +++ b/app/views/queries/_columns.rhtml @@ -1,7 +1,27 @@ <% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> <%= l(:field_column_names) %> -<% query.available_columns.each do |column| %> -
-<% end %> + <%= hidden_field_tag 'query[column_names][]', '' %> + + + + + + +
<%= 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" %> + +
+ +
<%= 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" %> +
+<% end %> + +<% content_for :header_tags do %> +<%= javascript_include_tag 'select_list_move' %> <% end %> diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml index a6b5a496..627058df 100644 --- a/app/views/queries/_form.rhtml +++ b/app/views/queries/_form.rhtml @@ -12,9 +12,9 @@

<%= 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")}' %>

+ :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %>

-<%= render :partial => 'queries/columns', :locals => {:query => query}%> <%= render :partial => 'queries/filters', :locals => {:query => query}%> +<%= render :partial => 'queries/columns', :locals => {:query => query}%> diff --git a/app/views/queries/edit.rhtml b/app/views/queries/edit.rhtml index 17b19cee..1c99ac07 100644 --- a/app/views/queries/edit.rhtml +++ b/app/views/queries/edit.rhtml @@ -1,6 +1,6 @@

<%= l(:label_query) %>

-<% 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 %> diff --git a/app/views/queries/new.rhtml b/app/views/queries/new.rhtml index 01490a3b..631fd6c0 100644 --- a/app/views/queries/new.rhtml +++ b/app/views/queries/new.rhtml @@ -1,6 +1,6 @@

<%= l(:label_query_new) %>

-<% 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 %> diff --git a/public/javascripts/select_list_move.js b/public/javascripts/select_list_move.js new file mode 100644 index 00000000..1ced8823 --- /dev/null +++ b/public/javascripts/select_list_move.js @@ -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