end
redirect_to :action => 'index'
end
+
+ def fields
+ if request.post? && params[:trackers]
+ params[:trackers].each do |tracker_id, tracker_params|
+ tracker = Tracker.find_by_id(tracker_id)
+ if tracker
+ tracker.core_fields = tracker_params[:core_fields]
+ tracker.custom_field_ids = tracker_params[:custom_field_ids]
+ tracker.save
+ end
+ end
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to :action => 'fields'
+ return
+ end
+ @trackers = Tracker.sorted.all
+ @custom_fields = IssueCustomField.all.sort
+ end
end
--- /dev/null
+<h2><%= link_to l(:label_tracker_plural), trackers_path %> » <%= l(:field_summary) %></h2>
+
+<% if @trackers.any? %>
+ <%= form_tag({}) do %>
+ <div class="autoscroll">
+ <table class="list">
+ <thead>
+ <tr>
+ <th></th>
+ <% @trackers.each do |tracker| %>
+ <th>
+ <%= tracker.name %>
+ <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.tracker-#{tracker.id}')",
+ :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
+ </th>
+ <% end %>
+ </tr>
+ </thead>
+ <tbody>
+ <tr class="group open">
+ <td colspan="<%= @trackers.size + 1 %>">
+ <span class="expander" onclick="toggleRowGroup(this);"> </span>
+ <%= l(:field_core_fields) %>
+ </td>
+ </tr>
+ <% Tracker::CORE_FIELDS.each do |field| %>
+ <tr class="<%= cycle("odd", "even") %>">
+ <td>
+ <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.core-field-#{field}')",
+ :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
+ <%= l("field_#{field}".sub(/_id$/, '')) %>
+ </td>
+ <% @trackers.each do |tracker| %>
+ <td align="center">
+ <%= check_box_tag "trackers[#{tracker.id}][core_fields][]", field, tracker.core_fields.include?(field),
+ :class => "tracker-#{tracker.id} core-field-#{field}" %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+ <% if @custom_fields.any? %>
+ <tr class="group open">
+ <td colspan="<%= @trackers.size + 1 %>">
+ <span class="expander" onclick="toggleRowGroup(this);"> </span>
+ <%= l(:label_custom_field_plural) %>
+ </td>
+ </tr>
+ <% @custom_fields.each do |field| %>
+ <tr class="<%= cycle("odd", "even") %>">
+ <td>
+ <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.custom-field-#{field.id}')",
+ :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
+ <%= field.name %>
+ </td>
+ <% @trackers.each do |tracker| %>
+ <td align="center">
+ <%= check_box_tag "trackers[#{tracker.id}][custom_field_ids][]", field.id, tracker.custom_fields.include?(field),
+ :class => "tracker-#{tracker.id} custom-field-#{field.id}" %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+ <% end %>
+ </tbody>
+ </table>
+ </div>
+ <p><%= submit_tag l(:button_save) %></p>
+ <% @trackers.each do |tracker| %>
+ <%= hidden_field_tag "trackers[#{tracker.id}][core_fields][]", '' %>
+ <%= hidden_field_tag "trackers[#{tracker.id}][custom_field_ids][]", '' %>
+ <% end %>
+ <% end %>
+<% else %>
+ <p class="nodata"><%= l(:label_no_data) %></p>
+<% end %>
+
+<% html_title l(:field_summary) %>
<div class="contextual">
<%= link_to l(:label_tracker_new), new_tracker_path, :class => 'icon icon-add' %>
+<%= link_to l(:field_summary), {:action => 'fields'}, :class => 'icon icon-summary' %>
</div>
<h2><%=l(:label_tracker_plural)%></h2>
match 'groups/destroy_membership/:id', :controller => 'groups', :action => 'destroy_membership', :id => /\d+/, :via => :post
match 'groups/edit_membership/:id', :controller => 'groups', :action => 'edit_membership', :id => /\d+/, :via => :post
- resources :trackers, :except => :show
+ resources :trackers, :except => :show do
+ collection do
+ match 'fields', :via => [:get, :post]
+ end
+ end
resources :issue_statuses, :except => :show do
collection do
post 'update_issue_done_ratio'
assert_redirected_to :action => 'index'
assert_not_nil flash[:error]
end
+
+ def test_get_fields
+ get :fields
+ assert_response :success
+ assert_template 'fields'
+
+ assert_select 'form' do
+ assert_select 'input[type=checkbox][name=?][value=assigned_to_id]', 'trackers[1][core_fields][]'
+ assert_select 'input[type=checkbox][name=?][value=2]', 'trackers[1][custom_field_ids][]'
+
+ assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][core_fields][]'
+ assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][custom_field_ids][]'
+ end
+ end
+
+ def test_post_fields
+ post :fields, :trackers => {
+ '1' => {'core_fields' => ['assigned_to_id', 'due_date', ''], 'custom_field_ids' => ['1', '2']},
+ '2' => {'core_fields' => [''], 'custom_field_ids' => ['']}
+ }
+ assert_redirected_to '/trackers/fields'
+
+ tracker = Tracker.find(1)
+ assert_equal %w(assigned_to_id due_date), tracker.core_fields
+ assert_equal [1, 2], tracker.custom_field_ids.sort
+
+ tracker = Tracker.find(2)
+ assert_equal [], tracker.core_fields
+ assert_equal [], tracker.custom_field_ids.sort
+ end
end
{ :controller => 'trackers', :action => 'destroy',
:format => 'xml', :id => '1' }
)
+ assert_routing(
+ { :method => 'get', :path => "/trackers/fields" },
+ { :controller => 'trackers', :action => 'fields' }
+ )
+ assert_routing(
+ { :method => 'post', :path => "/trackers/fields" },
+ { :controller => 'trackers', :action => 'fields' }
+ )
end
end