##// 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 def build_new_custom_field
77 def build_new_custom_field
78 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
78 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
79 if @custom_field.nil?
79 if @custom_field.nil?
80 render_404
80 render :action => 'select_type'
81 end
81 end
82 end
82 end
83
83
@@ -309,9 +309,13 module ApplicationHelper
309 end
309 end
310
310
311 # Renders tabs and their content
311 # Renders tabs and their content
312 def render_tabs(tabs)
312 def render_tabs(tabs, selected=params[:tab])
313 if tabs.any?
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 else
319 else
316 content_tag 'p', l(:label_no_data), :class => "nodata"
320 content_tag 'p', l(:label_no_data), :class => "nodata"
317 end
321 end
@@ -40,8 +40,13 module CustomFieldsHelper
40 :label => DocumentCategory::OptionName}
40 :label => DocumentCategory::OptionName}
41 ]
41 ]
42
42
43 def custom_fields_tabs
43 def render_custom_fields_tabs(types)
44 CUSTOM_FIELDS_TABS
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 end
50 end
46
51
47 def render_custom_field_format_partial(form, custom_field)
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 <div class="tabs">
1 <div class="tabs">
4 <ul>
2 <ul>
5 <% tabs.each do |tab| -%>
3 <% tabs.each do |tab| -%>
@@ -28,5 +28,3
28 <% end; reset_cycle %>
28 <% end; reset_cycle %>
29 </tbody>
29 </tbody>
30 </table>
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 <%= title l(:label_custom_field_plural) %>
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 label_drop_down_list: drop-down list
910 label_drop_down_list: drop-down list
911 label_checkboxes: checkboxes
911 label_checkboxes: checkboxes
912 label_link_values_to: Link values to URL
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 button_login: Login
915 button_login: Login
915 button_submit: Submit
916 button_submit: Submit
@@ -886,6 +886,7 fr:
886 label_drop_down_list: liste dΓ©roulante
886 label_drop_down_list: liste dΓ©roulante
887 label_checkboxes: cases Γ  cocher
887 label_checkboxes: cases Γ  cocher
888 label_link_values_to: Lier les valeurs vers l'URL
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 button_login: Connexion
891 button_login: Connexion
891 button_submit: Soumettre
892 button_submit: Soumettre
@@ -30,6 +30,14 class CustomFieldsControllerTest < ActionController::TestCase
30 assert_template 'index'
30 assert_template 'index'
31 end
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 def test_new_should_work_for_each_customized_class_and_format
41 def test_new_should_work_for_each_customized_class_and_format
34 custom_field_classes.each do |klass|
42 custom_field_classes.each do |klass|
35 Redmine::FieldFormat.available_formats.each do |format_name|
43 Redmine::FieldFormat.available_formats.each do |format_name|
@@ -113,9 +121,10 class CustomFieldsControllerTest < ActionController::TestCase
113 assert_equal 'list', field.field_format
121 assert_equal 'list', field.field_format
114 end
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 get :new, :type => 'UnknownCustomField'
125 get :new, :type => 'UnknownCustomField'
118 assert_response 404
126 assert_response :success
127 assert_template 'select_type'
119 end
128 end
120
129
121 def test_create_list_custom_field
130 def test_create_list_custom_field
@@ -160,6 +169,14 class CustomFieldsControllerTest < ActionController::TestCase
160 assert_template 'new'
169 assert_template 'new'
161 end
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 def test_edit
180 def test_edit
164 get :edit, :id => 1
181 get :edit, :id => 1
165 assert_response :success
182 assert_response :success
General Comments 0
You need to be logged in to leave comments. Login now