noosfero | 3 new commits pushed to repository
Daniela Feitosa
gitlab at gitlab.com
Mon Mar 16 21:33:31 BRT 2015
Daniela Feitosa pushed to refs/heads/stable-1.0 at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/b250b7114f420cb36207ec38f441580719393282">b250b711</a> by Daniela Feitosa
Fix: allowing submission of not logged users
Added the missing character to identify form
(cherry picked from commit 5b7b8e5273a8ef165d8dba64e500832583da4835)
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/bc3b02296c150ce45aa067a92ffbab8c033473c9">bc3b0229</a> by Daniela Feitosa
Fix: link to add more files on upload of files
Conflicts:
app/views/cms/_upload_file.html.erb
public/javascripts/application.js
(cherry picked from commit f3577c1b29363d9b8de8aa9e4b853518ceb0dd76)
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/46ef5a80ef19915b0d0f0893afae86c16118d3e9">46ef5a80</a> by Daniela Feitosa
Fix: display error msgs when form submission fails
(cherry picked from commit 0b9f2d0d4c364c71b56c0a74a44b4bb6dd20976e)
- - - - -
Changes:
=====================================
app/helpers/cms_helper.rb
=====================================
--- a/app/helpers/cms_helper.rb
+++ b/app/helpers/cms_helper.rb
@@ -9,12 +9,6 @@ module CmsHelper
mime_type.gsub('/', '_').gsub('-', '')
end
- def add_upload_file_field(name, locals)
- button_to_function :add, name, nil do |page|
- page.insert_html :bottom, :uploaded_files, CGI::escapeHTML(render(:partial => 'upload_file', :locals => locals, :object => UploadedFile.new))
- end
- end
-
def pagination_links(collection, options={})
options = {:previous_label => '« ', :next_label => ' »', :page_links => false}.merge(options)
will_paginate(collection, options)
=====================================
app/views/cms/_upload_file.html.erb
=====================================
--- a/app/views/cms/_upload_file.html.erb
+++ b/app/views/cms/_upload_file.html.erb
@@ -1,2 +1 @@
<p><%= file_field_tag('uploaded_files[]', :size => size) %></p>
-<%= javascript_tag("$('uploaded_files').scrollTop = $('uploaded_files').scrollHeight") %>
=====================================
app/views/cms/_upload_file_form.html.erb
=====================================
--- a/app/views/cms/_upload_file_form.html.erb
+++ b/app/views/cms/_upload_file_form.html.erb
@@ -13,7 +13,7 @@
<%= hidden_field_tag('back_to', @back_to) %>
<% button_bar do %>
- <%= add_upload_file_field(_('More files'), {:size => size}) %>
+ <%= button_to_function :add, _('More files'), "add_new_file_fields()" %>
<% if @back_to %>
<%= submit_button :save, _('Upload'), :cancel => @back_to %>
<% else %>
=====================================
plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
=====================================
--- a/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
+++ b/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
@@ -9,7 +9,7 @@ class CustomFormsPluginProfileController < ProfileController
@submission = CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id)
@submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user)
else
- @submission = CustomFormsPlugin::Submission.new(:form => @for)
+ @submission = CustomFormsPlugin::Submission.new(:form => @form)
end
# build the answers
=====================================
plugins/custom_forms/lib/custom_forms_plugin/submission.rb
=====================================
--- a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb
@@ -5,7 +5,7 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord
# validation is done manually, see below
has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy, :validate => false
- attr_accessible :form, :profile
+ attr_accessible :form, :profile, :author_name, :author_email
validates_presence_of :form
validates_presence_of :author_name, :author_email, :if => lambda {|submission| submission.profile.nil?}
@@ -13,13 +13,16 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord
validates_format_of :author_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|submission| !submission.author_email.blank?})
validate :check_answers
- def self.human_attribute_name(attrib)
- if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_i))
+ def self.human_attribute_name_with_customization(attrib, options={})
+ if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_s))
f.name
else
- attrib
+ _(self.human_attribute_name_without_customization(attrib))
end
end
+ class << self
+ alias_method_chain :human_attribute_name, :customization
+ end
before_create do |submission|
if submission.profile
=====================================
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
=====================================
--- 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
@@ -29,6 +29,30 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase
assert_redirected_to :action => 'show'
end
+ should 'save submission if fields are ok and user is not logged in' do
+ logout
+ form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software')
+ field = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form)
+
+ assert_difference 'CustomFormsPlugin::Submission.count', 1 do
+ post :show, :profile => profile.identifier, :id => form.id, :author_name => "john", :author_email => 'john at example.com', :submission => {field.id.to_s => 'Noosfero'}
+ end
+ assert_redirected_to :action => 'show'
+ end
+
+ should 'display errors if user is not logged in and author_name is not uniq' do
+ logout
+ form = CustomFormsPlugin::Form.create(:profile => profile, :name => 'Free Software')
+ field = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form)
+ submission = CustomFormsPlugin::Submission.create(:form => form, :author_name => "john", :author_email => 'john at example.com')
+
+ assert_no_difference 'CustomFormsPlugin::Submission.count' do
+ post :show, :profile => profile.identifier, :id => form.id, :author_name => "john", :author_email => 'john at example.com', :submission => {field.id.to_s => 'Noosfero'}
+ end
+ assert_equal "Submission could not be saved", session[:notice]
+ assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }
+ 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")
=====================================
public/javascripts/application.js
=====================================
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -1096,3 +1096,10 @@ function apply_zoom_to_images(zoom_text) {
});
});
}
+
+function add_new_file_fields() {
+ var cloned = jQuery('#uploaded_files p:last').clone();
+ cloned.find("input[type='file']").val('');
+ cloned.appendTo('#uploaded_files');
+ jQuery('body').scrollTo(cloned);
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150317/4404c576/attachment.html>
More information about the Noosfero-dev
mailing list