]> source.dussan.org Git - redmine.git/commitdiff
Set an appropriate default type in New custom field page depending on the current...
authorGo MAEDA <maeda@farend.jp>
Sat, 11 May 2019 02:06:28 +0000 (02:06 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 11 May 2019 02:06:28 +0000 (02:06 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@18156 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/custom_fields_helper.rb
app/views/custom_fields/index.html.erb
app/views/custom_fields/select_type.html.erb
test/helpers/custom_fields_helper_test.rb

index b4b44b238adc2aafe4ed06fe535dc9997cea17d4..0172bad0a41731a779d467c66f1cf6e310da55fb 100644 (file)
@@ -194,4 +194,15 @@ module CustomFieldsHelper
     end
     form.select :edit_tag_style, select_options, :label => :label_display
   end
+
+  def select_type_radio_buttons(default_type)
+    if CUSTOM_FIELDS_TABS.none? {|tab| tab[:name] == default_type}
+      default_type = 'IssueCustomField'
+    end
+    custom_field_type_options.map do |name, type|
+      content_tag(:label, :style => 'display:block;') do
+        radio_button_tag('type', type, type == default_type) + name
+      end
+    end.join("\n").html_safe
+  end
 end
index cf2193db52ae87668489901d47f9b6f249ef839f..3f1154dc7d0d6f1edc309eb5c94a8da95bc3f478 100644 (file)
@@ -1,5 +1,5 @@
 <div class="contextual">
-<%= link_to l(:label_custom_field_new), new_custom_field_path, :class => 'icon icon-add' %>
+<%= link_to_function l(:label_custom_field_new), "location.href = '#{new_custom_field_path}?tab=' + encodeURIComponent($('.tabs a.selected').attr('id').split('tab-').pop())", :class => 'icon icon-add' %>
 </div>
 
 <%= title l(:label_custom_field_plural) %>
index 084c9f3a76fa1d61a9f66f919e4242af7b36e11b..78d3e940ed8ee3ab1a4249d40d6ccbce74ba55b3 100644 (file)
@@ -1,13 +1,10 @@
 <%= custom_field_title @custom_field %>
 
-<% 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 %>
+  <%= select_type_radio_buttons(params[:tab]) %>
   </p>
   </div>
   <p><%= submit_tag l(:label_next).html_safe + " &#187;".html_safe, :name => nil %></p>
index 0316921128beae8a6cc4c1c76249ce128be4f21d..9bbdcd8e6adc8a0b068940ad8e85df58eaf5b3b5 100644 (file)
@@ -95,4 +95,14 @@ class CustomFieldsHelperTest < Redmine::HelperTest
 
     assert_select_in custom_field_tag('object', value), 'textarea[class=?]', 'text_cf wiki-edit'
   end
+
+  def test_select_type_radio_buttons
+    result = select_type_radio_buttons('UserCustomField')
+    assert_select_in result, 'input[type="radio"]', :count => 10
+    assert_select_in result, 'input#type_UserCustomField[checked=?]', 'checked'
+
+    result = select_type_radio_buttons(nil)
+    assert_select_in result, 'input[type="radio"]', :count => 10
+    assert_select_in result, 'input#type_IssueCustomField[checked=?]', 'checked'
+  end
 end