forked from squaretalent/radiant-forms-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
624 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.1 | ||
3.0.0.rc1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
class FormMail | ||
include Forms::Models::Extension | ||
|
||
def create | ||
@body = @page.render_snippet(@form) | ||
|
||
begin | ||
FormMailer.deliver_mail( | ||
:recipients => recipients, | ||
:from => from, | ||
:reply_to => reply_to, | ||
:subject => subject, | ||
:body => body, | ||
:cc => cc, | ||
:headers => headers, | ||
:content_type => content_type, | ||
:charset => charset | ||
) | ||
@sent = true | ||
rescue Exception => exception | ||
raise exception if RAILS_ENV['development'] | ||
@message = exception | ||
@sent = false | ||
end | ||
|
||
@result = { | ||
:sent => self.sent?, | ||
:message => self.message, | ||
:subject => self.subject, | ||
:from => self.from | ||
} | ||
end | ||
|
||
def from | ||
from = nil | ||
unless @config[:field].nil? or !@config[:field][:from].blank? | ||
from = hash_retrieve(@data, @config[:field][:from]) | ||
else | ||
from = @config[:from] | ||
end | ||
from | ||
end | ||
|
||
def recipients | ||
to = nil | ||
unless @config[:field].nil? or !@config[:field][:to].blank? | ||
to = hash_retrieve(@data, @config[:field][:to]) | ||
else | ||
to = @config[:to] | ||
end | ||
to | ||
end | ||
|
||
def reply_to | ||
reply_to = nil | ||
unless @config[:field].nil? or !@config[:field][:reply_to].blank? | ||
reply_to = hash_retrieve(@data, @config[:field][:reply_to]) | ||
else | ||
reply_to = @config[:reply_to] | ||
end | ||
reply_to | ||
end | ||
|
||
def sender | ||
sender = nil | ||
unless @config[:field].nil? or !@config[:field][:sender].blank? | ||
sender = hash_retrieve(@data, @config[:field][:sender]) | ||
else | ||
sender = @config[:sender] | ||
end | ||
sender | ||
end | ||
|
||
def subject | ||
subject = nil | ||
unless @config[:field].nil? or !@config[:field][:subject].blank? | ||
subject = hash_retrieve(@data, @config[:field][:subject]) | ||
else | ||
subject = @config[:subject] | ||
end | ||
subject | ||
end | ||
|
||
def body | ||
@body || '' | ||
end | ||
|
||
def cc | ||
@config[:cc] | ||
end | ||
|
||
def sent? | ||
@sent || false | ||
end | ||
|
||
def message | ||
@message || nil | ||
end | ||
|
||
def headers | ||
headers = { 'Reply-To' => reply_to } | ||
if sender | ||
headers['Return-Path'] = sender | ||
headers['Sender'] = sender | ||
end | ||
headers | ||
end | ||
|
||
def content_type | ||
content_type = config[:content_type] || 'multipart/mixed' | ||
end | ||
|
||
def charset | ||
charset = config[:charset] || 'utf-8' | ||
charset = charset == '' ? nil : charset | ||
end | ||
|
||
protected | ||
|
||
# takes object[value] || value and accesses the hash as hash[object][value] || hash[value] | ||
def hash_retrieve(hash, array) | ||
data = array.gsub('[','|').gsub(']','').split('|') rescue nil | ||
|
||
result = false | ||
result = hash.fetch(data[0]) unless data.nil? | ||
result = result.fetch(data[1]) if !data.nil? and data[1] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class FormMailer < ActionMailer::Base | ||
|
||
def mail(options) | ||
content_type options[:content_type] | ||
charset options[:charset] | ||
headers options[:headers] | ||
|
||
recipients options[:recipients] | ||
from options[:from] | ||
cc options[:cc] | ||
bcc options[:bcc] | ||
subject options[:subject] | ||
body options[:body] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Forms | ||
module Controllers | ||
module ApplicationController | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
helper_method :current_response | ||
|
||
def current_response | ||
if request.session[:form_response] | ||
@response = Response.find(request.session[:form_response]) | ||
else | ||
@response = Response.create | ||
request.session = @response.id | ||
end | ||
|
||
@response | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.