Skip to content
Snippets Groups Projects
Commit f4572bf2 authored by Tyler Lemburg's avatar Tyler Lemburg
Browse files

Email supportsgit add -A

parent e4d51098
No related branches found
No related tags found
No related merge requests found
......@@ -34,4 +34,8 @@ class ServiceSpace < ActiveRecord::Base
def admin_users_href
"/#{self.url_name}/admin/users/"
end
def admin_email_href
"/#{self.url_name}/admin/email/"
end
end
\ No newline at end of file
require 'models/user'
require 'models/permission'
before '/:service_space_url_name/admin/email*' do
unless @user.has_permission?(Permission::MANAGE_EMAILS, @space)
raise Sinatra::NotFound
end
end
get '/:service_space_url_name/admin/email/?' do
@breadcrumbs << {:text => 'Admin Emails', :href => @space.admin_email_href}
@breadcrumbs << {:text => 'Send Email'}
users = User.all.select{|user| user.in_space?(@space)}
erb :'admin/send_email', :layout => :fixed, :locals => {
:users => users
}
end
post '/:service_space_url_name/admin/email/?' do
users_to_send_to = []
# compile the list based on what was checked
if params.checked?('send_to_all_non_admins')
users = User.all.select{|user| user.in_space?(@space) && !user.is_admin?(@space)}
users_to_send_to += users
end
if params.checked?('send_to_all_users')
users = User.all.select{|user| user.in_space?(@space)}
users_to_send_to += users
end
if params.checked?('send_to_specific_user')
user = User.find_by(:id => params[:specific_user])
users_to_send_to << user unless user.nil?
end
# compact and uniqify the list
users_to_send_to = users_to_send_to.compact.uniq do |user|
user.id
end
# check on attachments
attachments = {}
params.select {|k,v| k.starts_with?('file_')}.each do |key, file_hash|
attachments[file_hash[:filename]] = file_hash[:tempfile].read
end
attachments = nil if attachments.empty?
# correctly choose how to send
if users_to_send_to.count == 1
Emailer.mail(users_to_send_to[0].email, params[:subject], params[:body], '', attachments)
output = users_to_send_to[0].full_name
elsif users_to_send_to.count > 1
bcc = users_to_send_to.map(&:email).join(',')
Emailer.mail('', params[:subject], params[:body], bcc, attachments)
output = "#{users_to_send_to.count} users"
else
flash :error, 'No Users Selected', 'This email was not sent to any users'
redirect back
end
flash :success, 'Email sent', "Your email was sent to #{output}."
redirect @space.admin_email_href
end
\ No newline at end of file
......@@ -159,10 +159,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
if (start_time >= reservation.start_time && start_time < reservation.end_time) ||
(end_time > reservation.start_time && end_time <= reservation.end_time) ||
(start_time < reservation.start_time && end_time > reservation.end_time)
flash :alert, "Tool is being used.", "Sorry, that resource is reserved during that time period. Please try another time slot."
redirect back
elsif reservation.user_id == @user.id
flash :alert, "Over Limit", "Sorry, you can only reserve this resource once per day. Please try reserving another time slot on another day."
flash :alert, "Resource is being used.", "Sorry, that resource is reserved during that time period. Please try another time slot."
redirect back
end
end
......@@ -332,10 +329,7 @@ post '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservat
if (start_time >= reservation.start_time && start_time < reservation.end_time) ||
(end_time >= reservation.start_time && end_time < reservation.end_time) ||
(start_time < reservation.start_time && end_time > reservation.end_time)
flash :alert, "Tool is being used.", "Sorry, that resource is reserved during that time period. Please try another time slot."
redirect back
elsif reservation.user_id == @user.id
flash :alert, "Over Limit", "Sorry, you can only reserve this resource once per day. Please try reserving another time slot on another day."
flash :alert, "Resource is being used.", "Sorry, that resource is reserved during that time period. Please try another time slot."
redirect back
end
end
......
<div id="pagetitle">
<h3>Send Email</h3>
</div>
<form action="" method="POST" enctype="multipart/form-data">
<div class="wdn-grid-set">
<fieldset class="bp2-wdn-col-one-half">
<legend>Send to:</legend>
<input type="checkbox" id="send-to-all-non-admins" name="send_to_all_non_admins"> <label for="send-to-all-non-admins">All Non-Admins of <%= @space.name %></label><br>
<input type="checkbox" id="send-to-all-users" name="send_to_all_users"> <label for="send-to-all-users">All Users of <%= @space.name %></label><br>
<input type="checkbox" id="send-to-specific-user" name="send_to_specific_user">
<label for="specific-user">Specific User:</label>
<select id="specific-user" name="specific_user" style="width: auto;">
<% users.sort{|x,y| x.sortable_name.downcase <=> y.sortable_name.downcase}.each do |user| %>
<option value="<%= user.id %>"><%= user.sortable_name %></option>
<% end %>
</select><br>
</fieldset>
<fieldset class="bp2-wdn-col-one-half">
<legend>Attachments</legend>
<div id="files">
<div id="file-container" class="file-container" style="padding-right: 60px; position: relative;">
<input class="file-input" type="file" name="file_1" />
<button style="display: none; position: absolute; right: 5px; top: 5px;" type="button" class="remove-file wdn-button">&times;</button>
</div>
</div>
<br>
<button id="add-file" type="button" class="wdn-button wdn-button-triad">Add another file</button>
</fieldset>
</div>
<fieldset>
<legend>Compose</legend>
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" />
<label for="body">Body:</label>
<textarea class="ckeditor" style="min-height: 150px" id="body" name="body"></textarea>
<br><br>
<button type="submit" class="wdn-button wdn-button-brand">Send</button>
</fieldset>
</form>
<script type="text/javascript" src="/js/lib/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
var files = 1;
require(['jquery'], function ($) {
$(document).ready(function () {
$('#specific-user').change(function (change) {
$('#send-to-specific-user').attr('checked', true);
});
$('#add-file').click(function (click) {
click.preventDefault();
$input_div = $('#file-container').clone();
$input_div.removeAttr('id');
$input_div.find('.file-input').attr('name', 'file_' + ++files);
$input_div.find('.remove-file').show();
$('#files').append($input_div);
});
$('#files').on('click', '.remove-file', function (click) {
click.preventDefault();
$(this).closest('.file-container').remove();
});
});
});
</script>
\ No newline at end of file
......@@ -2,6 +2,7 @@
<li><a href="/" title="UNL Resource Scheduler">Home</a></li>
<% unless @space.nil? %>
<li><a href="<%= @space.calendar_href %>">Calendar</a></li>
<li><a href="<%= @space.resources_href %>">Resources</a></li>
<% unless @user.nil? || !@user.is_admin?(@space) %>
<li><a href="<%= @space.admin_href %>" title="Admin">Admin</a>
<ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment