diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb index 8225c7d..0eed935 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb @@ -43,6 +43,10 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord (begining.present? && Time.now < begining) || (ending.present? && Time.now > ending) end + def will_open? + begining.present? && Time.now < begining + end + def accessible_to(target) return true if access.nil? || target == profile return false if target.nil? 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 f5f0d69..237ca95 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 @@ -35,7 +35,23 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase 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 + + should 'show expired message' 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 yet' + + form.begining = Time.now - 2.days + form.ending = Time.now - 1.days + form.save + + get :show, :profile => profile.identifier, :id => form.id + + assert_tag :tag => 'h2', :content => 'Sorry, you can\'t fill this form anymore' + end end diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb index bee84c0..f44f1ca 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb @@ -89,6 +89,22 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase assert !form.expired? end + should 'define if form will still open' do + form = CustomFormsPlugin::Form.new + assert !form.will_open? + + form.begining = Time.now + 1.day + assert form.will_open? + + form.begining = Time.now - 1.day + assert !form.will_open? + + form.begining = Time.now - 2.day + form.ending = Time.now - 1.day + assert form.expired? + assert !form.will_open? + end + should 'validates format of access' do form = CustomFormsPlugin::Form.new form.valid? 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 1bd7174..8d99864 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 @@ -3,7 +3,11 @@ <% if @submission.id.nil? %> <% if @form.expired? %> -

<%= _('Sorry, you can\'t fill this form right now') %>

+ <% if @form.will_open? %> +

<%= _('Sorry, you can\'t fill this form yet') %>

+ <% else %> +

<%= _('Sorry, you can\'t fill this form anymore') %>

+ <% end %> <% end %> <%= error_messages_for :submission %> diff --git a/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb b/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb index 0c63425..87fac78 100644 --- a/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb +++ b/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb @@ -4,7 +4,11 @@

<%= @form.name %>

<%= @form.description %>

<% if @form.expired? %> -

<%= _('Sorry, you can\'t fill this form right now') %>

+ <% if @form.will_open? %> +

<%= _('Sorry, you can\'t fill this form yet') %>

+ <% else %> +

<%= _('Sorry, you can\'t fill this form anymore') %>

+ <% end %> <% end %> <% f.fields_for :submission do |fi| %> diff --git a/po/pt/noosfero.po b/po/pt/noosfero.po index 2d4da85..0694103 100644 --- a/po/pt/noosfero.po +++ b/po/pt/noosfero.po @@ -11497,9 +11497,13 @@ msgstr "Nome do autor" msgid "Author email" msgstr "Email do autor" -#: plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb:5 -msgid "Sorry, you can't fill this form right now" -msgstr "Desculpe, você não pode preencher esse formulário no momento" +#: plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb:7 +msgid "Sorry, you can't fill this form yet" +msgstr "Desculpe, você não pode preencher esse formulário ainda" + +#: plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb:9 +msgid "Sorry, you can't fill this form anymore" +msgstr "Desculpe, você não pode mais preencher esse formulário" #: plugins/custom_forms/views/custom_forms_plugin_myprofile/_empty_field.html.erb:8 #: plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb:10 -- libgit2 0.21.2