add invites actions in controller and views
Index is added so organizer can see who they have invited. Oganizers will now be able to invite users with their email.Organizer will be able to delete and edit a invite.Add test for actions.
This commit is contained in:
parent
654760c3fc
commit
1c04e820b8
9 changed files with 279 additions and 3 deletions
|
|
@ -36,8 +36,8 @@ $(function () {
|
|||
format: 'YYYY-MM-DD',
|
||||
maxDate : $("#invitation-end-date").attr('end_date'),
|
||||
minDate : today
|
||||
});
|
||||
|
||||
}).keypress(function(event) {event.preventDefault();});
|
||||
|
||||
$("#registration-arrival-datepicker").on("dp.change",function (e) {
|
||||
// departure_date > start_date,arrival_date
|
||||
if ((new Date(e.date).getTime()) > (new Date($("#registration-arrival-datepicker").attr('start_date')).getTime())){
|
||||
|
|
|
|||
|
|
@ -2,10 +2,69 @@ module Admin
|
|||
class InvitesController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
|
||||
def index
|
||||
@invites = Invite.where(conference_id: @conference.id)
|
||||
@invites.each do |invite|
|
||||
invite.emails = User.find(invite.user_id).email
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@invite = @conference.invites.new
|
||||
end
|
||||
|
||||
def create; end
|
||||
def create
|
||||
emails_array = invite_params[:emails].split(',')
|
||||
invite_count = 0
|
||||
flag = 0
|
||||
emails_array.each do |email|
|
||||
@invite = @conference.invites.new(invite_params)
|
||||
new_user = User.find_by(email: email)
|
||||
new_user = User.invite!({ email: email }, current_user) if new_user.nil?
|
||||
@invite.user_id = new_user.id
|
||||
invite_count += 1
|
||||
unless @invite.save
|
||||
flash.now[:error] = "#{(invite_count - 1)} invitations created. Creating invitation failed. #{@invite.errors.full_messages.to_sentence}."
|
||||
flag = 1
|
||||
break
|
||||
end
|
||||
end
|
||||
if flag.zero?
|
||||
redirect_to admin_conference_invites_path, notice: "#{invite_count.to_s + ' invitation'.pluralize(invite_count)} successfully created."
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@invite = Invite.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@invite = Invite.find(params[:id])
|
||||
if @invite.update_attributes(invite_params)
|
||||
redirect_to admin_conference_invites_path,
|
||||
notice: 'Invitation successfully updated.'
|
||||
else
|
||||
flash.now[:error] = "Creating invitation failed. #{@invite.errors.full_messages.to_sentence}."
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if Invite.find(params[:id]).destroy
|
||||
redirect_to admin_conference_invites_path,
|
||||
notice: 'Invitation deleted.'
|
||||
else
|
||||
redirect_to admin_conference_invites_path,
|
||||
notice: 'Unable to delete the invitation.'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def invite_params
|
||||
params.require(:invite).permit(:emails, :end_date, :invite_for)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -100,3 +100,4 @@
|
|||
.col-md-12.text-right
|
||||
- if can? :create, Booth
|
||||
= link_to 'New Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-primary'
|
||||
= link_to 'Late Submission Invite', new_admin_conference_invite_path(@conference.short_title), class: 'button btn btn-success'
|
||||
|
|
|
|||
11
app/views/admin/invites/edit.html.haml
Normal file
11
app/views/admin/invites/edit.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
.row
|
||||
.col-md-12
|
||||
.page-header
|
||||
%h1 Edit Invitation
|
||||
|
||||
.row
|
||||
.col-md-8
|
||||
= semantic_form_for(@invite, url: admin_conference_invite_path(@conference.short_title), html: { multipart: true }) do |f|
|
||||
= f.input :invite_for, as: :select, collection: ['Track', (t 'booth').capitalize]
|
||||
= f.input :end_date, as: :string, input_html: { id: 'invitation-end-date', end_date: @conference.end_date }
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||
42
app/views/admin/invites/index.html.haml
Normal file
42
app/views/admin/invites/index.html.haml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
.row
|
||||
.col-md-12
|
||||
.page-header
|
||||
%h1
|
||||
Invitations
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
- if @invites.present?
|
||||
%table.datatable
|
||||
%thead
|
||||
%th
|
||||
%b ID
|
||||
%th
|
||||
%b User
|
||||
%th
|
||||
%b Invited for
|
||||
%th
|
||||
%b Invitation validity
|
||||
%th
|
||||
%b Action
|
||||
|
||||
- @invites.each do |invite|
|
||||
%tr
|
||||
%td
|
||||
= invite.id
|
||||
%td
|
||||
= invite.emails
|
||||
%td
|
||||
= invite.invite_for
|
||||
%td
|
||||
= invite.end_date
|
||||
%td
|
||||
= link_to 'Edit', edit_admin_conference_invite_path(@conference.short_title, invite.id),
|
||||
class: 'btn btn-primary'
|
||||
= link_to 'Delete', admin_conference_invite_path(@conference.short_title, invite.id), method: :delete,
|
||||
data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
|
||||
|
||||
.row
|
||||
.col-md-12.text-right
|
||||
- if can? :create, Invite
|
||||
= link_to 'Late Submission Invite', new_admin_conference_invite_path(@conference.short_title), class: 'button btn btn-success'
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
= f.input :end_date, as: :string, input_html: { id: 'invitation-end-date', end_date: @conference.end_date }
|
||||
%p.text-right
|
||||
= f.submit 'Submit', class: 'btn btn-success'
|
||||
= link_to 'View Invitations', admin_conference_invites_path, class: 'btn btn-primary'
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
|
|
|
|||
|
|
@ -100,3 +100,4 @@
|
|||
.row
|
||||
.col-md-12.text-right
|
||||
= link_to 'New Track', new_admin_conference_program_track_path(@conference.short_title), class: 'btn btn-primary'
|
||||
= link_to 'Late Submission Invite', new_admin_conference_invite_path(@conference.short_title), class: 'button btn btn-success'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue