Class: Widgets::ContactUs::Base

Inherits:
ErpApp::Widgets::Base
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/widgets/contact_us/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_layoutObject



74
75
76
77
78
79
80
81
# File 'app/widgets/contact_us/base.rb', line 74

def base_layout
  begin
    file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
    IO.read(file)
  rescue
    return nil
  end
end

.titleObject



66
67
68
# File 'app/widgets/contact_us/base.rb', line 66

def title
  "Contact Us"
end

.widget_nameObject



70
71
72
# File 'app/widgets/contact_us/base.rb', line 70

def widget_name
  File.basename(File.dirname(__FILE__))
end

Instance Method Details

#indexObject



6
7
8
9
10
# File 'app/widgets/contact_us/base.rb', line 6

def index
  @use_dynamic_form = params[:use_dynamic_form]

  render
end

#locateObject

should not be modified modify at your own risk



61
62
63
# File 'app/widgets/contact_us/base.rb', line 61

def locate
  File.dirname(__FILE__)
end

#newObject



12
13
14
15
16
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
50
51
52
53
54
55
56
57
# File 'app/widgets/contact_us/base.rb', line 12

def new
  @is_html_form = params[:is_html_form]
  @validation = {}
  @validation[:first_name] = "First Name Cannot be Blank" if params[:first_name].blank?
  @validation[:last_name] = "Last Name Cannot be Blank" if params[:last_name].blank?
  @validation[:message] = "Message Cannot be Blank" if params[:message].blank?
  @validation[:email] = "Please Enter a Valid Email Address" unless /^.+@.+\..+$/.match(params[:email])
			
  if @is_html_form and !@validation.empty?
    return render :update => {:id => "#{@uuid}_result", :view => :error}
  end
			
  @website = Website.find_by_host(request.host_with_port)
  @website_inquiry = WebsiteInquiry.new

  subject = strip_tags(params[:email_subject])
  params.delete(:email_subject)
  params[:created_by] = current_user unless current_user.nil?
  params[:created_with_form_id] = params[:dynamic_form_id] if params[:dynamic_form_id] and params[:is_html_form].blank?
  params[:website_id] = @website.id
  @website_inquiry = @website_inquiry.save_all_attributes(params, ErpApp::Widgets::Base::IGNORED_PARAMS)
				
  if @website_inquiry
    if @website.email_inquiries?
      @website_inquiry.send_email(subject)
    end
			  
    if @is_html_form
      render :update => {:id => "#{@uuid}_result", :view => :success}
    else
      render :json => {
        :success => true,
        :response => render_to_string(:template => "success", :layout => false)
      }
    end
  else
    if @is_html_form
      render :update => {:id => "#{@uuid}_result", :view => :error}
    else
      render :json => {
        :success => false,
        :response => render_to_string(:template => "error", :layout => false)
      }
    end
  end
end