Class: Muck::EmailSharesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/muck/email_shares_controller.rb', line 17

def create
  if params[:emails].blank?
    @result = t('muck.shares.emails_empty')
  elsif params[:message].blank?
    @result = t('muck.shares.message_empty')
  else
    @emails = params[:emails]
    @emails = @emails.join(', ') if @emails.is_a?(Array)
    @emails = @emails.split(/[, ]/) if !@emails.is_a?(Array)
    @emails = @emails.find_all { |email| !email.blank? }
    @emails = @emails.flatten.collect { |email| email.strip }
    check_emails = []
    subject = params[:subject]
    message = params[:message]
    @emails.each do |email|
      if !check_emails.include?(email)
        check_emails << email
        response = ShareMailer.share_email(current_user, email, subject, message).deliver
      end
    end
    @emails = @emails.join(',')
    @result = t('muck.shares.share_email_success', :emails => @emails)
    @success = true
  end
  respond_to do |format|
    format.html do
      flash[:notice] = @result
      render :template => 'email_shares/new', :layout => 'popup'
    end
    format.pjs { render :template => 'email_shares/create', :layout => false  }
    format.js { render :template => 'email_shares/create', :layout => false }
  end 
end

#newObject



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

def new
  flash.discard
  @emails = params[:emails]
  @message = CGI.unescape(params[:message] || '')
  @subject = CGI.unescape(params[:subject] || '')
  respond_to do |format|
    format.html { render :template => 'email_shares/new', :layout => 'popup' }
    format.pjs { render :template => 'email_shares/new', :layout => false }
    format.js { render :template => 'email_shares/new', :layout => false }
  end
end