Implements "Add template" button for email settings
close #16 Subjects now mandatory if send mail enabled
This commit is contained in:
parent
6dc1d91516
commit
24c0af7d3f
6 changed files with 184 additions and 89 deletions
|
|
@ -1,5 +1,51 @@
|
|||
$(function() {
|
||||
$(function () {
|
||||
/**
|
||||
* Toggles email template help below email body textarea field.
|
||||
*/
|
||||
$(document).ready( function() {
|
||||
$(".template-help").hide();
|
||||
$(".template_help_link").click(function() {
|
||||
var id = $(this).data('name');
|
||||
$("#" + id).toggle();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ module Admin
|
|||
class EventsController < ApplicationController
|
||||
before_filter :verify_organizer
|
||||
|
||||
before_action :get_event, except: [:index, :create]
|
||||
|
||||
# FIXME: The timezome should only be applied on output, otherwise
|
||||
# you get lost in timezone conversions...
|
||||
# around_filter :set_timezone_for_this_request
|
||||
|
|
@ -71,7 +73,6 @@ module Admin
|
|||
end
|
||||
|
||||
def show
|
||||
@event = @conference.events.find(params[:id])
|
||||
@tracks = @conference.tracks
|
||||
@event_types = @conference.event_types
|
||||
@comments = @event.root_comments
|
||||
|
|
@ -81,7 +82,6 @@ module Admin
|
|||
end
|
||||
|
||||
def edit
|
||||
@event = @conference.events.find(params[:id])
|
||||
@event_types = @conference.event_types
|
||||
@tracks = Track.all
|
||||
@comments = @event.root_comments
|
||||
|
|
@ -91,8 +91,7 @@ module Admin
|
|||
end
|
||||
|
||||
def comment
|
||||
event = @conference.events.find_by_id(params[:id])
|
||||
comment = Comment.build_from(event, current_user.id, params[:comment])
|
||||
comment = Comment.build_from(@event, current_user.id, params[:comment])
|
||||
comment.save!
|
||||
if !params[:parent].nil?
|
||||
comment.move_to_child_of(params[:parent])
|
||||
|
|
@ -102,7 +101,6 @@ module Admin
|
|||
end
|
||||
|
||||
def update
|
||||
@event = Event.find(params[:id])
|
||||
if params.has_key? :track_id
|
||||
@event.update_attribute(:track_id, params[:track_id])
|
||||
end
|
||||
|
|
@ -127,27 +125,30 @@ module Admin
|
|||
end
|
||||
|
||||
def accept
|
||||
update_state(params[:id], :accept, 'Event accepted!', true)
|
||||
send_mail = @event.conference.email_settings.send_on_accepted
|
||||
subject = @event.conference.email_settings.accepted_subject.blank?
|
||||
update_state(:accept, 'Event accepted!', true, subject, send_mail)
|
||||
end
|
||||
|
||||
def confirm
|
||||
update_state(params[:id], :confirm, 'Event confirmed!')
|
||||
update_state(:confirm, 'Event confirmed!')
|
||||
end
|
||||
|
||||
def cancel
|
||||
update_state(params[:id], :cancel, 'Event canceled!')
|
||||
update_state(:cancel, 'Event canceled!')
|
||||
end
|
||||
|
||||
def reject
|
||||
update_state(params[:id], :reject, 'Event rejected!', true)
|
||||
send_mail = @event.conference.email_settings.send_on_rejected
|
||||
subject = @event.conference.email_settings.rejected_subject.blank?
|
||||
update_state(:reject, 'Event rejected!', true, subject, send_mail)
|
||||
end
|
||||
|
||||
def restart
|
||||
update_state(params[:id], :restart, 'Review started!')
|
||||
update_state(:restart, 'Review started!')
|
||||
end
|
||||
|
||||
def vote
|
||||
@event = Event.find(params[:id])
|
||||
@ratings = @event.votes.includes(:user)
|
||||
|
||||
if votes = current_user.votes.find_by_event_id(params[:id])
|
||||
|
|
@ -167,31 +168,25 @@ module Admin
|
|||
|
||||
private
|
||||
|
||||
def update_state(id, transition, notice, mail = false)
|
||||
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?)
|
||||
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||
notice: 'Update Email Template before Sending Mails') && return
|
||||
def get_event
|
||||
@event = @conference.events.find_by_id(params[:id])
|
||||
if !@event
|
||||
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||
alert: 'Error! Could not find event!') && return
|
||||
end
|
||||
if event
|
||||
begin
|
||||
if mail
|
||||
event.send(transition,
|
||||
send_mail: params[:send_mail])
|
||||
else
|
||||
event.send(transition)
|
||||
end
|
||||
event.save
|
||||
rescue Transitions::InvalidTransition => e
|
||||
notice = "Update state failed. #{e.message}"
|
||||
end
|
||||
@event
|
||||
end
|
||||
|
||||
def update_state(transition, notice, mail = false, subject = false, send_mail = false)
|
||||
alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?)
|
||||
|
||||
if !alert.blank?
|
||||
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||
alert: alert) && return
|
||||
else
|
||||
notice = 'Error! Could not find event!'
|
||||
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||
notice: notice) && return
|
||||
end
|
||||
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||
notice: notice) && return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class Event < ActiveRecord::Base
|
|||
if conference.email_settings.send_on_accepted &&
|
||||
conference.email_settings.accepted_email_template &&
|
||||
conference.email_settings.accepted_subject &&
|
||||
options[:send_mail].blank?
|
||||
!options[:send_mail].blank?
|
||||
Rails.logger.debug 'Sending event acceptance mail'
|
||||
Mailbot.acceptance_mail(self).deliver
|
||||
end
|
||||
|
|
@ -148,7 +148,7 @@ class Event < ActiveRecord::Base
|
|||
if conference.email_settings.send_on_rejected &&
|
||||
conference.email_settings.rejected_email_template &&
|
||||
conference.email_settings.rejected_subject &&
|
||||
options[:send_mail].blank?
|
||||
!options[:send_mail].blank?
|
||||
Rails.logger.debug 'Sending rejected mail'
|
||||
Mailbot.rejection_mail(self).deliver
|
||||
end
|
||||
|
|
@ -186,6 +186,25 @@ class Event < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
def update_state(transition, mail = false, subject = false, send_mail = false, send_mail_param)
|
||||
alert = ''
|
||||
if mail && send_mail_param && subject && send_mail
|
||||
alert = 'Update Email Subject before Sending Mails'
|
||||
end
|
||||
begin
|
||||
if mail
|
||||
self.send(transition,
|
||||
send_mail: send_mail_param)
|
||||
else
|
||||
self.send(transition)
|
||||
end
|
||||
self.save
|
||||
rescue Transitions::InvalidTransition => e
|
||||
alert = "Update state failed. #{e.message}"
|
||||
end
|
||||
alert
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def abstract_limit
|
||||
|
|
|
|||
21
app/views/admin/emails/_help.html.haml
Normal file
21
app/views/admin/emails/_help.html.haml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
.template-help{:id => id}
|
||||
Valid attributes:
|
||||
%table.table
|
||||
%tr
|
||||
%td {email}
|
||||
%td The user's email address
|
||||
%tr
|
||||
%td {name}
|
||||
%td The user's full name
|
||||
%tr
|
||||
%td {conference}
|
||||
%td The full conference title
|
||||
%tr
|
||||
%td {proposalslink}
|
||||
%td A link to the user's proposal page
|
||||
%tr
|
||||
%td {registrationlink}
|
||||
%td A link to the registration page
|
||||
%tr
|
||||
%td {eventtitle}
|
||||
%td The title of an accepted or rejected proposal
|
||||
|
|
@ -1,55 +1,52 @@
|
|||
.row
|
||||
.col-md-8
|
||||
= link_to "Template Help", "#", :id => "template-help-link"
|
||||
#template-help
|
||||
Valid attributes:
|
||||
%table.table
|
||||
%tr
|
||||
%td {email}
|
||||
%td The user's email address
|
||||
%tr
|
||||
%td {name}
|
||||
%td The user's full name
|
||||
%tr
|
||||
%td {conference}
|
||||
%td The full conference title
|
||||
%tr
|
||||
%td {proposalslink}
|
||||
%td A link to the user's proposal page
|
||||
%tr
|
||||
%td {registrationlink}
|
||||
%td A link to the registration page
|
||||
%tr
|
||||
%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 :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?"
|
||||
= 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?"
|
||||
= 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?"
|
||||
= 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."
|
||||
= 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 :updated_conference_registration_dates_subject
|
||||
= f.input :updated_conference_registration_dates_template, :input_html => { :rows => 10, :cols => 20 }
|
||||
= f.input :send_on_venue_update, hint: 'Send an email on updating the Venue.'
|
||||
= f.input :venue_update_subject
|
||||
= f.input :venue_update_template, :input_html => { :rows => 10, :cols => 20 }
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
|
||||
:javascript
|
||||
$(document).ready( function() {
|
||||
$("#template-help").hide();
|
||||
$("#template-help-link").click(function() {
|
||||
$("#template-help").toggle();
|
||||
});
|
||||
});
|
||||
.row
|
||||
.col-md-12
|
||||
= f.input :send_on_registration, label: "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}
|
||||
%a.btn.btn-link.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
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"registration_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'registration_help'}
|
||||
= f.input :send_on_accepted, label: "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 }
|
||||
%a.btn.btn-link.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
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"accepted_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'accepted_help'}
|
||||
= f.input :send_on_rejected, label: "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 }
|
||||
%a.btn.btn-link.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
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"rejected_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'rejected_help'}
|
||||
= f.input :send_on_confirmed_without_registration, label: "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 }
|
||||
%a.btn.btn-link.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
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"confirmed_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'confirmed_help'}
|
||||
= f.input :send_on_updated_conference_dates, label: "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 }
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"updated_dates_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'updated_dates_help'}
|
||||
= f.input :send_on_updated_conference_registration_dates, label: "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 }
|
||||
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"updated_registrations_dates_help"}
|
||||
Show Help
|
||||
= render partial: 'help', locals: {id: 'updated_registrations_dates_help'}
|
||||
.row
|
||||
.col-md-12
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,16 @@ feature Event do
|
|||
fill_in 'email_settings_confirmed_email_template',
|
||||
with: 'Confirmed without registration email body'
|
||||
|
||||
fill_in 'email_settings_updated_conference_dates_subject',
|
||||
with: 'Updated conference dates subject'
|
||||
fill_in 'email_settings_updated_conference_dates_template',
|
||||
with: 'Updated conference dates email template'
|
||||
|
||||
fill_in 'email_settings_updated_conference_registration_dates_subject',
|
||||
with: 'Updated conference registration dates subject'
|
||||
fill_in 'email_settings_updated_conference_registration_dates_template',
|
||||
with: 'Updated conference registration dates template'
|
||||
|
||||
click_button 'Update Email settings'
|
||||
|
||||
expect(flash).
|
||||
|
|
@ -58,7 +68,14 @@ feature Event do
|
|||
value).to eq('Confirmed without registration subject')
|
||||
expect(find('#email_settings_confirmed_email_template').
|
||||
value).to eq('Confirmed without registration email body')
|
||||
|
||||
expect(find('#email_settings_updated_conference_dates_subject').
|
||||
value).to eq('Updated conference dates subject')
|
||||
expect(find('#email_settings_updated_conference_dates_template').
|
||||
value).to eq('Updated conference dates email template')
|
||||
expect(find('#email_settings_updated_conference_registration_dates_subject').
|
||||
value).to eq('Updated conference registration dates subject')
|
||||
expect(find('#email_settings_updated_conference_registration_dates_template').
|
||||
value).to eq('Updated conference registration dates template')
|
||||
expect(EmailSettings.count).to eq(expected_count)
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue