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.
|
* Opens a prompt with the URL to copy to clipboard.
|
||||||
* Used in the campaign index view.
|
* Used in the campaign index view.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ module Admin
|
||||||
class EventsController < ApplicationController
|
class EventsController < ApplicationController
|
||||||
before_filter :verify_organizer
|
before_filter :verify_organizer
|
||||||
|
|
||||||
|
before_action :get_event, except: [:index, :create]
|
||||||
|
|
||||||
# FIXME: The timezome should only be applied on output, otherwise
|
# FIXME: The timezome should only be applied on output, otherwise
|
||||||
# you get lost in timezone conversions...
|
# you get lost in timezone conversions...
|
||||||
# around_filter :set_timezone_for_this_request
|
# around_filter :set_timezone_for_this_request
|
||||||
|
|
@ -71,7 +73,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@event = @conference.events.find(params[:id])
|
|
||||||
@tracks = @conference.tracks
|
@tracks = @conference.tracks
|
||||||
@event_types = @conference.event_types
|
@event_types = @conference.event_types
|
||||||
@comments = @event.root_comments
|
@comments = @event.root_comments
|
||||||
|
|
@ -81,7 +82,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@event = @conference.events.find(params[:id])
|
|
||||||
@event_types = @conference.event_types
|
@event_types = @conference.event_types
|
||||||
@tracks = Track.all
|
@tracks = Track.all
|
||||||
@comments = @event.root_comments
|
@comments = @event.root_comments
|
||||||
|
|
@ -91,8 +91,7 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def comment
|
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!
|
comment.save!
|
||||||
if !params[:parent].nil?
|
if !params[:parent].nil?
|
||||||
comment.move_to_child_of(params[:parent])
|
comment.move_to_child_of(params[:parent])
|
||||||
|
|
@ -102,7 +101,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@event = Event.find(params[:id])
|
|
||||||
if params.has_key? :track_id
|
if params.has_key? :track_id
|
||||||
@event.update_attribute(:track_id, params[:track_id])
|
@event.update_attribute(:track_id, params[:track_id])
|
||||||
end
|
end
|
||||||
|
|
@ -127,27 +125,30 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept
|
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
|
end
|
||||||
|
|
||||||
def confirm
|
def confirm
|
||||||
update_state(params[:id], :confirm, 'Event confirmed!')
|
update_state(:confirm, 'Event confirmed!')
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
update_state(params[:id], :cancel, 'Event canceled!')
|
update_state(:cancel, 'Event canceled!')
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject
|
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
|
end
|
||||||
|
|
||||||
def restart
|
def restart
|
||||||
update_state(params[:id], :restart, 'Review started!')
|
update_state(:restart, 'Review started!')
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote
|
def vote
|
||||||
@event = Event.find(params[:id])
|
|
||||||
@ratings = @event.votes.includes(:user)
|
@ratings = @event.votes.includes(:user)
|
||||||
|
|
||||||
if votes = current_user.votes.find_by_event_id(params[:id])
|
if votes = current_user.votes.find_by_event_id(params[:id])
|
||||||
|
|
@ -167,31 +168,25 @@ module Admin
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_state(id, transition, notice, mail = false)
|
def get_event
|
||||||
event = Event.find(id)
|
@event = @conference.events.find_by_id(params[:id])
|
||||||
if mail && params[:send_mail].blank? && event &&
|
if !@event
|
||||||
(event.conference.email_settings.rejected_email_template.nil? ||
|
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||||
event.conference.email_settings.accepted_email_template.nil?)
|
alert: 'Error! Could not find event!') && return
|
||||||
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
|
||||||
notice: 'Update Email Template before Sending Mails') && return
|
|
||||||
end
|
end
|
||||||
if event
|
@event
|
||||||
begin
|
end
|
||||||
if mail
|
|
||||||
event.send(transition,
|
def update_state(transition, notice, mail = false, subject = false, send_mail = false)
|
||||||
send_mail: params[:send_mail])
|
alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?)
|
||||||
else
|
|
||||||
event.send(transition)
|
if !alert.blank?
|
||||||
end
|
return redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||||
event.save
|
alert: alert) && return
|
||||||
rescue Transitions::InvalidTransition => e
|
|
||||||
notice = "Update state failed. #{e.message}"
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
notice = 'Error! Could not find event!'
|
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
||||||
|
notice: notice) && return
|
||||||
end
|
end
|
||||||
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
|
||||||
notice: notice) && return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ class Event < ActiveRecord::Base
|
||||||
if conference.email_settings.send_on_accepted &&
|
if conference.email_settings.send_on_accepted &&
|
||||||
conference.email_settings.accepted_email_template &&
|
conference.email_settings.accepted_email_template &&
|
||||||
conference.email_settings.accepted_subject &&
|
conference.email_settings.accepted_subject &&
|
||||||
options[:send_mail].blank?
|
!options[:send_mail].blank?
|
||||||
Rails.logger.debug 'Sending event acceptance mail'
|
Rails.logger.debug 'Sending event acceptance mail'
|
||||||
Mailbot.acceptance_mail(self).deliver
|
Mailbot.acceptance_mail(self).deliver
|
||||||
end
|
end
|
||||||
|
|
@ -148,7 +148,7 @@ class Event < ActiveRecord::Base
|
||||||
if conference.email_settings.send_on_rejected &&
|
if conference.email_settings.send_on_rejected &&
|
||||||
conference.email_settings.rejected_email_template &&
|
conference.email_settings.rejected_email_template &&
|
||||||
conference.email_settings.rejected_subject &&
|
conference.email_settings.rejected_subject &&
|
||||||
options[:send_mail].blank?
|
!options[:send_mail].blank?
|
||||||
Rails.logger.debug 'Sending rejected mail'
|
Rails.logger.debug 'Sending rejected mail'
|
||||||
Mailbot.rejection_mail(self).deliver
|
Mailbot.rejection_mail(self).deliver
|
||||||
end
|
end
|
||||||
|
|
@ -186,6 +186,25 @@ class Event < ActiveRecord::Base
|
||||||
result
|
result
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def abstract_limit
|
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
|
.row
|
||||||
.col-md-8
|
.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|
|
= 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?"
|
.row
|
||||||
= f.input :registration_subject
|
.col-md-12
|
||||||
= f.input :registration_email_template, :input_html => { :rows => 10, :cols => 20}
|
= 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 :send_on_accepted, :label => false, :hint => "Send an email when the proposal is accepted?"
|
= f.input :registration_subject
|
||||||
= f.input :accepted_subject
|
= f.input :registration_email_template, :input_html => { :rows => 10, :cols => 20}
|
||||||
= f.input :accepted_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",
|
||||||
= f.input :send_on_rejected, :label => false, :hint => "Send an email when the proposal is rejected?"
|
"data-name"=>"email_settings_registration_email_template"} Load Template
|
||||||
= f.input :rejected_subject
|
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"registration_help"}
|
||||||
= f.input :rejected_email_template, :input_html => { :rows => 10, :cols => 20 }
|
Show Help
|
||||||
= 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?"
|
= render partial: 'help', locals: {id: 'registration_help'}
|
||||||
= f.input :confirmed_without_registration_subject
|
= 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 :confirmed_email_template, :input_html => { :rows => 10, :cols => 20 }
|
= f.input :accepted_subject
|
||||||
= f.input :send_on_updated_conference_dates, hint: "This is to notify all participants that the conference dates has been changed."
|
= f.input :accepted_email_template, :input_html => { :rows => 10, :cols => 20 }
|
||||||
= f.input :updated_conference_dates_subject
|
%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",
|
||||||
= f.input :updated_conference_dates_template, :input_html => { :rows => 10, :cols => 20 }
|
"data-name"=>"email_settings_accepted_email_template"} Load Template
|
||||||
= f.input :send_on_updated_conference_registration_dates, hint: "This is to notify all participants that the conference registration dates has been changed."
|
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"accepted_help"}
|
||||||
= f.input :updated_conference_registration_dates_subject
|
Show Help
|
||||||
= f.input :updated_conference_registration_dates_template, :input_html => { :rows => 10, :cols => 20 }
|
= render partial: 'help', locals: {id: 'accepted_help'}
|
||||||
= f.input :send_on_venue_update, hint: 'Send an email on updating the Venue.'
|
= 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 :venue_update_subject
|
= f.input :rejected_subject
|
||||||
= f.input :venue_update_template, :input_html => { :rows => 10, :cols => 20 }
|
= f.input :rejected_email_template, :input_html => { :rows => 10, :cols => 20 }
|
||||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
%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
|
||||||
:javascript
|
%a.btn.btn-link.control_label.template_help_link{"data-name"=>"rejected_help"}
|
||||||
$(document).ready( function() {
|
Show Help
|
||||||
$("#template-help").hide();
|
= render partial: 'help', locals: {id: 'rejected_help'}
|
||||||
$("#template-help-link").click(function() {
|
= 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"}
|
||||||
$("#template-help").toggle();
|
= 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',
|
fill_in 'email_settings_confirmed_email_template',
|
||||||
with: 'Confirmed without registration email body'
|
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'
|
click_button 'Update Email settings'
|
||||||
|
|
||||||
expect(flash).
|
expect(flash).
|
||||||
|
|
@ -58,7 +68,14 @@ feature Event do
|
||||||
value).to eq('Confirmed without registration subject')
|
value).to eq('Confirmed without registration subject')
|
||||||
expect(find('#email_settings_confirmed_email_template').
|
expect(find('#email_settings_confirmed_email_template').
|
||||||
value).to eq('Confirmed without registration email body')
|
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)
|
expect(EmailSettings.count).to eq(expected_count)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue