Class: Muck::InvitesController

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

Instance Method Summary collapse

Instance Method Details

#composeObject



15
16
17
18
19
20
21
22
# File 'app/controllers/muck/invites_controller.rb', line 15

def compose
  flash.discard
  respond_to do |format|
    format.html { render :template => 'invites/compose', :layout => 'popup' }
    format.pjs { render :template => 'invites/compose', :layout => false }
    format.js { render :template => 'invites/compose', :layout => false }
  end
end

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/muck/invites_controller.rb', line 49

def create
  if params[:emails] && !params[:emails].blank?
    emails = params[:emails]
    emails = emails.join(', ') if emails.is_a?(Array)
    current_user.invite(params[:emails], params[:message], current_user)
    @message = t('muck.invites.create_success', :emails => emails, :app_name => MuckEngine.configuration.application_name)
  else
    @message = t('muck.invites.emails_empty')
  end
  respond_to do |format|
    format.html { render :template => 'invites/create', :layout => false }
    format.pjs { render :template => 'invites/create', :layout => false }
    format.js { render :template => 'invites/create', :layout => false }
  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 }
    format.js { render :template => 'invites/new', :layout => false }
  end
end

#get_contactsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/muck/invites_controller.rb', line 24

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 { render :json => { :success => @success, :message => @message, :contacts => @contacts.as_json } }
    format.js do
      @render_contacts_into = params[:render_contacts_into] || 'invite-contacts'
      render :template => 'invites/get_contacts', :layout => false
    end
  end
end

#newObject



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

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