]> source.dussan.org Git - redmine.git/commitdiff
Custom query columns: checkboxes replaced by two selects that let the user specify...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 1 Oct 2007 11:39:34 +0000 (11:39 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 1 Oct 2007 11:39:34 +0000 (11:39 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@784 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/controllers/projects_controller.rb
app/models/query.rb
app/views/queries/_columns.rhtml
app/views/queries/_form.rhtml
app/views/queries/edit.rhtml
app/views/queries/new.rhtml
public/javascripts/select_list_move.js [new file with mode: 0644]

index eadd2ad71483b2d9488b6725b39d3d6b79c89e92..716816e34ec522315a5675456e48d8d9ce138da8 100644 (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                                             
index 284ac565562f5335c92a14202e9ee93f6bc33ee5..3053bea7c7d82ac2d251b1667709922c3036a52c 100644 (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                                         
index 400572eb274f9b35ee57287b96c380e6dc9104e9..30441d2607b508d05a9adecdb12945d21084f1fb 100644 (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
   
index f233f8ef63962ced0b9593b78a03786c841dac03..b03a3277d6b5ef8d7743f744273610b8e3725c05 100644 (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 %>
index a6b5a496c96ff97aa43a7069846b7740d8db1cfe..627058df04a199db32658f7b6bac19281d8e992b 100644 (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>
index 17b19cee94ad836da4eb6fbb27586ab510227128..1c99ac077ba4f42751f38b157ef63eecd82ab3ab 100644 (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 %>
index 01490a3bd9baa63f076528e02b131dbc1d525dcd..631fd6c027502ab21bd16bef03adccc8d53018c4 100644 (file)
@@ -1,6 +1,6 @@
 <h2><%= l(:label_query_new) %></h2>\r
 \r
-<% form_tag({:action => 'new', :project_id => @query.project}) do %>\r
+<% form_tag({:action => 'new', :project_id => @query.project}, :onsubmit => 'selectAllOptions("selected_columns");') do %>\r
   <%= render :partial => 'form', :locals => {:query => @query} %>\r
   <%= submit_tag l(:button_save) %>\r
 <% end %>\r
diff --git a/public/javascripts/select_list_move.js b/public/javascripts/select_list_move.js
new file mode 100644 (file)
index 0000000..1ced882
--- /dev/null
@@ -0,0 +1,55 @@
+var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);\r
+\r
+function addOption(theSel, theText, theValue)\r
+{\r
+  var newOpt = new Option(theText, theValue);\r
+  var selLength = theSel.length;\r
+  theSel.options[selLength] = newOpt;\r
+}\r
+\r
+function deleteOption(theSel, theIndex)\r
+{ \r
+  var selLength = theSel.length;\r
+  if(selLength>0)\r
+  {\r
+    theSel.options[theIndex] = null;\r
+  }\r
+}\r
+\r
+function moveOptions(theSelFrom, theSelTo)\r
+{\r
+  \r
+  var selLength = theSelFrom.length;\r
+  var selectedText = new Array();\r
+  var selectedValues = new Array();\r
+  var selectedCount = 0;\r
+  \r
+  var i;\r
+  \r
+  for(i=selLength-1; i>=0; i--)\r
+  {\r
+    if(theSelFrom.options[i].selected)\r
+    {\r
+      selectedText[selectedCount] = theSelFrom.options[i].text;\r
+      selectedValues[selectedCount] = theSelFrom.options[i].value;\r
+      deleteOption(theSelFrom, i);\r
+      selectedCount++;\r
+    }\r
+  }\r
+  \r
+  for(i=selectedCount-1; i>=0; i--)\r
+  {\r
+    addOption(theSelTo, selectedText[i], selectedValues[i]);\r
+  }\r
+  \r
+  if(NS4) history.go(0);\r
+}\r
+\r
+function selectAllOptions(id)\r
+{\r
+  var select = $(id);\r
+  for (var i=0; i<select.options.length; i++) {\r
+    select.options[i].selected = true;\r
+  }\r
+}\r
+\r