Skip to content

Commit

Permalink
mlm object nested
Browse files Browse the repository at this point in the history
  • Loading branch information
will-r committed Nov 21, 2011
1 parent f6c47bf commit 0987149
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 72 deletions.
9 changes: 7 additions & 2 deletions app/models/mailing_list_membership.rb
Expand Up @@ -10,8 +10,13 @@ def self.of_list(listname)
self self
end end


def exist?(address) [:digest, :not_metoo, :nomail, :plain].each do |col|
!!self.find_by_id(address) define_method(col) do
read_attribute(col) == 'Y'
end
define_method("#{col}=") do |value|
write_attribute(col, (!!value ? 'Y' : 'N'))
end
end end


end end
20 changes: 20 additions & 0 deletions app/views/accounts/_mailing_list.html.haml
@@ -0,0 +1,20 @@
- fields_for @reader do |rf|
- @reader.build_mailing_list_membership unless @reader.mailing_list_membership
- rf.fields_for :mailing_list_membership do |mf|
#mailing_list
%h3
= t('mailing_list_preferences')
%p
= t('control_your_subscription', :list_name => "#{Radiant.config['reader.mailman.list_name']}@")
%br
= mf.check_box :nomail
= mf.label :nomail
%br
= mf.check_box :digest
= mf.label :digest
%br
= mf.check_box :plain
= mf.label :plain
%br
= mf.check_box :not_metoo
= mf.label :not_metoo
13 changes: 0 additions & 13 deletions app/views/admin/accounts/_mailing_list.html.haml

This file was deleted.

@@ -1,6 +1,6 @@
#mailing_list_settings.box #mailing_list_settings
%h3 %h3
=t("reader_mailman_extension.mailing_list_configuration") =t("mailing_list_configuration")
%p %p
= edit_config 'reader.mailman.list_name' = edit_config 'reader.mailman.list_name'
%p %p
Expand Down
Expand Up @@ -2,7 +2,7 @@
%h3 %h3
.actions .actions
= button_to t("edit"), edit_admin_reader_settings_url, :method => :get = button_to t("edit"), edit_admin_reader_settings_url, :method => :get
=t("reader_mailman_extension.mailing_list_configuration") =t("mailing_list_configuration")
%p.ruled %p.ruled
= show_config 'reader.mailman.list_name' = show_config 'reader.mailman.list_name'
%p.ruled %p.ruled
Expand Down
34 changes: 21 additions & 13 deletions app/views/admin/readers/_mailing_list.html.haml
@@ -1,13 +1,21 @@
#mailing_list - fields_for @reader do |rf|
%p #mailing_list
= f.check_box :opt_out_of_mailing_list %h3
= f.label :opt_out_of_mailing_list, :class => "checkbox" = t('mailing_list_preferences')
%br %p
= f.check_box :mailing_list_digested = rf.check_box :opt_out_of_mailing_list
= f.label :mailing_list_digested, :class => "checkbox" = rf.label :opt_out_of_mailing_list
%br %br
= f.check_box :mailing_list_notmetoo - @reader.build_mailing_list_membership
= f.label :mailing_list_notmetoo, :class => "checkbox" - rf.fields_for :mailing_list_membership do |mf|
%br = mf.check_box :nomail
= f.check_box :mailing_list_nomail = mf.label :nomail
= f.label :mailing_list_nomail, :class => "checkbox" %br
= mf.check_box :digest
= mf.label :digest
%br
= mf.check_box :plain
= mf.label :plain
%br
= mf.check_box :not_metoo
= mf.label :not_metoo
26 changes: 16 additions & 10 deletions config/locales/en.yml
@@ -1,18 +1,24 @@
en: en:
activerecord: activerecord:
attributes: attributes:
reader: mailing_list_membership:
opt_out_of_mailing_list: "Tick this box if you <strong>do not</strong> want to go on the mailing list" nomail: "Tick this box if you <strong>do not</strong> want to receive mailing list messages"
mailing_list_digest: "Get mailing list as digest instead of individual messages" digest: "Get the mailing list as a daily digest instead of individual messages"
mailing_list_notmetoo: "Don't receive your own messages to the mailing list" plain: "Get digest messages in plain text rather than HTML"
mailing_list_nomail: "Switch off the mailing list temporarily but remain a member" not_metoo: "Don't receive an echo of your own messages to the mailing list"
errors: errors:
models: models:
download: download:
attributes: attributes:
config: config:
download: reader:
download: "download" mailman:
downloads: "Downloads" list_name: mailing list name
downloads_extension: host: database host
permission_denied: "You do not have permission to download the requested file." port: database port
username: db username
password: db password
control_your_subscription: "You can also control your membership of the %{list_name} mailing list from here:"
mailing_list: "Mailing list"
mailing_list_configuration: "Mailing list configuration"
mailing_list_preferences: "Mailing list preferences"
27 changes: 1 addition & 26 deletions lib/mailing_list_reader.rb
Expand Up @@ -3,32 +3,7 @@ module MailingListReader # for inclusion into Reader
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
has_one :mailing_list_membership, :primary_key => 'email', :foreign_key => 'address', :dependent => :destroy has_one :mailing_list_membership, :primary_key => 'email', :foreign_key => 'address', :dependent => :destroy

accepts_nested_attributes_for :mailing_list_membership
include InstanceMethods
after_create :create_list_membership
before_update :update_list_membership
end
end

module InstanceMethods
def create_list_membership
unless self.opt_out_of_mailing_list?
self.create_mailing_list_membership(:name => name, :ack => 'Y', :bi_date => 0, :bi_lastnotice => 0)
end
end

def update_list_membership
if reader.opts_out_of_mailing_list?
mailing_list_membership.destroy
else
mailing_list_membership ||= create_list_membership
mailing_list_membership.address = self.new_email if self.email.changed?
mailing_list_membership.digested = self.mailing_list_digested? ? 'Y' : 'N'
mailing_list_membership.notmetoo = self.mailing_list_notmetoo? ? 'Y' : 'N'
mailing_list_membership.nomail = self.mailing_list_nomail? ? 'Y' : 'N'
mailing_list_membership.save if mailing_list_membership.changed?
end
end end

end end
end end
9 changes: 4 additions & 5 deletions reader_mailman_extension.rb
Expand Up @@ -6,11 +6,10 @@ class ReaderMailmanExtension < Radiant::Extension
def activate def activate
Reader.send :include, MailingListReader Reader.send :include, MailingListReader


admin.reader.edit.add :form, "mailing_list", :after => 'edit_group' admin.account.edit.add :form, "accounts/mailing_list", :after => 'edit_password'
admin.account.edit.add :form, "mailing_list", :after => 'edit_password' admin.reader.edit.add :form, "admin/readers/mailing_list", :after => 'edit_group'
admin.reader.edit.add :form, "mailing_list", :before => 'edit_address' admin.reader_configuration.show.add :settings, "admin/reader_configuration/mailing_list", :after => "administration"
admin.reader_configuration.show.add :settings, "mailman", :after => "administration" admin.reader_configuration.edit.add :form, "admin/reader_configuration/edit_mailing_list", :after => "administration"
admin.reader_configuration.edit.add :form, "mailman", :after => "administration"
end end


end end

0 comments on commit 0987149

Please sign in to comment.