Browse files

Email settings

  • Loading branch information...
1 parent a43ee15 commit 49ffa47f9d46792ebb4da5c2db94268a7ffd51ca Angelo Grossini committed Apr 6, 2011
View
14 app/controllers/admin/membership_emails_controller.rb
@@ -4,5 +4,19 @@ class MembershipEmailsController < Admin::BaseController
:title_attribute => :title,
:order => "title ASC",
:xhr_paging => true
+
+ def settings
+ find_all_membership_emails
+ @users = User.where(['membership_level <> ? OR membership_level IS NULL', 'Member']).all
+ end
+
+ def save_settings
+ params[:settings].each do | key, value |
+ value.reject!{|v| !v || v == ''} if value.is_a?(Array)
+ puts "#{key} #{value}"
+ RefinerySetting.set(key, value)
+ end if params[:settings].present?
+ render :text => "<script>parent.window.$('.ui-dialog .ui-dialog-titlebar-close').trigger('click');</script>"
+ end
end
end
View
5 app/views/admin/membership_emails/_email_setting.html.erb
@@ -0,0 +1,5 @@
+<p class="field checkbox">
+ <%= hidden_field_tag "settings[deliver_mail_on_#{email_setting}]", false, :id => '' %>
+ <%= check_box_tag "settings[deliver_mail_on_#{email_setting}]", true, RefinerySetting.find_or_set("deliver_mail_on_#{email_setting}", true) %>
+ <label for="<%= "settings_deliver_mail_on_#{email_setting}" %>"><%= t(email_setting, :scope => 'admin.membership_emails') %></label>
+</p>
View
7 app/views/admin/membership_emails/_settings_admin_notification.html.erb
@@ -0,0 +1,7 @@
+<div id="admin_notifications" style="display: none;" class="dialog_area">
+ <h3><%= t('deliver_admin_notifications_to', :scope => 'admin.membership_emails.settings')%>:</h3>
+ <%= hidden_field_tag "settings[deliver_notification_to_users][]" %>
+ <% if @users.any? %>
+ <%= render :partial => 'user_entry', :collection => @users %>
+ <% end %>
+</div>
View
6 app/views/admin/membership_emails/_settings_email_delivery.html.erb
@@ -0,0 +1,6 @@
+<div id="email_delivery" class="dialog_area">
+ <h3><%= t('deliver_notifications_on', :scope => 'admin.membership_emails.settings')%>:</h3>
+ <% if @membership_emails.any? %>
+ <%= render :partial => 'email_setting', :collection => @membership_emails.collect{|m| m.title} %>
+ <% end %>
+</div>
View
7 app/views/admin/membership_emails/_user_entry.html.erb
@@ -0,0 +1,7 @@
+<p class="field checkbox">
+ <%= check_box_tag "settings[deliver_notification_to_users][]",
+ user_entry.email,
+ RefinerySetting.find_or_set('deliver_notification_to_users', @users.collect{|u|u.email}).include?(user_entry.email),
+ :id => "user_entry_#{user_entry_counter}" %>
+ <label for="<%= "user_entry_#{user_entry_counter}" %>"><%= "#{user_entry.username} (#{user_entry.email})" %></label>
+</p>
View
34 app/views/admin/membership_emails/settings.html.erb
@@ -0,0 +1,34 @@
+<div class='clearfix dialog_email_settings'>
+ <div id="dialog_menu_left">
+ <span id="email_delivery_radio" class="radio">
+ <input type="radio" name="settings_page" value="email_delivery" id="page_email_delivery" checked="true">
+ <label for="page_email_delivery" class="stripped"><%= t('email_delivery', :scope => 'admin.membership_emails.settings') %></label>
+ </span>
+ <span id="admin_notifications_radio" class="radio">
+ <input type="radio" name="settings_page" value="admin_notifications" id="page_admin_notifications">
+ <label for="page_admin_notifications" class="stripped"><%= t('admin_notifications', :scope => 'admin.membership_emails.settings') %></label>
+ </span>
+ </div>
+
+<%= form_tag save_settings_admin_membership_emails_path, :method => 'put' do %>
+ <div id="dialog_main">
+ <%= render :partial => 'settings_email_delivery' %>
+ <%= render :partial => 'settings_admin_notification' %>
+ </div>
+
+
+ <%= render :partial => "/shared/admin/form_actions",
+ :locals => {
+ :continue_editing => false,
+ :hide_cancel => false,
+ :hide_delete => true
+ } %>
+<% end %>
+</div>
+<% content_for :stylesheets do %>
+ <%= stylesheet_link_tag 'settings_dialog'%>
+<% end %>
+
+<% content_for :javascripts do %>
+ <%= javascript_include_tag 'settings_dialog'%>
+<% end %>
View
7 config/routes.rb
@@ -11,7 +11,12 @@
put :enable
end
end
- resources :membership_emails
+ resources :membership_emails, :except => :show do
+ collection do
+ get :settings
+ put :save_settings
+ end
+ end
end
resource :members, :except => [:destroy] do
View
9 public/javascripts/settings_dialog.js
@@ -0,0 +1,9 @@
+$(function(){
+ $('#dialog_menu_left input[type="radio"]').change(function(){
+ $('.dialog_area').hide();
+ $('#'+$(this).val())[$(this).is(':checked') ? 'show' : 'hide']();
+ });
+
+ $('.form-actions-dialog #cancel_button').not('.wym_iframe_body .form-actions-dialog #cancel_button').click(close_dialog);
+
+});
View
28 public/stylesheets/settings_dialog.css
@@ -0,0 +1,28 @@
+.checkbox label {
+ display: inline;
+}
+
+.dialog form {
+ margin-bottom: 0;
+}
+
+.dialog #dialog_menu_left {
+ width: 180px;
+}
+
+.dialog #dialog_main {
+ margin-left: 180px;
+ width: 430px;
+ min-height: 320px;
+}
+
+.dialog .dialog_area {
+ background: white;
+ z-index: 100;
+ position: relative;
+ min-height: 200px;
+}
+
+.dialog .dialog_area h3 {
+ margin-top: 5px;
+}

0 comments on commit 49ffa47

Please sign in to comment.