-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contact form refactored and ajaxified
- Loading branch information
1 parent
394af7c
commit ec5f74a
Showing
16 changed files
with
72 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class ContactForm | ||
include ActiveData::Model | ||
|
||
attribute :email_transfer_accepted, type: Boolean, default: true | ||
attribute :text, type: String | ||
|
||
|
||
validates :email_transfer_accepted, acceptance: { accept: true } | ||
validates :text, length: { maximum: 2000 }, presence: true | ||
|
||
def mail(sender, resource_id, resource_type) | ||
mailer = get_mailer_for resource_type | ||
mailer.delay.contact(sender: sender, resource_id: resource_id, text: self.text) if mailer | ||
end | ||
|
||
def get_mailer_for resource_type | ||
return ArticleMailer if resource_type == "article" | ||
return UserMailer if resource_type == "user" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#contact_form | ||
- if current_user | ||
p | ||
= t('article.show.contact.description') | ||
= semantic_form_for get_or_create_contact_form , url: toolbox_contact_path(resource_type: resource_type, resource_id: resource_id), remote: true, method: :post do |f| | ||
= f.inputs do | ||
= f.input :email_transfer_accepted, label: t('article.show.contact.email_transfer_accepted_label'), as: :boolean, required: true | ||
= f.input :text, as: :text, input_html: { rows: 4 } | ||
= f.actions do | ||
= f.action :submit, label: t('article.show.contact.action'), button_html: {class: "Button"} | ||
- else | ||
| Um eine Rückfrage stellen zu können, musst Du dich bei Fairmondo | ||
=<> link_to 'registrieren', new_user_registration_path | ||
| und | ||
=<> link_to('einloggen', new_user_session_path) + '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- if @contact_form.errors.present? | ||
render "toolbox/contact", resource_type: params[:resource_type], resource_id: params[:resource_id] | ||
- else | ||
p | ||
= I18n.t('users.profile.contact.success_notice') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if @contact_form.errors.present? %> | ||
$("#contact_form").replaceWith("<%= j render "toolbox/contact", resource_type: params[:resource_type], resource_id: params[:resource_id] %>"); | ||
<% else %> | ||
$("#contact_form").replaceWith("<p><%= I18n.t('users.profile.contact.success_notice') %></p>"); | ||
$.colorbox.resize() | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
/ Contact Box (refactor when we have a real messaging system) | ||
.Content.contact_seller | ||
- if current_user | ||
h1= t('users.profile.contact.heading') | ||
h4= t('users.profile.contact.description') | ||
= semantic_form_for :contact, url: toolbox_contact_path, method: :get, html: { class: 'js-visual-submit' } do |f| | ||
= f.inputs do | ||
= f.hidden_field :user_id, value: resource.id | ||
- text = (session[:seller_message]) ? session[:seller_message][resource.id.to_s] : nil | ||
= f.input :text, as: :text, label: t('users.profile.contact.labels.text'),input_html: { rows: 4, value: text, placeholder: t('users.profile.contact.labels.text') } | ||
= f.input :email_transfer_accepted, label: t('users.profile.contact.email_transfer_accepted_label'), as: :boolean, required: true, input_html: { checked: true } | ||
|
||
= f.actions do | ||
= f.action :submit, label: t('users.profile.contact.action'), button_html: {class: "Button"} | ||
- else | ||
| Um eine Rückfrage stellen zu können, musst Du dich bei Fairmondo | ||
=<> link_to 'registrieren', new_user_registration_path | ||
| und | ||
=<> link_to('einloggen', new_user_session_path) + '.' | ||
|
||
/ Contact Box (refactor when we have a real messaging system) | ||
.Content | ||
h1= t('users.profile.contact.heading') | ||
= render 'toolbox/contact', resource_type: :user, resource_id: @user.id |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters