##// END OF EJS Templates
Update the new custom field form with remotely....
Jean-Philippe Lang -
r9980:599736aca7b9
parent child
Show More
@@ -0,0 +1,1
1 $('#content').html('<%= escape_javascript(render :template => 'custom_fields/new', :layout => nil, :formats => [:html]) %>')
@@ -261,6 +261,10 class CustomField < ActiveRecord::Base
261 261 validate_field_value(value).empty?
262 262 end
263 263
264 def format_in?(*args)
265 args.include?(field_format)
266 end
267
264 268 protected
265 269
266 270 # Returns the error message for the given value regarding its format
@@ -1,88 +1,31
1 1 <%= error_messages_for 'custom_field' %>
2 2
3 <script type="text/javascript">
4 //<![CDATA[
5 function toggle_custom_field_format() {
6 var format = $("#custom_field_field_format").val();
7 var p_length = $("#custom_field_min_length");
8 var p_regexp = $("#custom_field_regexp");
9 var p_values = $("#custom_field_possible_values");
10 var p_searchable = $("#custom_field_searchable");
11 var p_default = $("#custom_field_default_value");
12 var p_multiple = $("#custom_field_multiple");
13 // can't change type on JQuery objects
14 var p_default2 = document.getElementById("custom_field_default_value");
15
16 p_default2.type = 'text';
17 p_default.parent().show();
18
19 switch (format) {
20 case "list":
21 p_length.parent().hide();
22 p_regexp.parent().hide();
23 p_searchable.parent().show();
24 p_values.parent().show();
25 p_multiple.parent().show();
26 break;
27 case "bool":
28 p_default2.type = 'checkbox';
29 p_length.parent().hide();
30 p_regexp.parent().hide();
31 p_searchable.parent().hide();
32 p_values.parent().hide();
33 p_multiple.parent().hide();
34 break;
35 case "date":
36 p_length.parent().hide();
37 p_regexp.parent().hide();
38 p_searchable.parent().hide();
39 p_values.parent().hide();
40 p_multiple.parent().hide();
41 break;
42 case "float":
43 case "int":
44 p_length.parent().show();
45 p_regexp.parent().show();
46 p_searchable.parent().hide();
47 p_values.parent().hide();
48 p_multiple.parent().hide();
49 break;
50 case "user":
51 case "version":
52 p_length.parent().hide();
53 p_regexp.parent().hide();
54 p_searchable.parent().hide();
55 p_values.parent().hide();
56 p_multiple.parent().show();
57 p_default.parent().hide();
58 break;
59 default:
60 p_length.parent().show();
61 p_regexp.parent().show();
62 p_searchable.parent().show();
63 p_values.parent().hide();
64 p_multiple.parent().hide();
65 break;
66 }
67 }
68
69 //]]>
70 </script>
71
72 3 <div class="box tabular">
73 4 <p><%= f.text_field :name, :required => true %></p>
74 <p><%= f.select :field_format, custom_field_formats_for_select(@custom_field), {}, :onchange => "toggle_custom_field_format();",
75 :disabled => !@custom_field.new_record? %></p>
5 <p><%= f.select :field_format, custom_field_formats_for_select(@custom_field), {}, :disabled => !@custom_field.new_record? %></p>
6
7 <% if @custom_field.format_in? 'list', 'user', 'version' %>
76 8 <p><%= f.check_box :multiple, :disabled => @custom_field.multiple && !@custom_field.new_record? %></p>
9 <% end %>
10
11 <% unless @custom_field.format_in? 'list', 'bool', 'date', 'user', 'version' %>
77 12 <p><label for="custom_field_min_length"><%=l(:label_min_max_length)%></label>
78 13 <%= f.text_field :min_length, :size => 5, :no_label => true %> -
79 14 <%= f.text_field :max_length, :size => 5, :no_label => true %><br />(<%=l(:text_min_max_length_info)%>)</p>
80 15 <p><%= f.text_field :regexp, :size => 50 %><br />(<%=l(:text_regexp_info)%>)</p>
16 <% end %>
17
18 <% if @custom_field.format_in? 'list' %>
81 19 <p>
82 20 <%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"), :rows => 15 %>
83 21 <em class="info"><%= l(:text_custom_field_possible_values_info) %></em>
84 22 </p>
23 <% end %>
24
25 <% unless @custom_field.format_in? 'user', 'version' %>
85 26 <p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
27 <% end %>
28
86 29 <%= call_hook(:view_custom_fields_form_upper_box, :custom_field => @custom_field, :form => f) %>
87 30 </div>
88 31
@@ -127,4 +70,3 when "IssueCustomField" %>
127 70 <% end %>
128 71 <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
129 72 </div>
130 <%= javascript_tag "toggle_custom_field_format();" %>
@@ -2,7 +2,7
2 2 &#187; <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
3 3 &#187; <%=h @custom_field.name %></h2>
4 4
5 <%= labelled_form_for :custom_field, @custom_field, :url => custom_field_path(@custom_field), :html => {:method => :put} do |f| %>
5 <%= labelled_form_for :custom_field, @custom_field, :url => custom_field_path(@custom_field), :html => {:method => :put, :id => 'custom_field_form'} do |f| %>
6 6 <%= render :partial => 'form', :locals => { :f => f } %>
7 7 <%= submit_tag l(:button_save) %>
8 8 <% end %>
@@ -2,8 +2,18
2 2 &#187; <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
3 3 &#187; <%= l(:label_custom_field_new) %></h2>
4 4
5 <%= labelled_form_for :custom_field, @custom_field, :url => custom_fields_path do |f| %>
5 <%= labelled_form_for :custom_field, @custom_field, :url => custom_fields_path, :html => {:id => 'custom_field_form'} do |f| %>
6 6 <%= render :partial => 'form', :locals => { :f => f } %>
7 7 <%= hidden_field_tag 'type', @custom_field.type %>
8 8 <%= submit_tag l(:button_save) %>
9 9 <% end %>
10
11 <%= javascript_tag do %>
12 $('#custom_field_field_format').change(function(){
13 $.ajax({
14 url: '<%= new_custom_field_path(:format => 'js') %>',
15 type: 'get',
16 data: $('#custom_field_form').serialize()
17 });
18 });
19 <% end %>
@@ -16,18 +16,11
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'custom_fields_controller'
20
21 # Re-raise errors caught by the controller.
22 class CustomFieldsController; def rescue_action(e) raise e end; end
23 19
24 20 class CustomFieldsControllerTest < ActionController::TestCase
25 21 fixtures :custom_fields, :custom_values, :trackers, :users
26 22
27 23 def setup
28 @controller = CustomFieldsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 24 @request.session[:user_id] = 1
32 25 end
33 26
@@ -43,7 +36,10 class CustomFieldsControllerTest < ActionController::TestCase
43 36 assert_response :success
44 37 assert_template 'new'
45 38 assert_kind_of klass, assigns(:custom_field)
46 assert_tag :select, :attributes => {:name => 'custom_field[field_format]'}
39 assert_select 'form#custom_field_form' do
40 assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]'
41 assert_select 'input[type=hidden][name=type][value=?]', klass.name
42 end
47 43 end
48 44 end
49 45
@@ -51,22 +47,23 class CustomFieldsControllerTest < ActionController::TestCase
51 47 get :new, :type => 'IssueCustomField'
52 48 assert_response :success
53 49 assert_template 'new'
54 assert_tag :input, :attributes => {:name => 'custom_field[name]'}
55 assert_tag :select,
56 :attributes => {:name => 'custom_field[field_format]'},
57 :child => {
58 :tag => 'option',
59 :attributes => {:value => 'user'},
60 :content => 'User'
61 }
62 assert_tag :select,
63 :attributes => {:name => 'custom_field[field_format]'},
64 :child => {
65 :tag => 'option',
66 :attributes => {:value => 'version'},
67 :content => 'Version'
68 }
69 assert_tag :input, :attributes => {:name => 'type', :value => 'IssueCustomField'}
50 assert_select 'form#custom_field_form' do
51 assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
52 assert_select 'option[value=user]', :text => 'User'
53 assert_select 'option[value=version]', :text => 'Version'
54 end
55 assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
56 end
57 end
58
59 def test_new_js
60 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
61 assert_response :success
62 assert_template 'new'
63 assert_equal 'text/javascript', response.content_type
64
65 field = assigns(:custom_field)
66 assert_equal 'list', field.field_format
70 67 end
71 68
72 69 def test_new_with_invalid_custom_field_class_should_render_404
General Comments 0
You need to be logged in to leave comments. Login now