Class: Muck::InvitesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/invites_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/muck/invites_controller.rb', line 39

def create
  if params[:emails]
    current_user.invite(params[:emails], current_user)
    message = t('muck.invites.create_success', :emails => params[:emails].join(', '), :app_name => GlobalConfig.application_name)
  end
  respond_to do |format|
    format.html do
      flash[:notice] = message
      redirect_to('/')
    end
    format.pjs { render :text => message }
  end 
  
rescue ActiveRecord::RecordInvalid => ex
  if @invite
    errors = @invite.errors.full_messages.to_sentence
  else
    errors = ex
  end
  flash[:error] = t('muck.invites.create_error', :errors => errors)
  respond_to do |format|
    format.html { render :template => 'invites/new' }
    format.pjs { render :template => 'invites/new', :layout => false }
  end
end

#get_contactsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/muck/invites_controller.rb', line 16

def get_contacts
  success = true
  begin
    @contacts = User.get_contacts(params[:get_contacts][:email], params[:get_contacts][:password])
    if @contacts.blank?
      message = t('muck.invites.no_contacts_found')
      success = false
    end
  rescue Contacts::AuthenticationError => ex
    success = false
    message = ex.to_s
  end    
  respond_to do |format|
    format.html do
      flash[:error] = message if message
      render :template => 'invites/_get_contacts'
    end
    format.json do
      render :json => { :success => success, :message => message, :html => get_contacts_html }
    end
  end
end

#newObject



7
8
9
10
11
12
13
14
# File 'app/controllers/muck/invites_controller.rb', line 7

def new
  flash.discard
  @page_title = t('muck.invites.new_invites', :app_name => GlobalConfig.application_name)
  respond_to do |format|
    format.html { render :template => 'invites/new' }
    format.pjs { render :template => 'invites/new', :layout => false }
  end
end