Commit 670ad3a92f4842dd1b7973883804d8911fd0be3d
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/324' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/324
Showing
7 changed files
with
48 additions
and
11 deletions
Show diff stats
app/helpers/forms_helper.rb
@@ -244,7 +244,7 @@ module FormsHelper | @@ -244,7 +244,7 @@ module FormsHelper | ||
244 | yearSuffix: #{datepicker_options[:year_suffix].to_json} | 244 | yearSuffix: #{datepicker_options[:year_suffix].to_json} |
245 | }) | 245 | }) |
246 | </script> | 246 | </script> |
247 | - " | 247 | + ".html_safe |
248 | result | 248 | result |
249 | end | 249 | end |
250 | 250 |
plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
@@ -27,6 +27,7 @@ class CustomFormsPluginProfileController < ProfileController | @@ -27,6 +27,7 @@ class CustomFormsPluginProfileController < ProfileController | ||
27 | failed_answers.each do |answer| | 27 | failed_answers.each do |answer| |
28 | @submission.errors.add(answer.field.name.to_sym, answer.errors[answer.field.slug.to_sym]) | 28 | @submission.errors.add(answer.field.name.to_sym, answer.errors[answer.field.slug.to_sym]) |
29 | end | 29 | end |
30 | + raise 'Submission failed: answers not valid' | ||
30 | end | 31 | end |
31 | session[:notice] = _('Submission saved') | 32 | session[:notice] = _('Submission saved') |
32 | redirect_to :action => 'show' | 33 | redirect_to :action => 'show' |
plugins/custom_forms/lib/custom_forms_plugin/helper.rb
@@ -103,14 +103,17 @@ module CustomFormsPlugin::Helper | @@ -103,14 +103,17 @@ module CustomFormsPlugin::Helper | ||
103 | 103 | ||
104 | def build_answers(submission, form) | 104 | def build_answers(submission, form) |
105 | answers = [] | 105 | answers = [] |
106 | - submission.each do |slug, value| | ||
107 | - field = form.fields.select {|field| field.slug==slug}.first | ||
108 | - if value.kind_of?(String) | ||
109 | - final_value = value | ||
110 | - elsif value.kind_of?(Array) | ||
111 | - final_value = value.join(',') | ||
112 | - elsif value.kind_of?(Hash) | ||
113 | - final_value = value.map {|option, present| present == '1' ? option : nil}.compact.join(',') | 106 | + form.fields.each do |field| |
107 | + final_value = '' | ||
108 | + if submission.has_key?(field.slug) | ||
109 | + value = submission[field.slug] | ||
110 | + if value.kind_of?(String) | ||
111 | + final_value = value | ||
112 | + elsif value.kind_of?(Array) | ||
113 | + final_value = value.join(',') | ||
114 | + elsif value.kind_of?(Hash) | ||
115 | + final_value = value.map {|option, present| present == '1' ? option : nil}.compact.join(',') | ||
116 | + end | ||
114 | end | 117 | end |
115 | answers << CustomFormsPlugin::Answer.new(:field => field, :value => final_value) | 118 | answers << CustomFormsPlugin::Answer.new(:field => field, :value => final_value) |
116 | end | 119 | end |
plugins/custom_forms/public/field.js
@@ -8,7 +8,6 @@ jQuery('.icon-edit').live('click', function() { | @@ -8,7 +8,6 @@ jQuery('.icon-edit').live('click', function() { | ||
8 | id = jQuery(elem).attr('field_id'); | 8 | id = jQuery(elem).attr('field_id'); |
9 | type = jQuery('#fields_'+id+'_type').val().split('_')[0]; | 9 | type = jQuery('#fields_'+id+'_type').val().split('_')[0]; |
10 | selector = '#edit-'+type+'-'+id | 10 | selector = '#edit-'+type+'-'+id |
11 | - jQuery(selector).show(); | ||
12 | return selector | 11 | return selector |
13 | } | 12 | } |
14 | }); | 13 | }); |
plugins/custom_forms/public/style.css
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../controllers/custom_forms_plugin_profile_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class CustomFormsPluginProfileController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class CustomFormsPluginProfileControllerTest < ActionController::TestCase | ||
8 | + def setup | ||
9 | + @controller = CustomFormsPluginProfileController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + @profile = create_user('profile').person | ||
13 | + login_as(@profile.identifier) | ||
14 | + environment = Environment.default | ||
15 | + environment.enable_plugin(CustomFormsPlugin) | ||
16 | + end | ||
17 | + | ||
18 | + attr_reader :profile | ||
19 | + | ||
20 | + should 'save submission if fields are ok' do | ||
21 | + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') | ||
22 | + field1 = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form, :mandatory => true) | ||
23 | + field2 = CustomFormsPlugin::TextField.create(:name => 'License', :form => form) | ||
24 | + | ||
25 | + assert_difference CustomFormsPlugin::Submission, :count, 1 do | ||
26 | + post :show, :profile => profile.identifier, :id => form.id, :submission => {field1.name.to_slug => 'Noosfero', field2.name.to_slug => 'GPL'} | ||
27 | + end | ||
28 | + assert !session[:notice].include?('not saved') | ||
29 | + assert_redirected_to :action => 'show' | ||
30 | + end | ||
31 | +end |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_empty_option.html.erb
1 | <tr id=<%= "empty-option-#{counter}" %> option_id=<%= option_counter %> style="display: none;"> | 1 | <tr id=<%= "empty-option-#{counter}" %> option_id=<%= option_counter %> style="display: none;"> |
2 | <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][name]") %></td> | 2 | <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][name]") %></td> |
3 | - <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][value]", nil, :size => 15) %></td> | 3 | + <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][value]") %></td> |
4 | <td class='actions'> | 4 | <td class='actions'> |
5 | <%= button_without_text :remove, _('Remove'), '#', :class => 'remove-option', :field_id => counter, :option_id => option_counter, :confirm => _('Are you sure you want to remove this option?') %> | 5 | <%= button_without_text :remove, _('Remove'), '#', :class => 'remove-option', :field_id => counter, :option_id => option_counter, :confirm => _('Are you sure you want to remove this option?') %> |
6 | </td> | 6 | </td> |