Update the new custom field form with remotely.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10163 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
1749fbf3e6
commit
599736aca7
@ -261,6 +261,10 @@ class CustomField < ActiveRecord::Base
|
|||||||
validate_field_value(value).empty?
|
validate_field_value(value).empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_in?(*args)
|
||||||
|
args.include?(field_format)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Returns the error message for the given value regarding its format
|
# Returns the error message for the given value regarding its format
|
||||||
|
@ -1,88 +1,31 @@
|
|||||||
<%= error_messages_for 'custom_field' %>
|
<%= 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">
|
<div class="box tabular">
|
||||||
<p><%= f.text_field :name, :required => true %></p>
|
<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();",
|
<p><%= f.select :field_format, custom_field_formats_for_select(@custom_field), {}, :disabled => !@custom_field.new_record? %></p>
|
||||||
: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>
|
<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>
|
<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 :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>
|
<%= 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>
|
<p><%= f.text_field :regexp, :size => 50 %><br />(<%=l(:text_regexp_info)%>)</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @custom_field.format_in? 'list' %>
|
||||||
<p>
|
<p>
|
||||||
<%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"), :rows => 15 %>
|
<%= 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>
|
<em class="info"><%= l(:text_custom_field_possible_values_info) %></em>
|
||||||
</p>
|
</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>
|
<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) %>
|
<%= call_hook(:view_custom_fields_form_upper_box, :custom_field => @custom_field, :form => f) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -127,4 +70,3 @@ when "IssueCustomField" %>
|
|||||||
<% end %>
|
<% end %>
|
||||||
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
|
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
|
||||||
</div>
|
</div>
|
||||||
<%= javascript_tag "toggle_custom_field_format();" %>
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
» <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
|
» <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
|
||||||
» <%=h @custom_field.name %></h2>
|
» <%=h @custom_field.name %></h2>
|
||||||
|
|
||||||
<%= labelled_form_for :custom_field, @custom_field, :url => custom_field_path(@custom_field), :html => {:method => :put} do |f| %>
|
<%= labelled_form_for :custom_field, @custom_field, :url => custom_field_path(@custom_field), :html => {:method => :put, :id => 'custom_field_form'} do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -2,8 +2,18 @@
|
|||||||
» <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
|
» <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
|
||||||
» <%= l(:label_custom_field_new) %></h2>
|
» <%= 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 } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= hidden_field_tag 'type', @custom_field.type %>
|
<%= hidden_field_tag 'type', @custom_field.type %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<% end %>
|
<% 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 %>
|
||||||
|
1
app/views/custom_fields/new.js.erb
Normal file
1
app/views/custom_fields/new.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$('#content').html('<%= escape_javascript(render :template => 'custom_fields/new', :layout => nil, :formats => [:html]) %>')
|
@ -16,18 +16,11 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
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
|
class CustomFieldsControllerTest < ActionController::TestCase
|
||||||
fixtures :custom_fields, :custom_values, :trackers, :users
|
fixtures :custom_fields, :custom_values, :trackers, :users
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = CustomFieldsController.new
|
|
||||||
@request = ActionController::TestRequest.new
|
|
||||||
@response = ActionController::TestResponse.new
|
|
||||||
@request.session[:user_id] = 1
|
@request.session[:user_id] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -43,7 +36,10 @@ class CustomFieldsControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'new'
|
assert_template 'new'
|
||||||
assert_kind_of klass, assigns(:custom_field)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,22 +47,23 @@ class CustomFieldsControllerTest < ActionController::TestCase
|
|||||||
get :new, :type => 'IssueCustomField'
|
get :new, :type => 'IssueCustomField'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'new'
|
assert_template 'new'
|
||||||
assert_tag :input, :attributes => {:name => 'custom_field[name]'}
|
assert_select 'form#custom_field_form' do
|
||||||
assert_tag :select,
|
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
|
||||||
:attributes => {:name => 'custom_field[field_format]'},
|
assert_select 'option[value=user]', :text => 'User'
|
||||||
:child => {
|
assert_select 'option[value=version]', :text => 'Version'
|
||||||
:tag => 'option',
|
end
|
||||||
:attributes => {:value => 'user'},
|
assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
|
||||||
:content => 'User'
|
end
|
||||||
}
|
end
|
||||||
assert_tag :select,
|
|
||||||
:attributes => {:name => 'custom_field[field_format]'},
|
def test_new_js
|
||||||
:child => {
|
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
|
||||||
:tag => 'option',
|
assert_response :success
|
||||||
:attributes => {:value => 'version'},
|
assert_template 'new'
|
||||||
:content => 'Version'
|
assert_equal 'text/javascript', response.content_type
|
||||||
}
|
|
||||||
assert_tag :input, :attributes => {:name => 'type', :value => 'IssueCustomField'}
|
field = assigns(:custom_field)
|
||||||
|
assert_equal 'list', field.field_format
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_with_invalid_custom_field_class_should_render_404
|
def test_new_with_invalid_custom_field_class_should_render_404
|
||||||
|
Loading…
x
Reference in New Issue
Block a user