Class: CabooseRets::AgentsController

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

Instance Method Summary collapse

Instance Method Details

#admin_assistant_to_optionsObject

GET /admin/agents/assistant-to-options



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/caboose_rets/agents_controller.rb', line 131

def admin_assistant_to_options
  options = [{
    'value' => '',
    'text' => '-- Not an assistant --'
  }]
  Agent.where(:office_mls_id => '46').reorder('last_name, first_name').all.each do |a|
    options << {
      'value' => a.mls_id,
      'text' => "#{a.first_name} #{a.last_name}"
    }
  end
  render :json => options
end

#admin_editObject

GET /admin/agents/:id/edit



61
62
63
64
65
66
# File 'app/controllers/caboose_rets/agents_controller.rb', line 61

def admin_edit
  return if !user_is_allowed('agents', 'edit')
  @agent = Agent.find(params[:id])
  @boss = @agent.assistant_to.nil? || @agent.assistant_to.strip.length == 0 ? nil : Agent.where(:mls_id => @agent.assistant_to).first
  render :layout => 'caboose/admin'
end

#admin_edit_bioObject

GET /admin/agents/:id/edit-bio



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

def admin_edit_bio
  return if !user_is_allowed('agents', 'edit')
  @agent = Agent.find(params[:id])
  render :layout => 'caboose/admin'
end

#admin_edit_contact_infoObject

GET /admin/agents/:id/edit-contact-info



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

def admin_edit_contact_info
  return if !user_is_allowed('agents', 'edit')
  @agent = Agent.find(params[:id])
  render :layout => 'caboose/admin'
end

#admin_edit_mls_infoObject

GET /admin/agents/:id/edit-mls-info



83
84
85
86
87
# File 'app/controllers/caboose_rets/agents_controller.rb', line 83

def admin_edit_mls_info
  return if !user_is_allowed('agents', 'edit')
  @agent = Agent.find(params[:id])
  render :layout => 'caboose/admin'
end

#admin_indexObject

GET /admin/agents



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/caboose_rets/agents_controller.rb', line 41

def admin_index
  return if !user_is_allowed('agents', 'view')

  @gen = Caboose::PageBarGenerator.new(params, {
      'office_mls_id'   => '',
      'mls_id'          => '',
      'first_name_like' => '',
      'last_name_like'  => ''
    },{
      'model'       => 'CabooseRets::Agent',
      'sort'        => 'last_name, first_name',
      'desc'        => false,
      'base_url'    => '/admin/agents',
      'use_url_params'  => false
  })
  @agents = @gen.items
  render :layout => 'caboose/admin'
end

#admin_refreshObject

GET /admin/agents/:id/refresh



123
124
125
126
127
128
# File 'app/controllers/caboose_rets/agents_controller.rb', line 123

def admin_refresh
  agent = Agent.find(params[:id])
  RetsImporter.import("(LA_LA_CODE=#{agent.mls_id})", 'Agent', 'AGT')
  RetsImporter.download_agent_images(agent)
  render :json => Caboose::StdClass.new({ 'success' => "The agent's info has been updated from MLS." })
end

#admin_updateObject

POST /admin/agents/:id



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/caboose_rets/agents_controller.rb', line 90

def admin_update
  Caboose.log(params)
  return if !user_is_allowed('agents', 'edit')

  resp = Caboose::StdClass.new({'attributes' => {}})
  agent = Agent.find(params[:id])

  save = true
  params.each do |name,value|
    case name
      when 'hide'
        agent.hide = value
      when 'contact_info'
        agent.contact_info = value
      when 'bio'
        agent.bio = value
      when 'designation'
        agent.designation = value
      when 'assistant_to'
        agent.assistant_to = value
        if !value.nil? && value.length > 0 && Agent.exists?(:mls_id => value)
          boss = Agent.where(:mls_id => value).first
          resp.attributes['assistant_to'] = { 'text' => "#{boss.first_name} #{boss.last_name}" }
        else
          resp.attributes['assistant_to'] = { 'text' => "Not an assistant" }
        end
    end
  end
  resp.success = save && agent.save
  render :json => resp
end

#agent_optionsObject

GET /admin/agents/agent_options



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/controllers/caboose_rets/agents_controller.rb', line 146

def agent_options
  options = [{
    'value' => '',
    'text' => '-- No Agent --'
  }]
  Agent.where(:office_mls_id => '46').reorder('last_name, first_name').all.each do |a|
    options << {
      'value' => a.mls_id,
      'text' => "#{a.first_name} #{a.last_name}"
    }
  end
  render :json => options
end

#detailsObject

GET /agents/:mls_id



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

def details
  mls_id = params[:mls_id]
  @agents = Agent.where("mls_id = '46'").order("last_name, first_name")
  @agent = Agent.where(:mls_id => mls_id).first || Agent.where(:mls_id => '048540000').first      
  # @assistants = Agent.where(:assistant_to => la_code).order("last_name, first_name")
  @next = Agent.where("\'mls_id\' > \'#{mls_id}\' AND \'mls_id\' <> \'048540000\' AND \'office_mls_id\' = \'46\'").order("last_name, first_name").first
  @prev = Agent.where("\'mls_id\' < \'#{mls_id}\' AND \'mls_id\' <> \'048540000\' AND \'office_mls_id\' = \'46\'").order("last_name, first_name").first
end

#indexObject

GET /agents



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

def index
  @agents     = Agent.where("office_mls_id = '46' ").order("last_name, first_name")
  @agent      = Agent.where(:mls_id => '048540000').first
  @assistants = Agent.where(:assistant_to => '048540000').order("last_name, first_name")
end

#listingsObject

GET /agents/:mls_id/listings



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/caboose_rets/agents_controller.rb', line 23

def listings
  @agent = Agent.where(:mls_id => params[:mls_id]).first
  is_agents = "mls_id = ? AND status = 'Active'"
  # is_coagents = "co_la_code = ? AND status = 'Active'"

  properties = Property.where(is_agents, params[:mls_id])
  # residential_properties += Property.where(is_coagents, params[:mls_id]).select{ |p| defined? p && p.mls_acct }

  @property_groups = [
    { type: 'Listing' , title: 'Property Listings' , url_prefix: 'properties' , properties: properties }        
  ]
end