Class: CabooseRets::OpenHousesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose_rets/open_houses_controller.rb

Instance Method Summary collapse

Instance Method Details

#admin_editObject



58
59
60
61
62
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 58

def admin_edit
  return unless (user_is_allowed_to 'edit', 'rets_open_houses')
  @openhouse = OpenHouse.find(params[:id])
  render :layout => 'caboose/admin'       
end

#admin_indexObject



17
18
19
20
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 17

def admin_index
  return unless (user_is_allowed_to 'view', 'rets_open_houses')     
  render :layout => 'caboose/admin'       
end

#admin_jsonObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 23

def admin_json 
  render :json => false and return if !user_is_allowed_to 'view', 'rets_open_houses'
  where = "(listing_mui in (select mls_number from rets_properties where list_office_mls_id = '#{@site.rets_office_id}'))" # '#{@site.rets_office_id}')"
  pager = Caboose::Pager.new(params, {
    'listing_mui' => ''
  }, {
    'model' => 'CabooseRets::OpenHouse',
    'sort'  => 'start_time',
    'desc'  => 'true',
    'base_url' => '/admin/open-houses',
    'items_per_page' => 50,
    'additional_where' => [ where ]
  })
  render :json => {
    :pager => pager,
    :models => pager.items
  } 
end

#admin_json_singleObject



43
44
45
46
47
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 43

def admin_json_single
  render :json => false and return if !user_is_allowed_to 'edit', 'rets_open_houses'
  prop = OpenHouse.find(params[:id])
  render :json => prop
end

#admin_refreshObject



50
51
52
53
54
55
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 50

def admin_refresh                  
  RetsImporter.update_helper('OpenHouse', DateTime.parse(7.days.ago.strftime('%F %T')))
  resp = Caboose::StdClass.new
  resp.success = "New open houses are being imported!"
  render :json => resp
end

#admin_updateObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 65

def admin_update
  return unless (user_is_allowed_to 'edit', 'rets_open_houses')
  resp = Caboose::StdClass.new
  openhouse = OpenHouse.find(params[:id])
  params.each do |k,v|
    case k
      when "hide" then openhouse.hide = v
    end
  end
  openhouse.save
  resp.success = true
  render :json => resp
end

#detailsObject

get /open-houses/:mls_number



12
13
14
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 12

def details
  @open_houses = OpenHouse.find(params[:mls_number])
end

#indexObject

get /open-houses



7
8
9
# File 'app/controllers/caboose_rets/open_houses_controller.rb', line 7

def index
  @open_houses = OpenHouse.where("open_house_type = 'PUB' and open_house_date >= '#{DateTime.now.strftime("%F")}'").reorder("open_house_date, start_time").all
end