Sha256: 20d979296d48828efb2cc96c888ac58c1c9963c51bdd92f3604a00bd6e42b8c7

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

class Muck::InvitesController < ApplicationController

  unloadable

  before_filter :login_required

  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

  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

  def create
    if params[:emails]
      current_user.invite(params[:emails])
      flash[:notice] = t('muck.invites.create_success', :emails => params[:emails].join(', '), :app_name => GlobalConfig.application_name)
    end  
    redirect_to('/')
  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)
  end

  protected

    def get_contacts_html
      render_as_html do
        render_to_string(:partial => 'invites/get_contacts')
      end
    end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
muck-invites-0.1.3 app/controllers/muck/invites_controller.rb
muck-invites-0.1.2 app/controllers/muck/invites_controller.rb
muck-invites-0.1.1 app/controllers/muck/invites_controller.rb