Class: Pwb::PropsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pwb/props_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

default_url_options, #set_locale, #set_theme_path

Instance Method Details

#request_property_info_ajaxObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/pwb/props_controller.rb', line 57

def request_property_info_ajax
  @error_messages = []
  I18n.locale = params["contact"]["locale"] || I18n.default_locale
  # have a hidden field in form to pass in above
  # if I didn't I could end up with the wrong locale
  # @enquiry = Message.new(params[:contact])
  @property = Prop.find(params[:contact][:property_id])
  @client = Client.find_or_initialize_by(email: params[:contact][:email])
  @client.attributes = {
    phone_number_primary: params[:contact][:tel],
    first_names: params[:contact][:name]
  }

  title = I18n.t "mailers.property_enquiry_targeting_agency.title"
  @enquiry = Message.new({
                           title: title,
                           content: params[:contact][:message],
                           locale: params[:contact][:locale],
                           url: request.referer,
                           host: request.host,
                           origin_ip: request.ip,
                           user_agent: request.user_agent,
                           delivery_email: @current_agency.email_for_property_contact_form
                           # origin_email: params[:contact][:email]
  })

  unless @enquiry.save && @client.save
    @error_messages += @client.errors.full_messages
    @error_messages += @enquiry.errors.full_messages
    return render "pwb/ajax/request_info_errors"
  end

  unless @current_agency.email_for_property_contact_form.present?
    # in case a delivery email has not been set
    @enquiry.delivery_email = "[email protected]"
  end

  @enquiry.client = @client
  @enquiry.save

  EnquiryMailer.property_enquiry_targeting_agency(@client, @enquiry, @property).deliver
  # @enquiry.delivery_success = true
  @enquiry.save
  @flash = I18n.t "contact.success"
  return render "pwb/ajax/request_info_success", layout: false
rescue => e

  # TODO: - log error to logger....
  @error_messages = [I18n.t("contact.error"), e]
  return render "pwb/ajax/request_info_errors", layout: false
end

#show_for_rentObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/pwb/props_controller.rb', line 5

def show_for_rent
  @carousel_speed = 3000
  # @inmo_template = "broad"
  @property_details = Prop.find_by_id(params[:id])
  # gon.property_details =@property_details
  @operation_type = "for_rent"
  @operation_type_key = @operation_type.camelize(:lower)
  @map_markers = []
  if @property_details && @property_details.visible && @property_details.for_rent
    set_map_marker
    # below lets me know what prices to display
    @show_vacational_rental = @property_details.for_rent_short_term

    js property_details: @property_details
    js 'Pwb/Props#show'
    @page_title = @property_details.title
    @page_description = @property_details.description
    # @page_keywords    = 'Site, Login, Members'
    return render "/pwb/props/show"
  else
    @page_title = I18n.t("propertyNotFound")
    hi_content = Content.where(tag: 'landing-carousel')[0]
    @header_image = hi_content.present? ? hi_content.default_photo : nil
    return render "not_found"
  end
end

#show_for_saleObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/pwb/props_controller.rb', line 32

def show_for_sale
  @carousel_speed = 3000
  # @inmo_template = "broad"
  @operation_type = "for_sale"
  @operation_type_key = @operation_type.camelize(:lower)
  @property_details = Prop.find_by_id(params[:id])
  @map_markers = []

  if @property_details && @property_details.visible && @property_details.for_sale
    set_map_marker
    # gon.property_details =@property_details
    js property_details: @property_details
    js 'Pwb/Props#show'
    @page_title = @property_details.title
    @page_description = @property_details.description
    # @page_keywords    = 'Site, Login, Members'
    return render "/pwb/props/show"
  else
    @page_title = I18n.t("propertyNotFound")
    hi_content = Content.where(tag: 'landing-carousel')[0]
    @header_image = hi_content.present? ? hi_content.default_photo : nil
    return render "not_found"
  end
end