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

Events and Resources

parent c37ee1d0
Branches
Tags
No related merge requests found
Showing
with 1237 additions and 79 deletions
...@@ -10,6 +10,7 @@ gem 'bcrypt' ...@@ -10,6 +10,7 @@ gem 'bcrypt'
gem 'unicorn' gem 'unicorn'
gem 'pony' gem 'pony'
gem 'rest-client' gem 'rest-client'
gem 'rack-cas'
group :development do group :development do
gem 'shotgun' gem 'shotgun'
......
...@@ -14,6 +14,7 @@ GEM ...@@ -14,6 +14,7 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.3) arel (6.0.3)
backports (3.6.8) backports (3.6.8)
bcrypt (3.1.11) bcrypt (3.1.11)
...@@ -57,14 +58,19 @@ GEM ...@@ -57,14 +58,19 @@ GEM
mime-types (>= 1.16, < 4) mime-types (>= 1.16, < 4)
method_source (0.8.2) method_source (0.8.2)
mime-types (2.99.2) mime-types (2.99.2)
mini_portile2 (2.1.0)
minitest (5.9.0) minitest (5.9.0)
multi_json (1.12.1) multi_json (1.12.1)
mysql (2.9.1) mysql (2.9.1)
nenv (0.3.0) nenv (0.3.0)
netrc (0.11.0) netrc (0.11.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.1.0) notiffany (0.1.0)
nenv (~> 0.1) nenv (~> 0.1)
shellany (~> 0.0) shellany (~> 0.0)
pkg-config (1.1.7)
pony (1.11) pony (1.11)
mail (>= 2.0) mail (>= 2.0)
pry (0.10.3) pry (0.10.3)
...@@ -72,6 +78,10 @@ GEM ...@@ -72,6 +78,10 @@ GEM
method_source (~> 0.8.1) method_source (~> 0.8.1)
slop (~> 3.4) slop (~> 3.4)
rack (1.6.4) rack (1.6.4)
rack-cas (0.13.0)
addressable (~> 2.3)
nokogiri (~> 1.5)
rack (~> 1.3)
rack-protection (1.5.3) rack-protection (1.5.3)
rack rack
rack-test (0.6.3) rack-test (0.6.3)
...@@ -130,6 +140,7 @@ DEPENDENCIES ...@@ -130,6 +140,7 @@ DEPENDENCIES
guard-less guard-less
mysql mysql
pony pony
rack-cas
rest-client rest-client
shotgun shotgun
sinatra sinatra
......
require 'sinatra' require 'sinatra'
require 'rest-client'
require 'rack/session/abstract/id'
require 'rack/cas'
require 'rack-cas'
require 'rack-cas/session_store/active_record'
require 'models/user' require 'models/user'
require 'models/service_space' require 'models/service_space'
use Rack::Session::Cookie, :key => 'rack.session', module Rack
:path => '/', module Session
:domain => (ENV['RACK_ENV'] == 'development' ? nil : 'resource.unl.edu'), class RackCASActiveRecordStore < Rack::Session::Abstract::ID
:secret => '420terrace12qmemorialpinnaclehawks', include RackCAS::ActiveRecordStore
:old_secret => '420terrace12qmemorialpinnaclehawks' end
end
end
use Rack::Session::RackCASActiveRecordStore
use Rack::CAS, server_url: 'https://login.unl.edu/cas',
session_store: RackCAS::ActiveRecordStore
Time.zone = "America/Chicago" Time.zone = "America/Chicago"
DIRECTORY_URL = 'http://directory.unl.edu/'
# this gives the user messages # this gives the user messages
def flash(type, header, message) def flash(type, header, message)
session["notice"] ||= [] session["notice"] ||= []
...@@ -21,6 +34,8 @@ def flash(type, header, message) ...@@ -21,6 +34,8 @@ def flash(type, header, message)
end end
before do before do
require_login
# site defaults # site defaults
@title = 'UNL Resource Scheduler' @title = 'UNL Resource Scheduler'
@breadcrumbs = [ @breadcrumbs = [
...@@ -34,15 +49,20 @@ before do ...@@ -34,15 +49,20 @@ before do
:text => 'UNL Resource Scheduler' :text => 'UNL Resource Scheduler'
} }
] ]
end
session[:init] = true def calculate_time(date_string, hour, minute, am_pm)
hour ||= 0
minute ||= 0
am_pm ||= 'am'
# check if the user is currently logged in hour = hour.to_i % 12
if session.has_key?(:user_id) hour = hour + 12 if am_pm == 'pm'
@user = (User.includes(:permissions).find(session[:user_id]) rescue nil)
else date_strings = date_string.split('/')
@user = nil; date_string = "#{date_strings[2]}-#{date_strings[0]}-#{date_strings[1]}"
end date = Time.parse(date_string)
Time.new(date.year, date.month, date.day, hour, minute, 0)
end end
helpers do helpers do
...@@ -51,12 +71,43 @@ helpers do ...@@ -51,12 +71,43 @@ helpers do
space = ServiceSpace.find_by(:url_name => url_name) space = ServiceSpace.find_by(:url_name => url_name)
raise Sinatra::NotFound if space.nil? raise Sinatra::NotFound if space.nil?
@space = space @space = space
if !@user.in_space(@space)
flash :error, 'Unauthorized', 'Sorry, you don\'t have access to this service space.'
redirect '/'
end
@breadcrumbs << {:text => @space.name, :href => @space.href}
end end
def require_login def require_login
if session['cas'].nil? || session['cas']['user'].nil?
halt 401
else
# check if the user already exists in this app's db
@user = User.find_by(:username => session['cas']['user'], :creation_method => 'CAS')
if @user.nil? if @user.nil?
flash(:alert, 'You Must Login', 'That page requires you to be logged in. If you don\'t have an account, please sign up for <a href="/new_members/">New&nbsp;Member&nbsp;Orientation</a>.') # get this user's info from UNL Directory
redirect '/login/' RestClient.get("#{DIRECTORY_URL}?uid=#{session['cas']['user']}&format=json") do |response, request, result|
case response.code
when 200
info = JSON.parse(response.body)
# create this user
@user = User.create(
username: session['cas']['user'],
email: info['mail'][0],
first_name: info['givenName'][0],
last_name: info['sn'][0],
date_created: Time.now,
creation_method: 'CAS',
is_admin: false
)
else
flash :error, 'User Not Found in UNL Directory', "This user was not found in the UNL Directory."
redirect back
end
end
end
end end
end end
end end
...@@ -74,7 +125,20 @@ end ...@@ -74,7 +125,20 @@ end
get '/' do get '/' do
@breadcrumbs << {:text => 'Home'} @breadcrumbs << {:text => 'Home'}
erb 'Home', :layout => :fixed # get the service spaces that this user has access to
spaces = @user.service_spaces
erb :home, :layout => :fixed, :locals => {
spaces: spaces
}
end
get '/images/:event_id/?' do
event = Event.find_by(:id => params[:event_id])
if event.nil? || event.imagedata.nil?
raise Sinatra::NotFound
end
return event.imagedata
end end
Dir.glob("#{ROOT}/routes/*.rb") { |file| require file } Dir.glob("#{ROOT}/routes/*.rb") { |file| require file }
\ No newline at end of file
require 'active_record'
class AddSessionStore < ActiveRecord::Migration
def change
create_table :sessions do |t|
t.string :cas_ticket
t.string :session_id
t.text :data
t.datetime :created_at
t.datetime :updated_at
end
end
end
\ No newline at end of file
require 'active_record'
class AddCreationMethod < ActiveRecord::Migration
def change
add_column :users, :creation_method, :string
end
end
\ No newline at end of file
require 'active_record'
require 'models/permission'
class AddSpacePermissions < ActiveRecord::Migration
def up
Permission.create(:name => 'User Access', :id => 8)
add_column :user_has_permissions, :service_space_id, :integer, :default => 1
end
def down
remove_column :user_has_permissions, :service_space_id, :integer, :default => 1
Permission.find_by(:id => 8).delete
end
end
\ No newline at end of file
...@@ -5,6 +5,7 @@ class Event < ActiveRecord::Base ...@@ -5,6 +5,7 @@ class Event < ActiveRecord::Base
has_one :reservation, :dependent => :destroy has_one :reservation, :dependent => :destroy
belongs_to :location belongs_to :location
belongs_to :event_type belongs_to :event_type
belongs_to :service_space
alias_method :type, :event_type alias_method :type, :event_type
alias_method :signups, :event_signups alias_method :signups, :event_signups
...@@ -29,16 +30,11 @@ class Event < ActiveRecord::Base ...@@ -29,16 +30,11 @@ class Event < ActiveRecord::Base
end end
def info_link def info_link
case type.description "/#{service_space.url_name}/events/#{id}/"
when 'New Member Orientation'
"/new_members/sign_up/#{id}/"
else
"/events/#{id}/"
end
end end
def edit_link def edit_link
"/admin/events/#{id}/edit/" "/#{service_space.url_name}/admin/events/#{id}/edit/"
end end
def has_reservation def has_reservation
...@@ -57,7 +53,6 @@ class Event < ActiveRecord::Base ...@@ -57,7 +53,6 @@ class Event < ActiveRecord::Base
self.event_type_id = params[:type] self.event_type_id = params[:type]
self.location_id = params[:location] self.location_id = params[:location]
self.max_signups = params[:limit_signups] == 'on' ? params[:max_signups].to_i : nil self.max_signups = params[:limit_signups] == 'on' ? params[:max_signups].to_i : nil
self.service_space_id = 1
self.save self.save
end end
......
...@@ -8,4 +8,5 @@ class Permission < ActiveRecord::Base ...@@ -8,4 +8,5 @@ class Permission < ActiveRecord::Base
MANAGE_SPACE_HOURS = 5 MANAGE_SPACE_HOURS = 5
MANAGE_EVENTS = 6 MANAGE_EVENTS = 6
SEE_AGENDA = 7 SEE_AGENDA = 7
USER_ACCESS = 8
end end
\ No newline at end of file
require 'active_record' require 'active_record'
require 'models/resource'
class Reservation < ActiveRecord::Base class Reservation < ActiveRecord::Base
belongs_to :resource belongs_to :resource
......
require 'active_record' require 'active_record'
class ServiceSpace < ActiveRecord::Base class ServiceSpace < ActiveRecord::Base
has_many :users
def href
"/#{self.url_name}/"
end
def calendar_href
"/#{self.url_name}/calendar/"
end
def resources_href
"/#{self.url_name}/resources/"
end
def admin_href
"/#{self.url_name}/admin/"
end
def admin_events_href
"/#{self.url_name}/admin/events/"
end
end end
\ No newline at end of file
...@@ -4,13 +4,20 @@ require 'models/resource_authorization' ...@@ -4,13 +4,20 @@ require 'models/resource_authorization'
require 'models/event_signup' require 'models/event_signup'
require 'models/permission' require 'models/permission'
require 'models/user_has_permission' require 'models/user_has_permission'
require 'models/service_space'
require 'classes/emailer' require 'classes/emailer'
class User < ActiveRecord::Base class User < ActiveRecord::Base
has_many :resource_authorizations has_many :resource_authorizations
has_many :event_signups has_many :event_signups
has_many :user_has_permissions has_many :user_has_permissions
has_many :permissions, through: :user_has_permissions has_many :permissions, through: :user_has_permissions, source: :permission
def service_spaces
ServiceSpace.all.select do |space|
self.in_space(space)
end
end
def authorized_resource_ids def authorized_resource_ids
self.resource_authorizations.map {|res_auth| res_auth.resource_id} self.resource_authorizations.map {|res_auth| res_auth.resource_id}
...@@ -24,30 +31,24 @@ class User < ActiveRecord::Base ...@@ -24,30 +31,24 @@ class User < ActiveRecord::Base
self.event_signups.map {|event_signup| event_signup.event_id} self.event_signups.map {|event_signup| event_signup.event_id}
end end
include BCrypt # we decide if the user is an admin if they have any permissions in the space (besides the user access permission, which indicates they are a basic user)
def is_admin?(space)
# now decides based on whether they have any admin permissions !self.user_has_permissions.where(:service_space_id => space.id).where.not(:permission_id => Permission::USER_ACCESS).empty?
def is_admin?
!self.permissions.empty?
end end
alias_method :admin?, :is_admin? alias_method :admin?, :is_admin?
def is_super_user? def is_super_user?(space)
self.permissions.include?(Permission.find(Permission::SUPER_USER)) !self.user_has_permissions.where(:service_space_id => space.id, :permission_id => Permission::SUPER_USER).empty?
end end
alias_method :super_user?, :is_super_user? alias_method :super_user?, :is_super_user?
def has_permission?(id) def has_permission?(id, space)
self.permissions.include?(Permission.find(id)) !self.user_has_permissions.where(:service_space_id => space.id, :permission_id => id).empty?
end end
def password # just notes whether they have any permissions in the space, and can access it at all
@password ||= Password.new(password_hash) def in_space(space)
end !self.user_has_permissions.where(:service_space_id => space.id).empty?
def password=(new_password)
@password = Password.create(new_password)
self.password_hash = @password
end end
def full_name def full_name
...@@ -57,26 +58,4 @@ class User < ActiveRecord::Base ...@@ -57,26 +58,4 @@ class User < ActiveRecord::Base
def sortable_name def sortable_name
"#{last_name}, #{first_name}" "#{last_name}, #{first_name}"
end end
def send_reset_password_email
token = ''
begin
token = String.token
end while User.find_by(:reset_password_token => token) != nil
self.reset_password_token = token
self.reset_password_expiry = Time.now + 1.day
self.save
body = <<EMAIL
<p>We received a request to reset your Innovation Studio Manager password. Please click the link below to reset your password.</p>
<p><a href="http://#{ENV['RACK_ENV'] == 'development' ? 'localhost:9393' : 'innovationstudio-manager.unl.edu'}/reset_password/#{token}/">http://#{ENV['RACK_ENV'] == 'development' ? 'localhost:9393' : 'innovationstudio-manager.unl.edu'}/reset_password/#{token}/</a></p>
<p>This link will only be active for 24 hours. If you did not request to reset your password, you may safely disregard this email.</p>
<p>Nebraska Innovation Studio</p>
EMAIL
Emailer.mail(self.email, 'Nebraska Innovation Studio password reset', body)
end
end end
\ No newline at end of file
...@@ -3,4 +3,9 @@ require 'active_record' ...@@ -3,4 +3,9 @@ require 'active_record'
class UserHasPermission < ActiveRecord::Base class UserHasPermission < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :permission belongs_to :permission
belongs_to :service_space
scope :in_space, ->(space) {
where(:service_space_id => space.id)
}
end end
\ No newline at end of file
require 'models/user'
require 'models/event'
require 'models/resource'
require 'models/space_hour'
require 'models/permission'
before '/:service_space_url_name/admin*' do
load_service_space
raise Sinatra::NotFound unless !@user.nil? && @user.is_admin?(@space)
end
get '/:service_space_url_name/admin/?' do
@breadcrumbs << {:text => 'Admin Home'}
user_count = User.where(:service_space_id => @space.id).count
upcoming_event_count = Event.where(:service_space_id => @space.id).where('start_time >= ?', Time.now).count
resource_count = Resource.where(:service_space_id => @space.id).count
date = Time.now.midnight
# get the hours for this day to show
hours = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:effective_date => :desc, :id => :desc).all.to_a
correct_hour = nil
hours.each do |space_hour|
if date.wday == space_hour.day_of_week && (space_hour.effective_date.in_time_zone.midnight == date.in_time_zone.midnight || (!space_hour.one_off && space_hour.effective_date.in_time_zone.midnight <= date.in_time_zone.midnight))
correct_hour = space_hour
break
end
end
erb :'admin/home', :layout => :fixed, :locals => {
:user_count => user_count,
:upcoming_event_count => upcoming_event_count,
:resource_count => resource_count,
:space_hour => correct_hour,
:date => date
}
end
Dir.glob("#{ROOT}/routes/admin/*.rb") { |file| require file }
\ No newline at end of file
require 'rest-client'
require 'models/event'
require 'models/event_type'
require 'models/location'
require 'models/resource'
before '/:service_space_url_name/admin/events*' do
unless @user.has_permission?(Permission::MANAGE_EVENTS, @space)
raise Sinatra::NotFound
end
end
get '/:service_space_url_name/admin/events/?' do
@breadcrumbs << {:text => 'Admin Events'}
page = params[:page]
page = page.to_i >= 1 ? page.to_i : 1
page_size = 10
tab = ['upcoming', 'past'].include?(params[:tab]) ? params[:tab] : 'upcoming'
case tab
when 'past'
where_clause = 'start_time < ?', Time.now
order_clause = {:start_time => :desc}
else
where_clause = 'start_time >= ?', Time.now
order_clause = {:start_time => :asc}
end
iterator = Event.includes(:event_signups).where(:service_space_id => @space.id).where(where_clause)
erb :'admin/events', :layout => :fixed, :locals => {
:events => iterator.order(order_clause).limit(page_size).offset((page-1)*page_size).all,
:total_pages => (iterator.count.to_f / page_size).ceil,
:page => page,
:tab => tab
}
end
get '/:service_space_url_name/admin/events/:event_id/signup_list/?' do
@breadcrumbs << {:text => 'Admin Events', :href => '/admin/events/'} << {text: 'Signup List'}
event = Event.includes(:event_signups).find_by(:id => params[:event_id], :service_space_id => @space.id)
if event.nil?
# that event does not exist
flash(:danger, 'Not Found', 'That event does not exist')
redirect @space.admin_events_href
end
erb :'admin/signup_list', :layout => :fixed, :locals => {
:event => event
}
end
get '/:service_space_url_name/admin/events/create/?' do
@breadcrumbs << {:text => 'Admin Events', :href => '/admin/events/'} << {text: 'Create Event'}
erb :'admin/new_event', :layout => :fixed, :locals => {
:event => Event.new,
:types => EventType.where(:service_space_id => @space.id).all,
:locations => Location.where(:service_space_id => @space.id).all,
:resources => Resource.where(:service_space_id => @space.id, :is_reservable => true).all,
:on_unl_events => false,
:on_main_calendar => false
}
end
post '/:service_space_url_name/admin/events/create/?' do
if params[:location] == 'new'
# this is a new location, we must create it!
location = Location.create(params[:new_location].merge({
:service_space_id => @space.id
}))
params[:location] = location.id
end
event = Event.new
event.set_image_data(params)
event.set_data(params)
event.service_space_id = @space.id
if params.has_key?('reserve_resource') && params['reserve_resource'] == 'on'
# we need to create a reservation for the resource on the appropriate time
Reservation.create(
:resource_id => params[:resource],
:event_id => event.id,
:start_time => event.start_time,
:end_time => event.end_time,
:is_training => true,
:user_id => nil
)
end
# notify that it worked
flash(:success, 'Event Created', "Your #{event.type.description}: #{event.title} has been created.")
redirect @space.admin_events_href
end
get '/:service_space_url_name/admin/events/:event_id/edit/?' do
@breadcrumbs << {:text => 'Admin Events', :href => '/admin/events/'} << {text: 'Edit Event'}
event = Event.includes(:event_type, :location, :reservation => :resource).find_by(:id => params[:event_id], :service_space_id => @space.id)
if event.nil?
# that event does not exist
flash(:danger, 'Not Found', 'That event does not exist')
redirect @space.admin_events_href
end
erb :'admin/new_event', :layout => :fixed, :locals => {
:event => event,
:types => EventType.where(:service_space_id => @space.id).all,
:locations => Location.where(:service_space_id => @space.id).all,
:resources => Resource.where(:service_space_id => @space.id, :is_reservable => true).all
}
end
post '/:service_space_url_name/admin/events/:event_id/edit/?' do
event = Event.find_by(:id => params[:event_id], :service_space_id => @space.id)
if event.nil?
# that event does not exist
flash(:danger, 'Not Found', 'That event does not exist')
redirect @space.admin_events_href
end
if params[:location] == 'new'
# this is a new location, we must create it!
location = Location.create(params[:new_location].merge({
:service_space_id => @space.id
}))
params[:location] = location.id
end
if params.checked?('remove_image')
event.remove_image_data
else
event.set_image_data(params)
end
event.set_data(params)
event.service_space_id = @space.id
# check the resource reservation for this
checked = params.checked?('reserve_resource')
if event.has_reservation && checked
# update the reservation
event.reservation.update(
:resource_id => params[:resource],
:event_id => event.id,
:start_time => event.start_time,
:end_time => event.end_time,
:is_training => true,
:user_id => nil
)
elsif event.has_reservation && !checked
# remove the reservation
event.reservation.delete
elsif !event.has_reservation && checked
# create the reservation
Reservation.create(
:resource_id => params[:resource],
:event_id => event.id,
:start_time => event.start_time,
:end_time => event.end_time,
:is_training => true,
:user_id => nil
)
end
# notify that it worked
flash(:success, 'Event Updated', "Your #{event.type.description}: #{event.title} has been updated.")
redirect @space.admin_events_href
end
post '/:service_space_url_name/admin/events/:event_id/delete/?' do
event = Event.find_by(:id => params[:event_id], :service_space_id => @space.id)
if event.nil?
# that event does not exist
flash(:danger, 'Not Found', 'That event does not exist')
redirect @space.admin_events_href
end
event.destroy
flash(:success, 'Event Deleted', "Your event #{event.title} has been deleted. All signups on this event have also been removed, and if a reservation was attached, it also has been removed.")
redirect @space.admin_events_href
end
\ No newline at end of file
require 'models/event'
require 'models/event_signup'
get '/:service_space_url_name/events/:event_id/?' do
load_service_space
# this is an event details page
begin
event = Event.includes(:location, :event_type, :event_signups).find(params[:event_id])
rescue ActiveRecord::RecordNotFound => e
not_found
end
@breadcrumbs << {:text => event.title}
erb :event_details, :layout => :fixed, :locals => {
:event => event
}
end
post '/:service_space_url_name/events/:event_id/sign_up/?' do
load_service_space
# check that is a valid event
event = Event.includes(:event_type).find_by(:service_space_id => @space.id, :id => params[:event_id])
if event.nil?
# that event does not exist
flash(:danger, 'Not Found', 'That event does not exist')
redirect '/calendar/'
end
if !event.max_signups.nil? && event.signups.count >= event.max_signups
# that event is full
flash(:danger, 'Event Full', 'Sorry, that event is full.')
redirect back
end
EventSignup.create(
:event_id => params[:event_id],
:name => @user.full_name,
:user_id => @user.id,
:email => @user.email
)
if event.type.description != 'Free Event'
# flash a message that this works
flash(:success, "You're signed up!", "Thanks for signing up! Don't forget, #{event.title} is #{event.start_time.in_time_zone.strftime('%A, %B %d at %l:%M %P')}.")
redirect back
else
# flash a message that this works
flash(:success, "Event Marked", "This free event has been marked on your hoempage.")
redirect back
end
end
post '/:service_space_url_name/events/:event_id/remove_signup/?' do
load_service_space
# get the event
event = Event.includes(:event_type).where(:id => params[:event_id]).first
# check that the signup exists
signup = EventSignup.where(:event_id => params[:event_id], :user_id => @user.id).first
if signup.nil?
flash :alert, 'Not Found', 'That signup was not found.'
redirect '/home/'
end
signup.delete
header = event.type.description == 'Free Event' ? 'Event Removed' : 'Signup Removed'
message = event.type.description == 'Free Event' ? "#{event.title} has been removed from your calendar." : "Your signup for #{event.title} has been removed."
flash :success, header, message
redirect '/home/'
end
\ No newline at end of file
require 'models/resource'
require 'models/reservation'
require 'models/event'
require 'models/event_type'
require 'models/event_signup'
require 'models/space_hour'
get '/:service_space_url_name/resources/?' do
load_service_space
@breadcrumbs << {:text => 'Resources'}
# show resources that the user is authorized to use, as well as all those that do not require authorization
resources = Resource.where(:service_space_id => @space.id).all.to_a
resources.reject! {|resource| resource.needs_authorization && !@user.authorized_resource_ids.include?(resource.id)}
erb :resources, :layout => :fixed, :locals => {
:available_resources => resources
}
end
# form for reserving a resource
get '/:service_space_url_name/resources/:resource_id/reserve/?' do
load_service_space
@breadcrumbs << {:text => 'Resources', :href => @space.resources_href} << {:text => 'Reserve'}
# check that the user has authorization to reserve this resource, if resource requires auth
resource = Resource.find_by(:service_space_id => @space.id, :id => params[:resource_id])
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.resources_href
end
date = params[:date].nil? ? Time.now.midnight.in_time_zone : Time.parse(params[:date]).midnight.in_time_zone
# get the studio's hours for this day
# is there a one_off
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
available_start_times = []
# calculate the available start times for reservation
if space_hour.nil?
start = 0
while start + (resource.minutes_per_reservation || 15) <= 1440
available_start_times << start
start += (resource.minutes_per_reservation || 15)
end
else
space_hour.hours.sort{|x,y| x[:start] <=> y[:start]}.each do |record|
if record[:status] == 'open'
start = record[:start]
while start + (resource.minutes_per_reservation || 15) <= record[:end]
available_start_times << start
start += (resource.minutes_per_reservation || 15)
end
end
end
end
# filter out times when resource is reserved
reservations = Reservation.includes(:event).where(:resource_id => resource.id).in_day(date).all
available_start_times = available_start_times - reservations.map{|res|res.start_time.in_time_zone.minutes_after_midnight}
erb :reserve, :layout => :fixed, :locals => {
:resource => resource,
:reservations => reservations,
:available_start_times => available_start_times,
:space_hour => space_hour,
:day => date,
:reservation => nil
}
end
# submit form for reserving a resource
post '/:service_space_url_name/resources/:resource_id/reserve/?' do
load_service_space
resource = Resource.find_by(:service_space_id => @space.id, :id => params[:resource_id])
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.resources_href
end
if params[:start_minutes].nil?
flash(:alert, 'Please specify a start time', 'Please specify a start time for your reservation.')
redirect back
end
hour = (params[:start_minutes].to_i / 60).floor
am_pm = hour >= 12 ? 'pm' : 'am'
hour = hour % 12
hour += 12 if hour == 0
minutes = params[:start_minutes].to_i % 60
start_time = calculate_time(params[:date], hour, minutes, am_pm)
end_time = start_time + params[:length].to_i.minutes
date = start_time.midnight
# validate that the requested time slot falls within the open hours of the day
# get the studio's hours for this day
# is there a one_off
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
unless space_hour.nil?
# figure out where the closed sections need to be
# we can assume that all records in this space_hour are non-intertwined
closed_start = 0
closed_end = 0
starts = space_hour.hours.map{|record| record[:start]}
ends = space_hour.hours.map{|record| record[:end]}
closeds = []
(0..1439).each do |j|
if starts.include?(j)
closed_end = j
closeds << {:status => 'closed', :start => closed_start, :end => closed_end}
closed_start = 0
closed_end = 0
end
if ends.include?(j)
closed_start = j
end
end
closed_end = 1440
closeds << {:status => 'closed', :start => closed_start, :end => closed_end}
# for each record, ensure that the time does not overlap if the record is not "open"
(space_hour.hours + closeds).each do |record|
if record[:status] != 'open'
start_time_minutes = 60 * start_time.hour + start_time.min
end_time_minutes = 60 * end_time.hour + end_time.min
if (record[:start]+1..record[:end]-1).include?(start_time_minutes) || (record[:start]+1..record[:end]-1).include?(end_time_minutes) ||
(start_time_minutes < record[:start] && end_time_minutes > record[:end])
# there is an overlap, this time is invalid
flash :alert, 'Invalid Time Slot', 'Sorry, that time slot is invalid for reservations.'
redirect back
end
end
end
end
# if no record studio is open
# check for possible other reservations during this time period
other_reservations = Reservation.where(:resource_id => params[:resource_id]).in_day(date).all
other_reservations.each do |reservation|
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."
redirect back
end
end
Reservation.create(
:resource_id => resource.id,
:event_id => nil,
:start_time => start_time,
:end_time => end_time,
:is_training => false,
:user_id => @user.id
)
flash(:success, 'Reservation Created', "You have successfully reserved #{resource.name} for #{params[:length]} minutes at #{start_time.in_time_zone.strftime('%A, %B %d at %l:%M %P')}")
redirect @space.resources_href
end
get '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservation_id/?' do
load_service_space
@breadcrumbs << {:text => 'Resources', :href => @space.resources_href} << {:text => 'Edit Reservation'}
resource = Resource.find_by(:service_space_id => @space.id, :id => params[:resource_id])
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.resources_href
end
# check that this reservation exists
reservation = Reservation.find(params[:reservation_id])
if reservation.nil?
flash(:alert, 'Not Found', 'That reservation does not exist.')
redirect back
end
date = params[:date].nil? ? reservation.start_time.in_time_zone.midnight : Time.parse(params[:date]).midnight.in_time_zone
# get the studio's hours for this day
# is there a one_off
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
available_start_times = []
# calculate the available start times for reservation
if space_hour.nil?
start = 0
while start + (resource.minutes_per_reservation || 15) <= 1440
available_start_times << start
start += (resource.minutes_per_reservation || 15)
end
else
space_hour.hours.sort{|x,y| x[:start] <=> y[:start]}.each do |record|
if record[:status] == 'open'
start = record[:start]
while start + (resource.minutes_per_reservation || 15) <= record[:end]
available_start_times << start
start += (resource.minutes_per_reservation || 15)
end
end
end
end
# filter out times when resource is reserved
reservations = Reservation.includes(:event).where(:resource_id => resource.id).in_day(date).all
available_start_times = (available_start_times - reservations.map{|res|res.start_time.in_time_zone.minutes_after_midnight})
if date == reservation.start_time.in_time_zone.midnight
available_start_times = available_start_times + [reservation.start_time.in_time_zone.minutes_after_midnight]
end
available_start_times.sort!
erb :reserve, :layout => :fixed, :locals => {
:resource => resource,
:reservations => reservations,
:available_start_times => available_start_times,
:space_hour => space_hour,
:day => date,
:reservation => reservation
}
end
post '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservation_id/?' do
load_service_space
resource = Resource.find_by(:service_space_id => @space.id, :id => params[:resource_id])
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.resources_href
end
# check that this reservation exists
reservation = Reservation.find(params[:reservation_id])
if reservation.nil?
flash(:alert, 'Not Found', 'That reservation does not exist.')
redirect back
end
hour = (params[:start_minutes].to_i / 60).floor
am_pm = hour >= 12 ? 'pm' : 'am'
hour = hour % 12
hour += 12 if hour == 0
minutes = params[:start_minutes].to_i % 60
start_time = calculate_time(params[:date], hour, minutes, am_pm)
end_time = start_time + params[:length].to_i.minutes
date = start_time.midnight
# validate that the requested time slot falls within the open hours of the day
# get the studio's hours for this day
# is there a one_off
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
unless space_hour.nil?
# figure out where the closed sections need to be
# we can assume that all records in this space_hour are non-intertwined
closed_start = 0
closed_end = 0
starts = space_hour.hours.map{|record| record[:start]}
ends = space_hour.hours.map{|record| record[:end]}
closeds = []
(0..1439).each do |j|
if starts.include?(j)
closed_end = j
closeds << {:status => 'closed', :start => closed_start, :end => closed_end}
closed_start = 0
closed_end = 0
end
if ends.include?(j)
closed_start = j
end
end
closed_end = 1440
closeds << {:status => 'closed', :start => closed_start, :end => closed_end}
# for each record, ensure that the time does not overlap if the record is not "open"
(space_hour.hours + closeds).each do |record|
if record[:status] != 'open'
start_time_minutes = 60 * start_time.hour + start_time.min
end_time_minutes = 60 * end_time.hour + end_time.min
if (record[:start]+1..record[:end]-1).include?(start_time_minutes) || (record[:start]+1..record[:end]-1).include?(end_time_minutes) ||
(start_time_minutes < record[:start] && end_time_minutes > record[:end])
# there is an overlap, this time is invalid
flash :alert, 'Invalid Time Slot', 'Sorry, that time slot is invalid for reservations.'
redirect back
end
end
end
end
# if no record studio is open
# check for possible other reservations during this time period
other_reservations = Reservation.where(:resource_id => params[:resource_id]).where.not(:id => reservation.id).in_day(date).all
other_reservations.each do |reservation|
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."
redirect back
end
end
reservation.update(
:start_time => start_time,
:end_time => end_time
)
flash(:success, 'Reservation Updated', "You have successfully updated your reservation for #{resource.name}: it is now for #{params[:length]} minutes at #{start_time.in_time_zone.strftime('%A, %B %d at %l:%M %P')}")
redirect back
end
post '/:service_space_url_name/resources/:resource_id/cancel/:reservation_id/?' do
load_service_space
# check that the user requesting cancel is the same as the one on the reservation
reservation = Reservation.find(params[:reservation_id])
if reservation.nil?
flash :alert, 'Not Found', 'That reservation was not found.'
redirect back
end
if reservation.user_id != @user.id
flash :alert, 'Unauthorized', 'That is not your reservation.'
redirect back
end
reservation.delete
flash :success, 'Reservation Cancelled', 'Your reservation has been removed.'
redirect back
end
require 'models/service_space'
require 'models/reservation'
require 'models/event'
get '/:service_space_url_name/?' do
load_service_space
reservations = Reservation.joins(:resource).includes(:event).
where(:resources => {:service_space_id => @space.id}).
where(:user_id => @user.id).
where('end_time >= ?', Time.now).
order(:start_time).all
events = Event.includes(:event_type).joins(:event_signups).
where(:event_signups => {:user_id => @user.id}, :service_space_id => @space.id).
where('end_time >= ?', Time.now).
order(:start_time).all
erb :space_home, :layout => :fixed, :locals => {
:reservations => reservations,
:events => events
}
end
\ No newline at end of file
<section class="wdn-grid-set reverse">
<div class="bp2-wdn-col-three-fourths">
<div id="pagetitle">
<h3>Events</h3>
</div>
<ul class="wdn_tabs">
<li class="<%='selected' if tab == 'upcoming' %>"><a href="?tab=upcoming">Upcoming</a></li>
<li class="<%='selected' if tab == 'past' %>"><a href="?tab=past">Past</a></li>
</ul>
<div class="wdn_tabs_content">
<div class="event-page">
<table class="event-list">
<thead>
<tr>
<th>Title</th>
<th>Date/Location</th>
<th>Signups</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% events.each do |event| %>
<tr>
<td class="small-hidden">
<a href="<%= @space.admin_events_href %><%= event.id %>/edit/"><%= event.title %></a>
</td>
<td>
<ul>
<li>
<%= event.start_time.in_time_zone.strftime('%m/%d/%Y @ %l:%M %P') %><br>
<%= event.location.name %>
</li>
</ul>
</td>
<td>
<a href="<%= @space.admin_events_href %><%= event.id %>/signup_list/"><%= event.signups.count %> signed up</a>
<% unless event.max_signups.nil? %>
<br><%= event.max_signups %> total slots
<% end %>
</td>
<td>
<form class="delete-event delete-form" action="<%= @space.admin_events_href %><%=event.id%>/delete/" method="POST">
<button type="submit" class="wdn-button">Delete</button>
</form>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% if total_pages > 1 %>
<script type="text/javascript">
WDN.loadCSS(WDN.getTemplateFilePath('css/modules/pagination.css'));
</script>
<div style="text-align: center;">
<div style="display: inline-block;">
<ul id="pending-pagination" class="wdn_pagination" data-tab="pending" style="padding-left: 0;">
<% if page != 1 %>
<li class="arrow prev"><a href="?tab=<%= tab %>&amp;page=<%= page-1 %>" title="Go to the previous page">← prev</a></li>
<% end %>
<% before_ellipsis_shown = false; after_ellipsis_shown = false %>
<% (1..total_pages).each do |i| %>
<% if i == page %>
<li class="selected"><span><%= i %></span></li>
<% elsif (i <= 3 || i >= total_pages - 2 || i == page - 1 ||
i == page - 2 || i == page + 1 || $i == page + 2) %>
<li><a href="?tab=<%= tab %>&amp;page=<%= i %>" title="Go to page <%= i %>"><%= i %></a></li>
<% elsif (i < page && !before_ellipsis_shown) %>
<li><span class="ellipsis">...</span></li>
<% before_ellipsis_shown = true %>
<% elsif (i > page && !after_ellipsis_shown) %>
<li><span class="ellipsis">...</span></li>
<% after_ellipsis_shown = true %>
<% end %>
<% end %>
<% if page != total_pages %>
<li class="arrow next"><a href="?tab=<%= tab %>&amp;page=<%= page+1 %>" title="Go to the next page">next →</a></li>
<% end %>
</ul>
</div>
</div>
<% end %>
</div>
</div>
<nav class="bp2-wdn-col-one-fourth">
<div class="toolbox">
<h3>Toolbox</h3>
<div class="tools">
<div style="text-align: center; margin-bottom: .8em">
<a class="wdn-button wdn-button-brand" href="<%= @space.admin_events_href %>create/">
<span style="font-size: 2em; vertical-align: middle; font-weight: 600">+</span>
<span style="vertical-align: middle;">New Event</span>
</a>
</div>
</div>
</div>
</nav>
</section>
<script type="text/javascript">
require(['jquery'], function($) {
$(document).ready(function() {
$('.delete-event').submit(function (submit) {
if (!window.confirm('Are you sure you want to delete this event?')) {
submit.preventDefault();
}
});
});
});
</script>
\ No newline at end of file
<div id="pagetitle">
<h3>NIS Manager Administration</h3>
<span class="wdn-subhead">Hello, <%= @user.full_name %> (<%= @user.username %>) <% if @user.is_super_user?(@space) %><br>Super User<% end %></span>
</div>
<table>
<tbody>
<% if @user.has_permission?(Permission::MANAGE_USERS, @space) || @user.has_permission?(Permission::SUPER_USER, @space) %>
<tr>
<td><strong>Users</strong></td>
<td><%= user_count %> users</td>
<td><a class="wdn-button wdn-button-brand" href="/admin/users/">Manage</a></td>
</tr>
<% end %>
<% if @user.has_permission?(Permission::MANAGE_EVENTS, @space) %>
<tr>
<td><strong>Events</strong></td>
<td><%= upcoming_event_count %> upcoming events</td>
<td><a class="wdn-button wdn-button-brand" href="<%= @space.admin_events_href %>">Manage</a></td>
</tr>
<% end %>
<% if @user.has_permission?(Permission::MANAGE_RESOURCES, @space) %>
<tr>
<td><strong>Resources</strong></td>
<td><%= resource_count %> resources</td>
<td><a class="wdn-button wdn-button-brand" href="/admin/tools/">Manage</a></td>
</tr>
<% end %>
<% if @user.has_permission?(Permission::MANAGE_SPACE_HOURS, @space) %>
<tr>
<td><strong>Hours</strong></td>
<td>Today:
<% unless space_hour.nil? %>
<%= space_hour.hours.map do |record|
start_time = date + record[:start].minutes
end_time = date + record[:end].minutes
"#{record[:status].capitalize_all}: #{start_time.in_time_zone.strftime('%l:%M %P')} - #{end_time.in_time_zone.strftime('%l:%M %P')}"
end.join(', ') %>
<% else %>
The space is open all day.
<% end %>
</td>
<td><a class="wdn-button wdn-button-brand" href="/admin/hours/">Manage</a></td>
</tr>
<% end %>
<% if @user.has_permission?(Permission::MANAGE_EMAILS, @space) %>
<tr>
<td><strong>Emails</strong></td>
<td></td>
<td><a class="wdn-button wdn-button-brand" href="/admin/emails/">Manage</a></td>
</tr>
<% end %>
<% if @user.has_permission?(Permission::SEE_AGENDA, @space) %>
<tr>
<td><strong>Agenda</strong></td>
<td></td>
<td><a class="wdn-button wdn-button-brand" href="/admin/agenda/">View</a></td>
</tr>
<% end %>
</tbody>
</table>
<div class="wdn-grid-set">
<form id="create-event-form" action="" method="POST" enctype="multipart/form-data">
<div class="bp3-wdn-col-two-thirds">
<fieldset>
<legend style="margin-top: 0">Event Details</legend>
<label for="title"><span class="required">*</span> Title</label>
<input type="text" id="title" name="title" value="<%= event.title %>"/>
<label for="description">Description</label>
<textarea rows="4" id="description" name="description"><%= event.description %></textarea>
<label for="type">Type</label>
<select id="type" name="type" class="use-select2" style="width: 100%;">
<% types.each do |type| %>
<option <%= 'selected="selected"' if !event.type.nil? && event.type.id == type.id %> value="<%= type.id %>"><%= type.description %></option>
<% end %>
</select>
<br><br>
<div>
<input type="checkbox" <%= 'checked="checked"' unless event.max_signups.nil? %> id="limit-signups" name="limit_signups"><label for="limit-signups">Limit signups for this event to: </label>
<input value="<%= event.max_signups %>" type="number" id="max-signups" name="max_signups" style="width: 100px;" />
</div>
</fieldset>
<fieldset>
<legend style="font-size: 1.6em">Location, Date, and Time</legend>
<label for="location"><span class="required">*</span> Location</label>
<select id="location" name="location" class="use-select2" style="width: 100%;">
<% locations.each do |location| %>
<option <%= 'selected="selected"' if !event.location.nil? && event.location.id == location.id %> value="<%= location.id %>"><%= location.name %></option>
<% end %>
<option value="new">-- New Location --</option>
</select>
<div style="display: none;" class="offset-field-group" id="new-location-details">
<label for="location-name"><span class="required">*</span> Name</label>
<input type="text" id="location-name" name="new_location[name]" />
<label for="location-address">Address</label>
<input type="text" id="location-address" name="new_location[streetaddress]" />
<label for="location-address2">Address 2</label>
<input type="text" id="location-address2" name="new_location[streetaddress2]" />
<label for="location-city">City</label>
<input type="text" id="location-city" name="new_location[city]" />
<label for="location-state">State</label>
<input type="text" id="location-state" name="new_location[state]" />
<label for="location-zip">Zip</label>
<input type="text" id="location-zip" name="new_location[zip]" />
<label for="location-additionalinfo">Additional Info</label>
<input type="text" id="location-additionalinfo" name="new_location[additionalinfo]" />
<label>* This location will be saved for future use</label>
</div>
<div>
<input type="checkbox" <%= 'checked="checked"' if !event.reservation.nil? && !event.reservation.resource.nil? %> id="reserve-resource" name="reserve_resource"><label for="reserve-resource">Reserve a resource for this event</label>
<div id="resources-for-reserving" style="<%= 'display: none;' if event.reservation.nil? || event.reservation.resource.nil? %>">
<label for="resource">Resource</label>
<select id="resource" name="resource" class="use-select2" style="width: 100%;">
<% resources.each do |resource| %>
<option <%= 'selected="selected"' if !event.reservation.nil? && !event.reservation.resource.nil? && event.reservation.resource.id == resource.id %> value="<%= resource.id %>"><%= "#{resource.name} - #{resource.model}" %></option>
<% end %>
</select>
</div>
</div>
<br>
<label for="start-date" ><span class="required">*</span> Start Date &amp; Time</label>
<div class="date-time-select"><span class="wdn-icon-calendar"></span>
<input id="start-date" value="<%= event.start_time.in_time_zone.strftime('%m/%d/%Y') if !event.start_time.nil? %>" name="start_date" title="Start Date" type="text" class="datepicker" /><br class="hidden small-block"> @
<select id="start-time-hour" name="start_time_hour" title="Start Time Hour">
<option value=""></option>
<% (1..12).each do |i| %>
<option <%= 'selected="selected"' if !event.start_time.nil? && event.start_time.in_time_zone.hour.to_i % 12 == i % 12 %> value="<%= i %>"><%= i %></option>
<% end %>
</select> :
<select id="start-time-minute" name="start_time_minute" title="Start Time Minute">
<option value=""></option>
<% (0..11).each do |i| %>
<option <%= 'selected="selected"' if !event.start_time.nil? && event.start_time.in_time_zone.min == i*5 %> value="<%= i * 5 %>"><%= (i*5).to_s.rjust(2, '0') %></option>
<% end %>
</select>
<div id="start-time-am-pm" class="am_pm">
<input <%= 'checked="checked"' if event.start_time.nil? || event.start_time.in_time_zone.hour < 12 %> id="start-time-am-pm-am" title="AM" type="radio" value="am" name="start_time_am_pm">AM<br>
<input <%= 'checked="checked"' if !event.start_time.nil? && event.start_time.in_time_zone.hour >= 12 %> id="start-time-am-pm-pm" title="PM" type="radio" value="pm" name="start_time_am_pm">PM
</div>
</div>
<label for="end-date">End Date &amp; Time (optional)</label>
<div class="date-time-select"><span class="wdn-icon-calendar"></span>
<input id="end-date" value="<%= event.end_time.in_time_zone.strftime('%m/%d/%Y') if !event.end_time.nil? %>" name="end_date" title="End Date" type="text" class="datepicker" /><br class="hidden small-block"> @
<select id="end-time-hour" name="end_time_hour" title="End Time Hour">
<option value=""></option>
<% (1..12).each do |i| %>
<option <%= 'selected="selected"' if !event.end_time.nil? && event.end_time.in_time_zone.hour.to_i % 12 == i % 12 %> value="<%= i %>"><%= i %></option>
<% end %>
</select> :
<select id="end-time-minute" name="end_time_minute" title="End Time Minute">
<option value=""></option>
<% (0..11).each do |i| %>
<option <%= 'selected="selected"' if !event.end_time.nil? && event.end_time.in_time_zone.min == i*5 %> value="<%= i * 5 %>"><%= (i*5).to_s.rjust(2, '0') %></option>
<% end %>
</select>
<div id="end-time-am-pm" class="am_pm">
<input <%= 'checked="checked"' if event.end_time.nil? || event.end_time.in_time_zone.hour < 12 %> id="end-time-am-pm-am" title="AM" type="radio" value="am" name="end_time_am_pm">AM<br>
<input <%= 'checked="checked"' if !event.end_time.nil? && event.end_time.in_time_zone.hour >= 12 %> id="end-time-am-pm-pm" title="PM" type="radio" value="pm" name="end_time_am_pm">PM
</div>
</div>
</fieldset>
</div>
<div class="bp3-wdn-col-one-third">
<div class="visual-island">
<div class="vi-header">
<label>Image</label>
</div>
<div class="details">
<% unless event.imagedata.nil? %>
<img src="<%= event.image_src %>" alt="Image for Event <%= event.title %>">
<br>
<input type="checkbox" name="remove_image" id="remove-image">
<label for="remove-image">Remove Image</label>
<% end %>
<input style="font-size: 10px;" type="file" name="imagedata" id="imagedata" title="Event Image">
</div>
</div>
</div>
<div class="bp1-wdn-col-two-thirds">
<button class="wdn-button wdn-button-brand wdn-pull-left" type="submit"><%= event.id.nil? ? 'Create' : 'Save' %> Event</button>
</div>
</form>
</div>
<br>
<script type="text/javascript">
WDN.initializePlugin('jqueryui', [function() {
$ = require('jquery');
$('.datepicker').datepicker();
$("LINK[href^='//unlcms.unl.edu/wdn/templates_4.0/scripts/plugins/ui/css/jquery-ui.min.css']").remove();
$('#reserve-resource').click(function(click) {
if ($('#reserve-resource').is(':checked')) {
$('#resources-for-reserving').show();
} else {
$('#resources-for-reserving').hide();
}
});
$('#location').change(function (change) {
if ($(this).val() == 'new') {
$('#new-location-details').show();
} else {
$('#new-location-details').hide();
}
}).change();
$('#export-to-unl-events').change(function (change) {
if ($('#export-to-unl-events').is(':checked')) {
$('#consider-for-unl-main').removeAttr('disabled');
} else {
$('#consider-for-unl-main').attr('checked', false);
$('#consider-for-unl-main').attr('disabled', 'disabled');
}
}).change();
}]);
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment