]> source.dussan.org Git - redmine.git/commitdiff
Show tabs for existing custom field types only and adds a view for choosing the type...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 7 Feb 2014 07:57:59 +0000 (07:57 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 7 Feb 2014 07:57:59 +0000 (07:57 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12849 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/custom_fields_controller.rb
app/helpers/application_helper.rb
app/helpers/custom_fields_helper.rb
app/views/common/_tabs.html.erb
app/views/custom_fields/_index.html.erb
app/views/custom_fields/index.html.erb
app/views/custom_fields/select_type.html.erb [new file with mode: 0644]
config/locales/en.yml
config/locales/fr.yml
test/functional/custom_fields_controller_test.rb

index 3f721b145c9d6c9452427444bbf21581781d3584..28178e98bb1b50c13d3680dc0219d18c0df8fe43 100644 (file)
@@ -77,7 +77,7 @@ class CustomFieldsController < ApplicationController
   def build_new_custom_field
     @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
     if @custom_field.nil?
-      render_404
+      render :action => 'select_type'
     end
   end
 
index 25096a11defd4efa5e175e909d2b4238c8bdc4ac..363653cd832e34ceda3b781513cd0875e9156468 100644 (file)
@@ -309,9 +309,13 @@ module ApplicationHelper
   end
 
   # Renders tabs and their content
-  def render_tabs(tabs)
+  def render_tabs(tabs, selected=params[:tab])
     if tabs.any?
-      render :partial => 'common/tabs', :locals => {:tabs => tabs}
+      unless tabs.detect {|tab| tab[:name] == selected}
+        selected = nil
+      end
+      selected ||= tabs.first[:name]
+      render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected}
     else
       content_tag 'p', l(:label_no_data), :class => "nodata"
     end
index 5447130a512538534787f2d916b8c76fb2f8f9f1..173e0d5f81ac6317e0b884078b159af99c409342 100644 (file)
@@ -40,8 +40,13 @@ module CustomFieldsHelper
      :label => DocumentCategory::OptionName}
   ]
 
-  def custom_fields_tabs
-    CUSTOM_FIELDS_TABS
+  def render_custom_fields_tabs(types)
+    tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) }
+    render_tabs tabs
+  end
+
+  def custom_field_type_options
+    CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]}
   end
 
   def render_custom_field_format_partial(form, custom_field)
index 8cbcda51aa991e02fa7b3c4bb15bc6ad5cee492d..34fd570eaed94f2ff3bbc4031e6373fb1d71152c 100644 (file)
@@ -1,5 +1,3 @@
-<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %>
-
 <div class="tabs">
   <ul>
   <% tabs.each do |tab| -%>
index 4752c2519f306669edf980b7a23e7a059855239a..0b578d6ee59dc7a96e4190c809f3034ab8948613 100644 (file)
@@ -28,5 +28,3 @@
   <% end; reset_cycle %>
   </tbody>
 </table>
-
-<p><%= link_to l(:label_custom_field_new), new_custom_field_path(:type => tab[:name]), :class => 'icon icon-add' %></p>
index b4e87f066a793f6c3ec2036ae1e0980baffbd525..e4464132f51ebd29e7367b289202300d68a7a659 100644 (file)
@@ -1,3 +1,11 @@
+<div class="contextual">
+<%= link_to l(:label_custom_field_new), new_custom_field_path, :class => 'icon icon-add' %>
+</div>
+
 <%= title l(:label_custom_field_plural) %>
 
-<%= render_tabs custom_fields_tabs %>
+<% if @custom_fields_by_type.present? %>
+  <%= render_custom_fields_tabs(@custom_fields_by_type.keys) %>
+<% else %>
+  <p class="nodata"><%= l(:label_no_data) %></p>
+<% end %>
diff --git a/app/views/custom_fields/select_type.html.erb b/app/views/custom_fields/select_type.html.erb
new file mode 100644 (file)
index 0000000..fd9c5a2
--- /dev/null
@@ -0,0 +1,15 @@
+<%= title [l(:label_custom_field_plural), custom_fields_path],
+  l(:label_custom_field_new) %>
+
+<% selected = 0 %>
+<%= form_tag new_custom_field_path, :method => 'get' do %>
+  <div class="box">
+  <p><%= l(:label_custom_field_select_type) %>:</p>
+  <p>
+  <% custom_field_type_options.each do |name, type| %>
+    <label style="display:block;"><%= radio_button_tag 'type', type, 1==selected+=1 %> <%= name %></label>
+  <% end %>
+  </p>
+  </div>
+  <p><%= submit_tag l(:label_next).html_safe + " &#187;".html_safe, :name => nil %></p>
+<% end %>
index c9256ae404e2d43bbfe844576badd69152914433..39b7d8f04edfacfa3d4e8d873670a8179e34329b 100644 (file)
@@ -910,6 +910,7 @@ en:
   label_drop_down_list: drop-down list
   label_checkboxes: checkboxes
   label_link_values_to: Link values to URL
+  label_custom_field_select_type: Select the type of object to which the custom field is to be attached
 
   button_login: Login
   button_submit: Submit
index 2eff8fcd3c46ec13c2520034a4d4b7a3b9c62f6f..ad7ca550df8c5afa52a4fd26f57e564c4e0a01d9 100644 (file)
@@ -886,6 +886,7 @@ fr:
   label_drop_down_list: liste déroulante
   label_checkboxes: cases à cocher
   label_link_values_to: Lier les valeurs vers l'URL
+  label_custom_field_select_type: Selectionner le type d'objet auquel attacher le champ personnalisé
 
   button_login: Connexion
   button_submit: Soumettre
index 394ede20a81a07ee83c0fe63f6b6c146cc50fed8..76579d74a29cc4b2d9b3223d23ba3535f6b8e1ef 100644 (file)
@@ -30,6 +30,14 @@ class CustomFieldsControllerTest < ActionController::TestCase
     assert_template 'index'
   end
 
+  def test_new_without_type_should_render_select_type
+    get :new
+    assert_response :success
+    assert_template 'select_type'
+    assert_select 'input[name=type]', CustomField.subclasses.size
+    assert_select 'input[name=type][checked=checked]', 1
+  end
+
   def test_new_should_work_for_each_customized_class_and_format
     custom_field_classes.each do |klass|
       Redmine::FieldFormat.available_formats.each do |format_name|
@@ -113,9 +121,10 @@ class CustomFieldsControllerTest < ActionController::TestCase
     assert_equal 'list', field.field_format
   end
 
-  def test_new_with_invalid_custom_field_class_should_render_404
+  def test_new_with_invalid_custom_field_class_should_render_select_type
     get :new, :type => 'UnknownCustomField'
-    assert_response 404
+    assert_response :success
+    assert_template 'select_type'
   end
 
   def test_create_list_custom_field
@@ -160,6 +169,14 @@ class CustomFieldsControllerTest < ActionController::TestCase
     assert_template 'new'
   end
 
+  def test_create_without_type_should_render_select_type
+    assert_no_difference 'CustomField.count' do
+      post :create, :custom_field => {:name => ''}
+    end
+    assert_response :success
+    assert_template 'select_type'
+  end
+
   def test_edit
     get :edit, :id => 1
     assert_response :success