Skip to content

Commit

Permalink
allows admins to configure the confirmation in each language that the…
Browse files Browse the repository at this point in the history
… frontend is available in
  • Loading branch information
bryanmtl committed May 28, 2011
1 parent b5ec6f8 commit de44d1b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/inquiry_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Admin::InquirySettingsController < Admin::BaseController

before_filter :set_url_override?, :only => [:edit, :update]
after_filter :save_subject_for_confirmation?, :only => :update
after_filter :save_message_for_confirmation?, :only => :update
around_filter :rewrite_flash?, :only => :update

protected
Expand All @@ -19,6 +20,10 @@ def rewrite_flash?
def save_subject_for_confirmation?
InquirySetting.confirmation_subject = params[:subject] if params.keys.include?('subject')
end

def save_message_for_confirmation?
InquirySetting.confirmation_message = params[:message] if params.keys.include?('message')
end

def set_url_override?
@url_override = admin_inquiry_setting_url(@refinery_setting, :dialog => from_dialog?)
Expand Down
22 changes: 15 additions & 7 deletions app/models/inquiry_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ def self.confirmation_body
)
end

def self.confirmation_subject
RefinerySetting.find_or_set(:inquiry_confirmation_subject,
def self.confirmation_subject(locale='en')
RefinerySetting.find_or_set("inquiry_confirmation_subject_#{locale}".to_sym,
"Thank you for your inquiry")
end

def self.confirmation_subject=(value)
# handles a change in Refinery API
if RefinerySetting.methods.map(&:to_sym).include?(:set)
RefinerySetting.set(:inquiry_confirmation_subject, value)
else
RefinerySetting[:inquiry_confirmation_subject] = value
value.first.keys.each do |locale|
RefinerySetting.set("inquiry_confirmation_subject_#{locale}".to_sym, value.first[locale.to_sym])
end
end

def self.confirmation_message(locale='en')
RefinerySetting.find_or_set("inquiry_confirmation_messeage_#{locale}".to_sym,
RefinerySetting[:inquiry_confirmation_body])
end

def self.confirmation_message=(value)
value.first.keys.each do |locale|
RefinerySetting.set("inquiry_confirmation_messeage_#{locale}".to_sym, value.first[locale.to_sym])
end
end

def self.notification_recipients
RefinerySetting.find_or_set(:inquiry_notification_recipients,
((Role[:refinery].users.first.email rescue nil) if defined?(Role)).to_s)
Expand Down
46 changes: 24 additions & 22 deletions app/views/admin/inquiry_settings/_confirmation_email_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@
<%= "#{RefinerySetting[:site_name]} &lt;no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}&gt;".html_safe %>
</td>
</tr>
<tr>
<td>
<label class='stripped'><%= t('.subject') %></label>
</td>
<td>
<%= text_field_tag 'subject', InquirySetting.confirmation_subject,
:class => 'widest' %>
</td>
</tr>
<tr>
<td valign='top'>
<%= f.label :value, t('.message'),
:class => 'stripped' %>
</td>
<td>
<%= f.text_area :value, :value => f.object.value, # required, we can't use :value
:rows => "5",
:class => 'widest' %>
<br/>
<em><%= t('.note') %></em>
</td>
</tr>
<% ::Refinery::I18n.frontend_locales.each do |locale| %>
<tr>
<td>
<label class='stripped'><%= t('.subject') %> (<%= locale.to_s %>)</label>
</td>
<td>
<%= text_field_tag "subject[][#{locale.to_s}]", InquirySetting.confirmation_subject(locale),
:class => 'widest' %>
</td>
</tr>
<tr>
<td valign='top'>
<%= f.label :value, t('.message'),
:class => 'stripped' %> (<%= locale.to_s %>)
</td>
<td>
<%= text_area_tag "message[][#{locale.to_s}]", InquirySetting.confirmation_message(locale), # required, we can't use :value
:rows => "5",
:class => 'widest' %>
<br/>
<em><%= t('.note') %></em>
</td>
</tr>
<% end %>
</table>

<%= render :partial => "/shared/admin/form_actions",
Expand Down

0 comments on commit de44d1b

Please sign in to comment.