diff --git a/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb b/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb index bcb23f6..e1138e7 100644 --- a/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb +++ b/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb @@ -18,6 +18,7 @@ class CustomFormsPluginProfileController < ProfileController if request.post? begin raise 'Submission already present!' if user.present? && CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) + raise 'Form expired!' if @form.expired? # @submission.answers for some reason has the same answer twice failed_answers = answers.select {|answer| !answer.valid? } diff --git a/plugins/custom_forms/lib/custom_forms_plugin/helper.rb b/plugins/custom_forms/lib/custom_forms_plugin/helper.rb index 7458a4e..6fc3af1 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/helper.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/helper.rb @@ -77,26 +77,26 @@ module CustomFormsPlugin::Helper def display_text_field(field, answer, form) value = answer.present? ? answer.value : field.default_value - text_field(form, "#{field.id}", :value => value, :disabled => answer.present? && answer.id.present?) + text_field(form, "#{field.id}", :value => value, :disabled => (answer.present? && answer.id.present?) || field.form.expired? ) end def display_select_field(field, answer, form) case field.select_field_type when 'multiple_select' selected = answer.present? ? answer.value.split(',') : field.alternatives.select {|a| a.selected_by_default}.map{|a| a.id.to_s} - select_tag "submission[#{field.id}]", options_for_select(field.alternatives.map{|a| [a.label, a.id.to_s]}, selected), :multiple => true, :size => field.alternatives.size, :disabled => answer.present? && answer.id.present? + select_tag "submission[#{field.id}]", options_for_select(field.alternatives.map{|a| [a.label, a.id.to_s]}, selected), :multiple => true, :size => field.alternatives.size, :disabled => (answer.present? && answer.id.present?) || field.form.expired? when 'check_box' field.alternatives.map do |alternative| default = answer.present? ? answer.value.split(',').include?(alternative.id.to_s) : alternative.selected_by_default - labelled_check_box alternative.label, "submission[#{field.id}][#{alternative.id}]", '1', default, :disabled => answer.present? && answer.id.present? + labelled_check_box alternative.label, "submission[#{field.id}][#{alternative.id}]", '1', default, :disabled => (answer.present? && answer.id.present?) || field.form.expired? end.join("\n") when 'select' selected = answer.present? ? answer.value.split(',') : field.alternatives.select {|a| a.selected_by_default}.map{|a| a.id.to_s} - select_tag "submission[#{field.id}]", options_for_select([['','']] + field.alternatives.map {|a| [a.label, a.id.to_s]}, selected), :disabled => answer.present? && answer.id.present? + select_tag "submission[#{field.id}]", options_for_select([['','']] + field.alternatives.map {|a| [a.label, a.id.to_s]}, selected), :disabled => (answer.present? && answer.id.present?) || field.form.expired? when 'radio' field.alternatives.map do |alternative| default = answer.present? ? answer.value == alternative.id.to_s : alternative.selected_by_default - labelled_radio_button alternative.label, "submission[#{field.id}]", alternative.id, default, :disabled => answer.present? && answer.id.present? + labelled_radio_button alternative.label, "submission[#{field.id}]", alternative.id, default, :disabled => (answer.present? && answer.id.present?) || field.form.expired? end.join("\n") end end diff --git a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb index df54bb8..f5f0d69 100644 --- a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb +++ b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb @@ -28,4 +28,14 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase assert !session[:notice].include?('not saved') assert_redirected_to :action => 'show' end + + should 'disable fields if form expired' do + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day) + form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field") + + get :show, :profile => profile.identifier, :id => form.id + + assert_tag :tag => 'h2', :content => 'Sorry, you can\'t fill this form right now' + assert_tag :tag => 'input', :attributes => {:disabled => 'disabled'} + end end diff --git a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb index 71f46e3..3b70153 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb @@ -1,6 +1,10 @@
<%= @form.description %>
+<% if @form.expired? %> +