Permalink
Browse files

mlm object nested

  • Loading branch information...
1 parent f6c47bf commit 09871491c721563c73d07631628a778c0a335a15 @will-r will-r committed Nov 21, 2011
@@ -10,8 +10,13 @@ def self.of_list(listname)
self
end
- def exist?(address)
- !!self.find_by_id(address)
+ [:digest, :not_metoo, :nomail, :plain].each do |col|
+ define_method(col) do
+ read_attribute(col) == 'Y'
+ end
+ define_method("#{col}=") do |value|
+ write_attribute(col, (!!value ? 'Y' : 'N'))
+ end
end
end
@@ -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
@@ -1,13 +0,0 @@
-#mailing_list
- %p
- = f.check_box :opt_out_of_mailing_list
- = f.label :opt_out_of_mailing_list, :class => "checkbox"
- %br
- = f.check_box :mailing_list_digested
- = f.label :mailing_list_digested, :class => "checkbox"
- %br
- = f.check_box :mailing_list_notmetoo
- = f.label :mailing_list_notmetoo, :class => "checkbox"
- %br
- = f.check_box :mailing_list_nomail
- = f.label :mailing_list_nomail, :class => "checkbox"
@@ -1,6 +1,6 @@
-#mailing_list_settings.box
+#mailing_list_settings
%h3
- =t("reader_mailman_extension.mailing_list_configuration")
+ =t("mailing_list_configuration")
%p
= edit_config 'reader.mailman.list_name'
%p
@@ -2,7 +2,7 @@
%h3
.actions
= button_to t("edit"), edit_admin_reader_settings_url, :method => :get
- =t("reader_mailman_extension.mailing_list_configuration")
+ =t("mailing_list_configuration")
%p.ruled
= show_config 'reader.mailman.list_name'
%p.ruled
@@ -1,13 +1,21 @@
-#mailing_list
- %p
- = f.check_box :opt_out_of_mailing_list
- = f.label :opt_out_of_mailing_list, :class => "checkbox"
- %br
- = f.check_box :mailing_list_digested
- = f.label :mailing_list_digested, :class => "checkbox"
- %br
- = f.check_box :mailing_list_notmetoo
- = f.label :mailing_list_notmetoo, :class => "checkbox"
- %br
- = f.check_box :mailing_list_nomail
- = f.label :mailing_list_nomail, :class => "checkbox"
+- fields_for @reader do |rf|
+ #mailing_list
+ %h3
+ = t('mailing_list_preferences')
+ %p
+ = rf.check_box :opt_out_of_mailing_list
+ = rf.label :opt_out_of_mailing_list
+ %br
+ - @reader.build_mailing_list_membership
+ - rf.fields_for :mailing_list_membership do |mf|
+ = 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
View
@@ -1,18 +1,24 @@
en:
activerecord:
attributes:
- reader:
- opt_out_of_mailing_list: "Tick this box if you <strong>do not</strong> want to go on the mailing list"
- mailing_list_digest: "Get mailing list as digest instead of individual messages"
- mailing_list_notmetoo: "Don't receive your own messages to the mailing list"
- mailing_list_nomail: "Switch off the mailing list temporarily but remain a member"
+ mailing_list_membership:
+ nomail: "Tick this box if you <strong>do not</strong> want to receive mailing list messages"
+ digest: "Get the mailing list as a daily digest instead of individual messages"
+ plain: "Get digest messages in plain text rather than HTML"
+ not_metoo: "Don't receive an echo of your own messages to the mailing list"
errors:
models:
download:
attributes:
config:
- download:
- download: "download"
- downloads: "Downloads"
- downloads_extension:
- permission_denied: "You do not have permission to download the requested file."
+ reader:
+ mailman:
+ list_name: mailing list name
+ host: database host
+ 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"
View
@@ -3,32 +3,7 @@ module MailingListReader # for inclusion into Reader
def self.included(base)
base.class_eval do
has_one :mailing_list_membership, :primary_key => 'email', :foreign_key => 'address', :dependent => :destroy
-
- 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
+ accepts_nested_attributes_for :mailing_list_membership
end
-
end
end
@@ -6,11 +6,10 @@ class ReaderMailmanExtension < Radiant::Extension
def activate
Reader.send :include, MailingListReader
- admin.reader.edit.add :form, "mailing_list", :after => 'edit_group'
- admin.account.edit.add :form, "mailing_list", :after => 'edit_password'
- admin.reader.edit.add :form, "mailing_list", :before => 'edit_address'
- admin.reader_configuration.show.add :settings, "mailman", :after => "administration"
- admin.reader_configuration.edit.add :form, "mailman", :after => "administration"
+ admin.account.edit.add :form, "accounts/mailing_list", :after => 'edit_password'
+ admin.reader.edit.add :form, "admin/readers/mailing_list", :after => 'edit_group'
+ admin.reader_configuration.show.add :settings, "admin/reader_configuration/mailing_list", :after => "administration"
+ admin.reader_configuration.edit.add :form, "admin/reader_configuration/edit_mailing_list", :after => "administration"
end
end

0 comments on commit 0987149

Please sign in to comment.