##// END OF EJS Templates
Show tabs for existing custom field types only and adds a view for choosing the type when adding a new custom field....
Jean-Philippe Lang -
r12574:7b127ee489a1
parent child
Show More
@@ -0,0 +1,15
1 <%= title [l(:label_custom_field_plural), custom_fields_path],
2 l(:label_custom_field_new) %>
3
4 <% selected = 0 %>
5 <%= form_tag new_custom_field_path, :method => 'get' do %>
6 <div class="box">
7 <p><%= l(:label_custom_field_select_type) %>:</p>
8 <p>
9 <% custom_field_type_options.each do |name, type| %>
10 <label style="display:block;"><%= radio_button_tag 'type', type, 1==selected+=1 %> <%= name %></label>
11 <% end %>
12 </p>
13 </div>
14 <p><%= submit_tag l(:label_next).html_safe + " &#187;".html_safe, :name => nil %></p>
15 <% end %>
@@ -77,7 +77,7 class CustomFieldsController < ApplicationController
77 77 def build_new_custom_field
78 78 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
79 79 if @custom_field.nil?
80 render_404
80 render :action => 'select_type'
81 81 end
82 82 end
83 83
@@ -309,9 +309,13 module ApplicationHelper
309 309 end
310 310
311 311 # Renders tabs and their content
312 def render_tabs(tabs)
312 def render_tabs(tabs, selected=params[:tab])
313 313 if tabs.any?
314 render :partial => 'common/tabs', :locals => {:tabs => tabs}
314 unless tabs.detect {|tab| tab[:name] == selected}
315 selected = nil
316 end
317 selected ||= tabs.first[:name]
318 render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected}
315 319 else
316 320 content_tag 'p', l(:label_no_data), :class => "nodata"
317 321 end
@@ -40,8 +40,13 module CustomFieldsHelper
40 40 :label => DocumentCategory::OptionName}
41 41 ]
42 42
43 def custom_fields_tabs
44 CUSTOM_FIELDS_TABS
43 def render_custom_fields_tabs(types)
44 tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) }
45 render_tabs tabs
46 end
47
48 def custom_field_type_options
49 CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]}
45 50 end
46 51
47 52 def render_custom_field_format_partial(form, custom_field)
@@ -1,5 +1,3
1 <% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %>
2
3 1 <div class="tabs">
4 2 <ul>
5 3 <% tabs.each do |tab| -%>
@@ -28,5 +28,3
28 28 <% end; reset_cycle %>
29 29 </tbody>
30 30 </table>
31
32 <p><%= link_to l(:label_custom_field_new), new_custom_field_path(:type => tab[:name]), :class => 'icon icon-add' %></p>
@@ -1,3 +1,11
1 <div class="contextual">
2 <%= link_to l(:label_custom_field_new), new_custom_field_path, :class => 'icon icon-add' %>
3 </div>
4
1 5 <%= title l(:label_custom_field_plural) %>
2 6
3 <%= render_tabs custom_fields_tabs %>
7 <% if @custom_fields_by_type.present? %>
8 <%= render_custom_fields_tabs(@custom_fields_by_type.keys) %>
9 <% else %>
10 <p class="nodata"><%= l(:label_no_data) %></p>
11 <% end %>
@@ -910,6 +910,7 en:
910 910 label_drop_down_list: drop-down list
911 911 label_checkboxes: checkboxes
912 912 label_link_values_to: Link values to URL
913 label_custom_field_select_type: Select the type of object to which the custom field is to be attached
913 914
914 915 button_login: Login
915 916 button_submit: Submit
@@ -886,6 +886,7 fr:
886 886 label_drop_down_list: liste déroulante
887 887 label_checkboxes: cases à cocher
888 888 label_link_values_to: Lier les valeurs vers l'URL
889 label_custom_field_select_type: Selectionner le type d'objet auquel attacher le champ personnalisé
889 890
890 891 button_login: Connexion
891 892 button_submit: Soumettre
@@ -30,6 +30,14 class CustomFieldsControllerTest < ActionController::TestCase
30 30 assert_template 'index'
31 31 end
32 32
33 def test_new_without_type_should_render_select_type
34 get :new
35 assert_response :success
36 assert_template 'select_type'
37 assert_select 'input[name=type]', CustomField.subclasses.size
38 assert_select 'input[name=type][checked=checked]', 1
39 end
40
33 41 def test_new_should_work_for_each_customized_class_and_format
34 42 custom_field_classes.each do |klass|
35 43 Redmine::FieldFormat.available_formats.each do |format_name|
@@ -113,9 +121,10 class CustomFieldsControllerTest < ActionController::TestCase
113 121 assert_equal 'list', field.field_format
114 122 end
115 123
116 def test_new_with_invalid_custom_field_class_should_render_404
124 def test_new_with_invalid_custom_field_class_should_render_select_type
117 125 get :new, :type => 'UnknownCustomField'
118 assert_response 404
126 assert_response :success
127 assert_template 'select_type'
119 128 end
120 129
121 130 def test_create_list_custom_field
@@ -160,6 +169,14 class CustomFieldsControllerTest < ActionController::TestCase
160 169 assert_template 'new'
161 170 end
162 171
172 def test_create_without_type_should_render_select_type
173 assert_no_difference 'CustomField.count' do
174 post :create, :custom_field => {:name => ''}
175 end
176 assert_response :success
177 assert_template 'select_type'
178 end
179
163 180 def test_edit
164 181 get :edit, :id => 1
165 182 assert_response :success
General Comments 0
You need to be logged in to leave comments. Login now