This commit is contained in:
Christian Bruckmayer 2014-07-18 11:50:13 +00:00
commit 0ca2c61e2d
7 changed files with 93 additions and 35 deletions

View file

@ -1,4 +1,40 @@
$(function() {
/**
* Adds the default template as value to the regarding email textarea field.
*/
$(".load_template").on('click', function(){
var template = $(this).data('template');
var textarea_name = $(this).data('name');
$('#' + textarea_name).val(template);
});
/**
* Toggle the required attribute on click on_send_email radio button.
*/
$('.send_on_radio').click(function() {
toggle_required_for_mail_subjects($(this))
});
/**
* Adds required attribute to on_send_email radio button if necessary.
*/
$('.send_on_radio').each(function() {
toggle_required_for_mail_subjects($(this))
});
/**
* Toggle the required attribute helper function.
*/
function toggle_required_for_mail_subjects($this){
var name = $this.data('name');
if($this.is(':checked')) {
$('#' + name).prop('required', true);
}else
{
$('#' + name).removeAttr('required');
}
}
/**
* Opens a prompt with the URL to copy to clipboard.
* Used in the campaign index view.

View file

@ -127,7 +127,9 @@ module Admin
end
def accept
update_state(params[:id], :accept, 'Event accepted!', true)
event = Event.find(params[:id])
subject = event.conference.email_settings.accepted_subject.blank?
update_state(params[:id], :accept, 'Event accepted!', true, subject)
end
def confirm
@ -139,7 +141,9 @@ module Admin
end
def reject
update_state(params[:id], :reject, 'Event rejected!', true)
event = Event.find(params[:id])
subject = event.conference.email_settings.rejected_subject.blank?
update_state(params[:id], :reject, 'Event rejected!', true, subject)
end
def restart
@ -167,10 +171,11 @@ module Admin
private
def update_state(id, transition, notice, mail = false)
def update_state(id, transition, notice, mail = false, subject = nil)
event = Event.find(id)
if mail
check_mail_settings(event)
if mail && params[:send_mail].blank? && event && subject
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: 'Please add a Subject before sending Mails!') && return
end
if event
begin
@ -182,25 +187,13 @@ module Admin
end
event.save
rescue Transitions::InvalidTransition => e
redirect_to(
admin_conference_events_path(conference_id: @conference.short_title),
notice: "Update state failed. #{e.message}") && return
notice = "Update state failed. #{e.message}"
end
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: notice)
else
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: 'Error! Could not find event!')
end
end
def check_mail_settings(event)
if !params[:send_mail].blank? && event &&
event.conference.email_settings.rejected_email_template.nil? &&
event.conference.email_settings.accepted_email_template.nil?
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: 'Update Email Template before Sending Mails') && return
notice = 'Error! Could not find event!'
end
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: notice) && return
end
end
end

View file

@ -162,7 +162,7 @@ class ProposalController < ApplicationController
if @event.transition_possible? :confirm
begin
@event.confirm!
rescue InvalidTransition => e
rescue Transitions::InvalidTransition => e
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
alert: "Event was NOT confirmed: #{e.message}")
return
@ -187,7 +187,7 @@ class ProposalController < ApplicationController
begin
@event.restart
@event.save
rescue InvalidTransition => e
rescue Transitions::InvalidTransition => e
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
alert: "Event was NOT restarted: #{e.message}")
return

View file

@ -124,7 +124,9 @@ class Event < ActiveRecord::Base
end
def process_confirmation
if conference.email_settings.send_on_confirmed_without_registration?
if conference.email_settings.send_on_confirmed_without_registration? &&
conference.email_settings.confirmed_email_template &&
conference.email_settings.confirmed_without_registration_subject
if conference.registrations.where(user_id: submitter.id).first.nil?
Mailbot.confirm_reminder_mail(self).deliver
end
@ -133,6 +135,8 @@ class Event < ActiveRecord::Base
def process_acceptance(options)
if conference.email_settings.send_on_accepted &&
conference.email_settings.accepted_email_template &&
conference.email_settings.accepted_subject &&
options[:send_mail].blank?
Rails.logger.debug 'Sending event acceptance mail'
Mailbot.acceptance_mail(self).deliver
@ -141,6 +145,8 @@ class Event < ActiveRecord::Base
def process_rejection(options)
if conference.email_settings.send_on_rejected &&
conference.email_settings.rejected_email_template &&
conference.email_settings.rejected_subject &&
options[:send_mail].blank?
Rails.logger.debug 'Sending rejected mail'
Mailbot.rejection_mail(self).deliver

View file

@ -23,22 +23,30 @@
%td {eventtitle}
%td The title of an accepted or rejected proposal
= semantic_form_for(@settings, :url => admin_conference_email_path(@conference.short_title, @conference.email_settings),:html => {:multipart => true}) do |f|
= f.input :send_on_registration, :label => false, :hint => "Send an email when the user registers for the conference?"
= f.input :send_on_registration, :label => false, :hint => "Send an email when the user registers for the conference?", :input_html => {"data-name"=>"email_settings_registration_subject", "class"=>"send_on_radio"}
= f.input :registration_subject
= f.input :registration_email_template, :input_html => { :rows => 10, :cols => 20}
= f.input :send_on_accepted, :label => false, :hint => "Send an email when the proposal is accepted?"
%a.control_label.load_template{"data-template"=>"Dear {name},\n\nThank you for Registering for the conference {conference}.\nPlease complete your registration by filling out your travel information.\n\nIf you are unable to attend please unregister online:\n{registrationlink}\n\nFeel free to contact us with any questions or concerns.\nWe look forward to see you there.\n\nBest wishes\n\n{conference} Team",
"data-name"=>"email_settings_registration_email_template"} Load Template
= f.input :send_on_accepted, :label => false, :hint => "Send an email when the proposal is accepted?", :input_html => {"data-name"=>"email_settings_accepted_subject", "class"=>"send_on_radio"}
= f.input :accepted_subject
= f.input :accepted_email_template, :input_html => { :rows => 10, :cols => 20 }
= f.input :send_on_rejected, :label => false, :hint => "Send an email when the proposal is rejected?"
%a.control_label.load_template{"data-template"=>"Dear {name}\n\nWe are very pleased to inform you that your submission {eventtitle} has been accepted for the conference {conference}.\n\nThe public page of your submission can be found at:\n{proposalslink}\nIf you haven´t already registered for {conference}, please do as soon as possible:\n{registrationlink}\n\nFeel free to contact us with any questions or concerns.\n\nWe look forward to seeing you there.\n\nBest wishes\n\n{conference} Team",
"data-name"=>"email_settings_accepted_email_template"} Load Template
= f.input :send_on_rejected, :label => false, :hint => "Send an email when the proposal is rejected?", :input_html => {"data-name"=>"email_settings_rejected_subject", "class"=>"send_on_radio"}
= f.input :rejected_subject
= f.input :rejected_email_template, :input_html => { :rows => 10, :cols => 20 }
= f.input :send_on_confirmed_without_registration, :label => false, :hint => "Send an email when a user has a confirmed proposal, but isn't yet registered?"
%a.control_label.load_template{"data-template"=>"Dear {name},\n\nThank you for your submission {eventtitle} for the conference {conference}.\nAfter careful consideration we are sorry to inform you that your submissionhas been rejected.\n\n\nBest wishes\n\n{conference} Team",
"data-name"=>"email_settings_rejected_email_template"} Load Template
= f.input :send_on_confirmed_without_registration, :label => false, :hint => "Send an email when a user has a confirmed proposal, but isn't yet registered?", :input_html => {"data-name"=>"email_settings_confirmed_without_registration_subject", "class"=>"send_on_radio"}
= f.input :confirmed_without_registration_subject
= f.input :confirmed_email_template, :input_html => { :rows => 10, :cols => 20 }
= f.input :send_on_updated_conference_dates, hint: "This is to notify all participants that the conference dates has been changed."
%a.control_label.load_template{"data-template"=>"Dear {name},\n\nThank you for the confirmation of {eventtitle}. Unfortunately you are not registered for the conference {conference}. Please register as soon as possible:\n{registrationlink}\n\nFeel free to contact us with any questions or concerns.\n\nWe look forward to seeing you there.\n\nBest wishes\n\n{conference} Team",
"data-name"=>"email_settings_confirmed_email_template"} Load Template
= f.input :send_on_updated_conference_dates, hint: "This is to notify all participants that the conference dates has been changed.", :input_html => {"data-name"=>"email_settings_updated_conference_dates_subject", "class"=>"send_on_radio"}
= f.input :updated_conference_dates_subject
= f.input :updated_conference_dates_template, :input_html => { :rows => 10, :cols => 20 }
= f.input :send_on_updated_conference_registration_dates, hint: "This is to notify all participants that the conference registration dates has been changed."
= f.input :send_on_updated_conference_registration_dates, hint: "This is to notify all participants that the conference registration dates has been changed.", :input_html => {"data-name"=>"email_settings_updated_conference_registration_dates_subject", "class"=>"send_on_radio"}
= f.input :updated_conference_registration_dates_subject
= f.input :updated_conference_registration_dates_template, :input_html => { :rows => 10, :cols => 20 }
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}

View file

@ -0,0 +1,15 @@
class AddDefaultValueToEmailSettings < ActiveRecord::Migration
def up
change_column :email_settings, :send_on_registration, :boolean, default: false
change_column :email_settings, :send_on_accepted, :boolean, default: false
change_column :email_settings, :send_on_rejected, :boolean, default: false
change_column :email_settings, :send_on_confirmed_without_registration, :boolean, default: false
end
def down
change_column :email_settings, :send_on_registration, :boolean, default: true
change_column :email_settings, :send_on_accepted, :boolean, default: true
change_column :email_settings, :send_on_rejected, :boolean, default: true
change_column :email_settings, :send_on_confirmed_without_registration, :boolean, default: true
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140714141156) do
ActiveRecord::Schema.define(version: 20140716115448) do
create_table "ahoy_events", force: true do |t|
t.uuid "visit_id"
@ -150,10 +150,10 @@ ActiveRecord::Schema.define(version: 20140714141156) do
create_table "email_settings", force: true do |t|
t.integer "conference_id"
t.boolean "send_on_registration", default: true
t.boolean "send_on_accepted", default: true
t.boolean "send_on_rejected", default: true
t.boolean "send_on_confirmed_without_registration", default: true
t.boolean "send_on_registration", default: false
t.boolean "send_on_accepted", default: false
t.boolean "send_on_rejected", default: false
t.boolean "send_on_confirmed_without_registration", default: false
t.text "registration_email_template"
t.text "accepted_email_template"
t.text "rejected_email_template"