##// END OF EJS Templates
Moving a custom field value in the order switches in the edit view (#21535)....
Jean-Philippe Lang -
r14603:227594481e2d
parent child
Show More
@@ -0,0 +1,38
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../base', __FILE__)
19
20 class Redmine::UiTest::CustomFieldsTest < Redmine::UiTest::Base
21 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
22 :trackers, :projects_trackers, :enabled_modules,
23 :custom_fields, :custom_values, :custom_fields_trackers
24
25 def test_reordering_should_redirect_to_index
26 assert_equal 1, UserCustomField.find(4).position
27 log_user 'admin', 'admin'
28 visit '/custom_fields'
29
30 # click 'User' tab
31 page.first('a#tab-UserCustomField').click
32 # click 'Move down' link on the first row
33 page.first('td.reorder a:nth-child(3)').click
34
35 assert_equal "/custom_fields?tab=UserCustomField", URI.parse(current_url).request_uri
36 assert_equal 2, UserCustomField.find(4).position
37 end
38 end
@@ -1,88 +1,88
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class CustomFieldsController < ApplicationController
19 19 layout 'admin'
20 20
21 21 before_filter :require_admin
22 22 before_filter :build_new_custom_field, :only => [:new, :create]
23 23 before_filter :find_custom_field, :only => [:edit, :update, :destroy]
24 24 accept_api_auth :index
25 25
26 26 def index
27 27 respond_to do |format|
28 28 format.html {
29 29 @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
30 30 }
31 31 format.api {
32 32 @custom_fields = CustomField.all
33 33 }
34 34 end
35 35 end
36 36
37 37 def new
38 38 @custom_field.field_format = 'string' if @custom_field.field_format.blank?
39 39 @custom_field.default_value = nil
40 40 end
41 41
42 42 def create
43 43 if @custom_field.save
44 44 flash[:notice] = l(:notice_successful_create)
45 45 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
46 46 redirect_to edit_custom_field_path(@custom_field)
47 47 else
48 48 render :action => 'new'
49 49 end
50 50 end
51 51
52 52 def edit
53 53 end
54 54
55 55 def update
56 56 if @custom_field.update_attributes(params[:custom_field])
57 57 flash[:notice] = l(:notice_successful_update)
58 58 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
59 redirect_to edit_custom_field_path(@custom_field)
59 redirect_back_or_default edit_custom_field_path(@custom_field)
60 60 else
61 61 render :action => 'edit'
62 62 end
63 63 end
64 64
65 65 def destroy
66 66 begin
67 67 @custom_field.destroy
68 68 rescue
69 69 flash[:error] = l(:error_can_not_delete_custom_field)
70 70 end
71 71 redirect_to custom_fields_path(:tab => @custom_field.class.name)
72 72 end
73 73
74 74 private
75 75
76 76 def build_new_custom_field
77 77 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
78 78 if @custom_field.nil?
79 79 render :action => 'select_type'
80 80 end
81 81 end
82 82
83 83 def find_custom_field
84 84 @custom_field = CustomField.find(params[:id])
85 85 rescue ActiveRecord::RecordNotFound
86 86 render_404
87 87 end
88 88 end
@@ -1,30 +1,31
1 1 <table class="list">
2 2 <thead><tr>
3 3 <th><%=l(:field_name)%></th>
4 4 <th><%=l(:field_field_format)%></th>
5 5 <th><%=l(:field_is_required)%></th>
6 6 <% if tab[:name] == 'IssueCustomField' %>
7 7 <th><%=l(:field_is_for_all)%></th>
8 8 <th><%=l(:label_used_by)%></th>
9 9 <% end %>
10 10 <th><%=l(:button_sort)%></th>
11 11 <th></th>
12 12 </tr></thead>
13 13 <tbody>
14 14 <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
15 <% back_url = custom_fields_path(:tab => tab[:name]) %>
15 16 <tr class="<%= cycle("odd", "even") %>">
16 17 <td class="name"><%= link_to custom_field.name, edit_custom_field_path(custom_field) %></td>
17 18 <td><%= l(custom_field.format.label) %></td>
18 19 <td><%= checked_image custom_field.is_required? %></td>
19 20 <% if tab[:name] == 'IssueCustomField' %>
20 21 <td><%= checked_image custom_field.is_for_all? %></td>
21 22 <td><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
22 23 <% end %>
23 <td class="reorder"><%= reorder_links('custom_field', {:action => 'update', :id => custom_field}, :put) %></td>
24 <td class="reorder"><%= reorder_links('custom_field', {:action => 'update', :id => custom_field, :back_url => back_url}, :put) %></td>
24 25 <td class="buttons">
25 26 <%= delete_link custom_field_path(custom_field) %>
26 27 </td>
27 28 </tr>
28 29 <% end; reset_cycle %>
29 30 </tbody>
30 31 </table>
General Comments 0
You need to be logged in to leave comments. Login now