Implements "Add template" button for email settings

fix #16
Subjects now required
This commit is contained in:
Chrisbr 2014-07-18 13:46:39 +02:00
parent 4d25abccc3
commit 6dab37a2b7
3 changed files with 59 additions and 13 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,13 +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 && params[:send_mail].blank? && event &&
(event.conference.email_settings.rejected_email_template.nil? ||
event.conference.email_settings.accepted_email_template.nil?)
if mail && params[:send_mail].blank? && event && subject
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
notice: 'Update Email Template before Sending Mails') && return
notice: 'Please add a Subject before sending Mails!') && return
end
if event
begin

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"}