Permalink
Browse files

can email presenters

  • Loading branch information...
1 parent 0e5918b commit a24646ebdbf0249e8e51653546f74ed9fd0460f6 @paulanthonywilson paulanthonywilson committed Apr 14, 2012
@@ -323,3 +323,23 @@ table#proposal_votes tr:nth-of-type(11n) td{
}
}
}
+
+#email {
+ // display: none;
+ margin: 20px 0;
+ border: solid 1px #888;
+ width: 530px;
+ #subject, #body, input{
+ clear:both;
+ display: block;
+ margin: 10px;
+ }
+ #subject {
+ width: 500px;
+ }
+ #body {
+ width: 502px;
+ height: 200px;
+ }
+}
+
@@ -31,6 +31,13 @@ def index
@proposals = Proposal.all(:include=>:presenter, :conditions=>@state_filter.condition).sort_by(&:average_score).reverse
end
+ def email_presenters
+ params[:proposal_ids].each do |id|
+ proposal = Proposal.find(id)
+ PresenterMailer.email_about_proposal(proposal, params[:subject], params[:body]).deliver
+ end
+ end
+
def update_state
@proposal = Proposal.find(params[:id], :include=>:presenter)
@@ -0,0 +1,2 @@
+alert("Well, that's gone!");
+$('#subject, #body').val('');
@@ -9,7 +9,38 @@
</div>
</div>
+<h2><%= link_to_function "Email", "$('#email').toggle('blind');" %></h2>
+<div id="email">
+ <input id="subject" type="text">
+ <textarea id="body" type="text"></textarea>
+ <%= button_to_function "Send to selected", "sendEmailToSelected()" %>
+</div>
+<script>
+ var sendEmailToSelected;
+ $(function(){
+ sendEmailToSelected = function(){
+ var proposal_ids = $.makeArray($('.select_proposal:checked')
+ .map(function(){return parseInt($(this).val());}));
+ var subject = $('#subject').val();
+ var body = $('#body').val();
+ $.ajax({
+ type: 'post',
+ data: {subject: subject, body: body, proposal_ids:proposal_ids},
+ headers: {
+ 'X-CSRF-Token': '<%= form_authenticity_token.to_s %>'
+ },
+ complete: function(request){},
+ url: "<%= email_presenters_admin_proposals_path %>"
+ });
+ }
+ }
+ );
+</script>
+<p>
+ All:
+ <input id="toggle_all_proposals" type="checkbox">
+</p>
<div id="admin_proposal_list">
<% @proposals.each_with_index do |proposal, i|%>
<%= div_for proposal do %>
@@ -22,6 +53,6 @@
<script>
$('.state_checkbox').change(function(){$('#admin_proposals_form').submit();});
$('#toggle_all_proposals').change(function(){
- $('.select_proposal').attr('checked', $(this).attr('checked'));
+ $('.select_proposal').prop('checked', $(this).prop('checked'));
});
</script>
@@ -14,7 +14,7 @@
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
- config.action_mailer.raise_delivery_errors = false
+ config.action_mailer.raise_delivery_errors = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
@@ -0,0 +1,9 @@
+ActionMailer::Base.smtp_settings = {
+ :address => 'smtp.sendgrid.net',
+ :port => '587',
+ :authentication => :plain,
+ :user_name => 'conference@scottishrubyconference.com',
+ :password => 'is-oas-jeb-yac',
+ :domain => 'scottishrubyconference.com'
+}
+ActionMailer::Base.delivery_method = :smtp
View
@@ -20,6 +20,7 @@
end
collection do
get :delegate_votes
+ post :email_presenters
end
end
end
View
@@ -12,6 +12,7 @@
%w(title reviewer_notes description).each do |attr|
sequence(attr){|n| "#{attr}#{n}"}
end
+ presenter
end
factory :rating do |f|
@@ -67,17 +67,34 @@ def setup
context "update state" do
setup do
@proposal = FactoryGirl.create(:proposal, :state=>'submitted', :presenter=>Factory.create(:presenter))
- put :update_state, :id=>@proposal.id, :event=>'accept'
+ put :update_state, :id=>@proposal.id, :event=>'accept', :format=>'js'
end
should "update the proposal state" do
assert_equal 'accepted', @proposal.reload.state
end
- should render_template 'proposal'
+ should render_template('update_state')
end
+
+ context :email_presenters do
+ setup do
+ @proposals = [Factory(:proposal), Factory(:proposal)]
+ end
+ should "email all the presenters" do
+ @proposals.each do |proposal|
+ email = flexmock('email')
+ flexmock(PresenterMailer).should_receive(:email_about_proposal).with(proposal, "Hello", "How are you?").and_return(email).once
+ email.should_receive(:deliver).once
+ end
+
+ post :email_presenters, :subject=>'Hello', :body=>'How are you?',
+ :proposal_ids=>@proposals.map(&:id)
+ end
+ end
+
end

0 comments on commit a24646e

Please sign in to comment.