Class: Orange::ContactFormsResource

Inherits:
ModelResource show all
Defined in:
lib/orange-more/contactforms/resources/contactforms_resource.rb

Instance Attribute Summary

Attributes inherited from ModelResource

#model_class

Instance Method Summary collapse

Methods inherited from ModelResource

#afterDelete, #afterNew, #afterSave, #beforeDelete, #beforeNew, #beforeSave, #create, #delete, #do_list_view, #do_view, #edit, #find_list, #find_one, #index, #list, #new, new, #onDelete, #onNew, #onSave, #save, #show, #table_row, use, #view, #view_opts

Methods inherited from RoutableResource

#routable, #route

Methods inherited from Resource

#afterLoad, call_me, #do_view, #find_extras, #init, #initialize, #options, #orange, #orange_name, #routable, #set_orange, set_orange, #view, #view_opts

Methods included from ClassInheritableAttributes

#cattr_accessor, #cattr_reader, #cattr_writer, eval_in_accessor_module, fetch_value, store_value

Constructor Details

This class inherits a constructor from Orange::Resource

Instance Method Details

#contactform(packet, opts = {}) ⇒ Object



28
29
30
31
32
# File 'lib/orange-more/contactforms/resources/contactforms_resource.rb', line 28

def contactform(packet, opts = {})
  template = opts[:template].to_sym || :contactform
  packet['route.return_path'] = packet.request.path.to_s
  do_view(packet, template, opts)
end

#mailer(packet, opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/orange-more/contactforms/resources/contactforms_resource.rb', line 34

def mailer(packet, opts = {})
  params = packet.request.params
  route = params['r']
  if params['contact_phone'] != ''
    packet.flash['error'] = "An error has occurred. Please try your submission again."
    packet.reroute(route)
  end
  path = packet['route.path']
  parts = path.split('/')
  form = model_class.get(parts.last.to_i)
  mail = Mail.new do
    from "WNSF <[email protected]>"
    to form.to_address
    subject 'E-mail contact from WNSF.org - '+form.title
    body "From: "+params['contact_from']+" ("+params['contact_email_address']+")\n\nMessage:\n"+params['contact_message']
  end
  mail.delivery_method :sendmail
  mail.deliver
  packet.flash['error'] = "Thanks for your submission. We will contact you as soon as possible."
  packet.reroute(route)
end

#stack_initObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/orange-more/contactforms/resources/contactforms_resource.rb', line 7

def stack_init
  orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Contact Forms')
  orange[:radius].define_tag "contactform" do |tag|
 	  if tag.attr["name"] && model_class.named(tag.attr["name"]).count >0
      m = model_class.named(tag.attr["name"]).first #selects contactform based on title
   elsif model_class.all.count > 0
     if tag.attr["id"]
  	    m = model_class.get(tag.attr["id"])
     else
       m = model_class.first
     end
   end
    unless m.nil?
      template = tag.attr["template"] || "contactform"
      orange[:contactforms].contactform(tag.locals.packet, {:model => m, :template => template, :id => m.id})
    else
      ""
    end
  end
end