<%= error_messages_for 'custom_field' %>
-<script type="text/javascript">
-//<![CDATA[
-function toggle_custom_field_format() {
- var format = $("#custom_field_field_format").val();
- var p_length = $("#custom_field_min_length");
- var p_regexp = $("#custom_field_regexp");
- var p_values = $("#custom_field_possible_values");
- var p_searchable = $("#custom_field_searchable");
- var p_default = $("#custom_field_default_value");
- var p_multiple = $("#custom_field_multiple");
- // can't change type on JQuery objects
- var p_default2 = document.getElementById("custom_field_default_value");
-
- p_default2.type = 'text';
- p_default.parent().show();
-
- switch (format) {
- case "list":
- p_length.parent().hide();
- p_regexp.parent().hide();
- p_searchable.parent().show();
- p_values.parent().show();
- p_multiple.parent().show();
- break;
- case "bool":
- p_default2.type = 'checkbox';
- p_length.parent().hide();
- p_regexp.parent().hide();
- p_searchable.parent().hide();
- p_values.parent().hide();
- p_multiple.parent().hide();
- break;
- case "date":
- p_length.parent().hide();
- p_regexp.parent().hide();
- p_searchable.parent().hide();
- p_values.parent().hide();
- p_multiple.parent().hide();
- break;
- case "float":
- case "int":
- p_length.parent().show();
- p_regexp.parent().show();
- p_searchable.parent().hide();
- p_values.parent().hide();
- p_multiple.parent().hide();
- break;
- case "user":
- case "version":
- p_length.parent().hide();
- p_regexp.parent().hide();
- p_searchable.parent().hide();
- p_values.parent().hide();
- p_multiple.parent().show();
- p_default.parent().hide();
- break;
- default:
- p_length.parent().show();
- p_regexp.parent().show();
- p_searchable.parent().show();
- p_values.parent().hide();
- p_multiple.parent().hide();
- break;
- }
-}
-
-//]]>
-</script>
-
<div class="box tabular">
<p><%= f.text_field :name, :required => true %></p>
-<p><%= f.select :field_format, custom_field_formats_for_select(@custom_field), {}, :onchange => "toggle_custom_field_format();",
- :disabled => !@custom_field.new_record? %></p>
+<p><%= f.select :field_format, custom_field_formats_for_select(@custom_field), {}, :disabled => !@custom_field.new_record? %></p>
+
+<% if @custom_field.format_in? 'list', 'user', 'version' %>
<p><%= f.check_box :multiple, :disabled => @custom_field.multiple && !@custom_field.new_record? %></p>
+<% end %>
+
+<% unless @custom_field.format_in? 'list', 'bool', 'date', 'user', 'version' %>
<p><label for="custom_field_min_length"><%=l(:label_min_max_length)%></label>
<%= f.text_field :min_length, :size => 5, :no_label => true %> -
<%= f.text_field :max_length, :size => 5, :no_label => true %><br />(<%=l(:text_min_max_length_info)%>)</p>
<p><%= f.text_field :regexp, :size => 50 %><br />(<%=l(:text_regexp_info)%>)</p>
+<% end %>
+
+<% if @custom_field.format_in? 'list' %>
<p>
<%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"), :rows => 15 %>
<em class="info"><%= l(:text_custom_field_possible_values_info) %></em>
</p>
+<% end %>
+
+<% unless @custom_field.format_in? 'user', 'version' %>
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
+<% end %>
+
<%= call_hook(:view_custom_fields_form_upper_box, :custom_field => @custom_field, :form => f) %>
</div>
<% end %>
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
</div>
-<%= javascript_tag "toggle_custom_field_format();" %>
» <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
» <%= l(:label_custom_field_new) %></h2>
-<%= labelled_form_for :custom_field, @custom_field, :url => custom_fields_path do |f| %>
+<%= labelled_form_for :custom_field, @custom_field, :url => custom_fields_path, :html => {:id => 'custom_field_form'} do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= hidden_field_tag 'type', @custom_field.type %>
<%= submit_tag l(:button_save) %>
<% end %>
+
+<%= javascript_tag do %>
+$('#custom_field_field_format').change(function(){
+ $.ajax({
+ url: '<%= new_custom_field_path(:format => 'js') %>',
+ type: 'get',
+ data: $('#custom_field_form').serialize()
+ });
+});
+<% end %>
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../test_helper', __FILE__)
-require 'custom_fields_controller'
-
-# Re-raise errors caught by the controller.
-class CustomFieldsController; def rescue_action(e) raise e end; end
class CustomFieldsControllerTest < ActionController::TestCase
fixtures :custom_fields, :custom_values, :trackers, :users
def setup
- @controller = CustomFieldsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
@request.session[:user_id] = 1
end
assert_response :success
assert_template 'new'
assert_kind_of klass, assigns(:custom_field)
- assert_tag :select, :attributes => {:name => 'custom_field[field_format]'}
+ assert_select 'form#custom_field_form' do
+ assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]'
+ assert_select 'input[type=hidden][name=type][value=?]', klass.name
+ end
end
end
get :new, :type => 'IssueCustomField'
assert_response :success
assert_template 'new'
- assert_tag :input, :attributes => {:name => 'custom_field[name]'}
- assert_tag :select,
- :attributes => {:name => 'custom_field[field_format]'},
- :child => {
- :tag => 'option',
- :attributes => {:value => 'user'},
- :content => 'User'
- }
- assert_tag :select,
- :attributes => {:name => 'custom_field[field_format]'},
- :child => {
- :tag => 'option',
- :attributes => {:value => 'version'},
- :content => 'Version'
- }
- assert_tag :input, :attributes => {:name => 'type', :value => 'IssueCustomField'}
+ assert_select 'form#custom_field_form' do
+ assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
+ assert_select 'option[value=user]', :text => 'User'
+ assert_select 'option[value=version]', :text => 'Version'
+ end
+ assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
+ end
+ end
+
+ def test_new_js
+ get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
+ assert_response :success
+ assert_template 'new'
+ assert_equal 'text/javascript', response.content_type
+
+ field = assigns(:custom_field)
+ assert_equal 'list', field.field_format
end
def test_new_with_invalid_custom_field_class_should_render_404