Skip to content

Commit

Permalink
split manage/message and clean up those views #14
Browse files Browse the repository at this point in the history
  • Loading branch information
bteitelb committed Feb 23, 2015
1 parent c44fb69 commit 1981951
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 141 deletions.
25 changes: 19 additions & 6 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,33 @@ def show

# GET /events/1/manage
# GET /events/1.json/manage
def manage_attendees
def manage
if @event.manageable?
@activities_n_counts = Activity.activities_n_counts(:limit => 20, :trackable => @event)
respond_to do |format|
format.html { render 'manage' }
format.json { render json: @event }
end
render 'manage'
else
if not @event.rsvp
render_error(:message => 'Cannot manage attendees because RSVP is not set for this workshop', :status => :unauthorized)
elsif @event.external
render_error(:message => 'Cannot manage attendees of an external workshop', :status => :unauthorized)
else
render_error(:message => 'Workshop unmanageable for some reason', :status => :unauthorized)
raise "workshop unmanageable for some unknown reason"
end
end
end

# GET /events/1/message
# GET /events/1.json/message
def message
if @event.manageable?
render 'message'
else
if not @event.rsvp
render_error(:message => 'Cannot message attendees because RSVP is not set for this workshop', :status => :unauthorized)
elsif @event.external
render_error(:message => 'Cannot message attendees of an external workshop', :status => :unauthorized)
else
raise "workshop unmessageable for some unknown reason"
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def update
def manage
@attendees = @workshop.attendees.uniq
end

# GET /w/:id/message(.:format)
def message
@attendees = @workshop.attendees.uniq
end

# POST /w/1/sms_attendees
def sms_attendees
Expand Down
5 changes: 3 additions & 2 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Ability
include CanCan::Ability

def initialize(user, session)
alias_action :edit, :update, :destroy, :accept_attendee, :cancel_attend, :manage_attendees, :lock, :unlock, :sms_attendees, :upload_photo, :manage, :to => :manage_as_host
alias_action :edit, :update, :destroy, :accept_attendee, :cancel_attend, :lock, :unlock, :sms_attendees, :upload_photo, :manage, :message, :to => :manage_as_host

# anyone
can [:show, :attend_by_email], Event
Expand All @@ -27,7 +27,8 @@ def initialize(user, session)
end

can [:plus, :minus, :create, :index, :destroy], Review, :author_id => user.id


cannot :manage_as_host, Workshop
can :simple_index_partial, Workshop
# host
if user.host?
Expand Down
6 changes: 3 additions & 3 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

<%= simple_form_for(@event) do |f| %>
<div class="page-header">
<label class="optional" for="event_venue_id">From the series:</label>
<label>From the series:</label>
<div class="pull-right">
<%= iconic_link_to 'Message attendees', manage_event_path(@event), class: 'btn btn-sm btn-default', title: 'message all' , icon: 'send' %>
<%= iconic_link_to 'Message attendees', message_event_path(@event), class: 'btn btn-sm btn-default', title: 'message attendees' , icon: 'send' %>
<%= iconic_link_to 'Manage attendees', manage_event_path(@event), class: 'btn btn-sm btn-default', title: 'message attendees' , icon: 'group' %>
<%= iconic_link_to 'Configure alerts', edit_workshop_path(@event.workshop), class: 'btn btn-sm btn-default', title: 'configure alerts' , icon: 'exclamation-circle' %>
<%= iconic_link_to 'Delete', @event, confirm: 'Are you sure?', method: :delete, class: 'btn btn-sm btn-danger', title: 'delete', id: 'delete_event_link' %>
</div>
Expand Down
74 changes: 31 additions & 43 deletions app/views/events/manage.html.erb
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
<% if (@event.host === current_user) or admin_session? %>
<h2 class="margin0"><%= link_to @event.workshop.title, edit_workshop_path(@event.workshop) %></h2>
<p>hosted by <%= contextualized_user_link(@event.host, :linked => true) %> ·
<%= event_price(@event, :show_materials_fee => true) %> ·
<%= @event.max_attendees %> slots ·
<%= pluralize(@event.attendances.count, 'person') %> signed up ·
meets <%= @event.meetings.count == 1 ? 'once' : (@event.meetings.count == 2 ? 'twice' : pluralize(@event.meetings.count, 'time')) %>
</p>
<%= link_to 'message all attendees in series', manage_workshop_path(@event.workshop), class: 'pull-right' %>
<p>
<%= render 'reruns/meeting_times_list', :rerun => @event, :include_venue => false, :inline => true %>
</p>
<div class="well">
<h3>Message Attendees</h3>
<ul class="nav nav-pills margin0">
<li class="active"><a href="#compose_sms" data-toggle="tab">Short message</a></li>
<li><a href="#compose_email" data-toggle="tab">Long message</a></li>
</ul>
<div class="tab-content">
<div class='tab-pane active' id='compose_sms'>
<%= render 'reruns/message_attendees', :rerun => @event, :url => sms_attendees_path(@event) %>
</div>
<div class='tab-pane' id='compose_email'>
<%= render 'messages/form', :message => Message.new(:apropos => @event) %>
</div>
<div class="page-header">
<div class="pull-right">
<%= iconic_link_to 'Manage all attendees in series', manage_workshop_path(@event.workshop), class: 'btn btn-sm btn-default', title: 'manage all attendees' , icon: 'group' %>
</div>
<label>Manage attendees of:</label>
<h2 class="margin0"><%= link_to @event.title, @event %></h2>
<p>
<%= render 'reruns/meeting_times_list', :rerun => @event, :include_venue => false, :inline => true %>
</p>
<p>hosted by <%= contextualized_user_link(@event.host, :linked => true) %> ·
<%= event_price(@event, :show_materials_fee => true) %> ·
<%= @event.max_attendees %> slots ·
<%= pluralize(@event.attendances.count, 'person') %> signed up<br/>
meets <%= @event.meetings.count == 1 ? 'once' : (@event.meetings.count == 2 ? 'twice' : pluralize(@event.meetings.count, 'time')) %> · part of the series <%= link_to @event.title, my_workshops_path(:anchor => "w_#{@event.workshop.uuid}") %>
</p>
</div>

<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs margin0">
<li class="active"><a href="#attendees" data-toggle="tab">Attendees</a></li>
<li><a href="#activity" data-toggle="tab">Activity</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane active" id="attendees">
<%= render 'manage_attendances' %>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs margin0">
<li class="active"><a href="#attendees" data-toggle="tab">Attendees</a></li>
<li><a href="#activity" data-toggle="tab">Activity</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane active" id="attendees">
<%= render 'manage_attendances' %>
</div>
<div class="tab-pane" id="activity">
<%= render :partial => 'activities/index', :locals => {:activities_n_counts => @activities_n_counts} %>
</div>
<div class="tab-pane" id="activity">
<%= render :partial => 'activities/index', :locals => {:activities_n_counts => @activities_n_counts} %>
</div>
</div>
</div>
</div>
<% end %>

<%# render :partial => 'events/attend_status_and_call_to_action' %>

<div class="row">
<%# render :partial => 'activities/index', :locals => {:activities => @event.activities} %>
</div>
<%# render :partial => 'activities/index', :locals => {:activities => @event.activities} %>

<%# render :partial => 'attendees_modal' %>
31 changes: 31 additions & 0 deletions app/views/events/message.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="page-header">
<div class="pull-right">
<%= iconic_link_to 'Message all attendees in series', message_workshop_path(@event.workshop), class: 'btn btn-sm btn-default', title: 'message all attendees' , icon: 'send' %>
</div>
<label>Message attendees of:</label>
<h2 class="margin0"><%= link_to @event.title, @event %></h2>
<p>
<%= render 'reruns/meeting_times_list', :rerun => @event, :include_venue => false, :inline => true %>
</p>
<p>hosted by <%= contextualized_user_link(@event.host, :linked => true) %> ·
<%= event_price(@event, :show_materials_fee => true) %> ·
<%= @event.max_attendees %> slots ·
<%= pluralize(@event.attendances.count, 'person') %> signed up ·
meets <%= @event.meetings.count == 1 ? 'once' : (@event.meetings.count == 2 ? 'twice' : pluralize(@event.meetings.count, 'time')) %><br/>
part of the series <%= link_to @event.title, my_workshops_path(:anchor => "w_#{@event.workshop.uuid}") %>
</p>
</div>
<div class="well">
<ul class="nav nav-pills margin0">
<li class="active"><a href="#compose_sms" data-toggle="tab">Short message</a></li>
<li><a href="#compose_email" data-toggle="tab">Long message</a></li>
</ul>
<div class="tab-content">
<div class='tab-pane active' id='compose_sms'>
<%= render 'reruns/message_attendees', :rerun => @event, :url => sms_attendees_path(@event) %>
</div>
<div class='tab-pane' id='compose_email'>
<%= render 'messages/form', :message => Message.new(:apropos => @event) %>
</div>
</div>
</div>
85 changes: 0 additions & 85 deletions app/views/workshops/manage.html.erb

This file was deleted.

38 changes: 38 additions & 0 deletions app/views/workshops/message.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="page-header">
<label>Message all attendees from the series:</label>
<h2 class="margin0"><%= link_to @workshop.title, my_workshops_path(:anchor => "w_#{@workshop.uuid}") %></h2>
</div>
<div class="alert alert-danger" role="alert">
Messages sent from this page will be broadcast to all <%= @workshop.attendees.where(:sms_short_messages => true).count %> people who have attended one of the <%= @workshop.events.count %> workshops in this series. Be careful.
</div>
<div class="well">
<ul class="nav nav-pills margin0">
<li class="active"><a href="#compose_sms" data-toggle="tab">Short message</a></li>
<li><a href="#compose_email" data-toggle="tab">Long message</a></li>
</ul>
<div class="tab-content">
<div class='tab-pane active' id='compose_sms'>
<%= render 'reruns/message_attendees', :rerun => @workshop, :url => sms_attendees_workshop_path(@workshop) %>
</div>
<div class='tab-pane' id='compose_email'>
<%= render 'messages/form', :message => Message.new(:apropos => @workshop) %>
</div>
</div>
</div>
<%= render 'messages/modal_new', :message => Message.new, :to => :one_person %>


<% ready_script do -%>
<% if user_signed_in? %>
$('#event_attendees a.message_user').on('click', function(e) {
$('#new_message_modal .modal-header-content').html($(this).data('modal-header-content'));
$('#new_message_modal #message__to_user_uuid').attr('value', $(this).data('id'));
$('#new_message_modal').modal('show');
e.preventDefault();
});
<% end %>
$(document).on('ajax:success', '#new_message_modal form', function(e, data, status, xhr) {
$("#new_message_modal").modal('hide');
show_bootstrap_alert({text: "Your message has been sent.", type: 'success'});
});
<% end -%>
9 changes: 7 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
resources :w, controller: 'workshops', as: 'workshops' do
member do
get 'manage'
get 'message'
get 'reruns_partial'
match 'upload_photo'
post 'auto_add_rerun'
get 'simple_index_partial'
get 'manage_attendees'
post 'sms_attendees'
end
end
Expand All @@ -31,7 +31,12 @@
get 'events/:id/attendees(.:format)' => 'events#attendees', :as => :attendees
post 'events/:id/confirm(.:format)' => 'events#confirm', :as => :confirm_attend
get 'events/:id/accept_attendee(.:format)' => 'events#accept_attendee', :as => :accept_attendee
get 'events/:id/manage' => 'events#manage_attendees', :as => :manage_event
resources :events, controller: 'events' do
member do
get 'manage'
get 'message'
end
end
post 'events/:id/lock' => 'events#lock', :as => :lock_event
post 'events/:id/unlock' => 'events#unlock', :as => :unlock_event
post 'events/:id/sms_attendees' => 'events#sms_attendees', :as => :sms_attendees
Expand Down

0 comments on commit 1981951

Please sign in to comment.