Class: CabooseRets::AgentsController

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

Instance Method Summary collapse

Instance Method Details

#admin_agent_optionsObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/caboose_rets/agents_controller.rb', line 37

def admin_agent_options
  options = []
  rc = CabooseRets::RetsConfig.where(:site_id => @site.id).first
  agents = rc ? CabooseRets::Agent.joins(:meta).where(:office_mls_id => rc.office_mls, rets_agents_meta: {hide: FALSE, accepts_listings: true}).order(:sort_order).all : []
  agents.each do |c|
    options << { 'value' => c.mls_id, 'text' => "#{c.first_name} #{c.last_name}" }
  end     
  render :json => options
end

#admin_editObject



96
97
98
99
100
101
# File 'app/controllers/caboose_rets/agents_controller.rb', line 96

def admin_edit
  return unless (user_is_allowed_to 'edit', 'rets_agents')
  @agent = Agent.find(params[:id])
  @agent_meta = @agent.meta ? @agent.meta : AgentMeta.create(:la_code => @agent.matrix_unique_id) if @agent
  render :layout => 'caboose/admin'       
end

#admin_edit_sortObject



76
77
78
79
80
# File 'app/controllers/caboose_rets/agents_controller.rb', line 76

def admin_edit_sort
  return unless user_is_allowed_to 'edit', 'rets_agents'
  @agents = Agent.where("office_mls_id ILIKE ?", @site.rets_office_id).order(:sort_order).all
  render :layout => 'caboose/admin'  
end

#admin_indexObject



31
32
33
34
# File 'app/controllers/caboose_rets/agents_controller.rb', line 31

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

#admin_jsonObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/caboose_rets/agents_controller.rb', line 48

def admin_json 
  render :json => false and return if !user_is_allowed_to 'view', 'rets_agents'
  where = "(office_mls_id ILIKE '#{@site.rets_office_id}')"
  pager = Caboose::Pager.new(params, {
    'first_name_like' => '',
    'last_name_like' => ''
  }, {
    'model' => 'CabooseRets::Agent',
    'sort'  => 'last_name',
    'desc'  => 'false',
    'base_url' => '/admin/agents',
    'items_per_page' => 50,
    'additional_where' => [ (where) ]
  })
  render :json => {
    :pager => pager,
    :models => pager.items.as_json(:include => [:meta])
  } 
end

#admin_json_singleObject



69
70
71
72
73
# File 'app/controllers/caboose_rets/agents_controller.rb', line 69

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

#admin_updateObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/caboose_rets/agents_controller.rb', line 104

def admin_update
  return unless (user_is_allowed_to 'edit', 'rets_agents')
  resp = Caboose::StdClass.new
  agent = Agent.find(params[:id])
  meta = agent.meta ? agent.meta : AgentMeta.create(:la_code => agent.matrix_unique_id)
  params.each do |k,v|
    case k
      when "bio" then meta.bio = v
      when "slug" then agent.slug = v
      when "hide" then meta.hide = v
      when "weight" then meta.weight = v
      when "accepts_listings" then meta.accepts_listings = v
    end
  end
  agent.save
  meta.save
  resp.success = true
  render :json => resp
end

#admin_update_imageObject



125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/caboose_rets/agents_controller.rb', line 125

def admin_update_image
  render :json => false and return unless user_is_allowed_to 'edit', 'rets_agents'    
  resp = Caboose::StdClass.new({ 'attributes' => {} })
  agent = Agent.find(params[:id])
  meta = agent.meta ? agent.meta : AgentMeta.create(:la_code => agent.matrix_unique_id) if agent
  meta.image = params[:image]
  meta.save
  resp.attributes['image'] = { 'value' => meta.image.url(:thumb) }    
  render :text => resp.to_json
end

#admin_update_sortObject



83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/caboose_rets/agents_controller.rb', line 83

def admin_update_sort
  resp = Caboose::StdClass.new
  return unless user_is_allowed_to 'edit', 'rets_agents'
  params[:agent].each_with_index do |ag, ind|
    agent = Agent.find(ag)
    agent.sort_order = ind
    agent.save
  end
  resp.success = true
  render :json => resp
end

#contactObject



21
22
23
24
# File 'app/controllers/caboose_rets/agents_controller.rb', line 21

def contact
  @agent = Agent.where(:mls_id => params[:mls_id]).where("office_mls_id ILIKE ?", @site.rets_office_id).first if !params[:mls_id].blank?
  @agent = Agent.where(:slug => params[:slug]).where("office_mls_id ILIKE ?", @site.rets_office_id).first if !params[:slug].blank?
end

#detailsObject



13
14
15
16
17
# File 'app/controllers/caboose_rets/agents_controller.rb', line 13

def details
  @agent = Agent.where(:mls_id => params[:mls_id]).where("office_mls_id ILIKE ?", @site.rets_office_id).first if !params[:mls_id].blank?
  @agent = Agent.where(:slug => params[:slug]).where("office_mls_id ILIKE ?", @site.rets_office_id).first if !params[:slug].blank?
  @listings = Property.where("list_agent_mls_id ILIKE ? OR co_list_agent_mls_id ILIKE ?", @agent.mls_id, @agent.mls_id).where(:status => 'Active').order('list_price desc').all
end

#indexObject



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

def index
  @agents = Agent.where("office_mls_id ILIKE ?",@site.rets_office_id).order(:sort_order).reject{ |a| (a.meta && a.meta.hide == true) }
end