Class: CabooseRets::AgentsController
- Inherits:
-
ApplicationController
- Object
- Caboose::ApplicationController
- ApplicationController
- CabooseRets::AgentsController
- Defined in:
- app/controllers/caboose_rets/agents_controller.rb
Instance Method Summary collapse
- #admin_agent_options ⇒ Object
- #admin_edit ⇒ Object
- #admin_edit_sort ⇒ Object
- #admin_index ⇒ Object
- #admin_json ⇒ Object
- #admin_json_single ⇒ Object
- #admin_update ⇒ Object
- #admin_update_image ⇒ Object
- #admin_update_sort ⇒ Object
- #contact ⇒ Object
- #details ⇒ Object
- #index ⇒ Object
Instance Method Details
#admin_agent_options ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/caboose_rets/agents_controller.rb', line 37 def = [] 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| << { 'value' => c.mls_id, 'text' => "#{c.first_name} #{c.last_name}" } end render :json => end |
#admin_edit ⇒ Object
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. ? @agent. : AgentMeta.create(:la_code => @agent.matrix_unique_id) if @agent render :layout => 'caboose/admin' end |
#admin_edit_sort ⇒ Object
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_index ⇒ Object
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_json ⇒ Object
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_single ⇒ Object
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_update ⇒ Object
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]) = agent. ? agent. : AgentMeta.create(:la_code => agent.matrix_unique_id) params.each do |k,v| case k when "bio" then .bio = v when "slug" then agent.slug = v when "hide" then .hide = v when "weight" then .weight = v when "accepts_listings" then .accepts_listings = v end end agent.save .save resp.success = true render :json => resp end |
#admin_update_image ⇒ Object
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]) = agent. ? agent. : AgentMeta.create(:la_code => agent.matrix_unique_id) if agent .image = params[:image] .save resp.attributes['image'] = { 'value' => .image.url(:thumb) } render :text => resp.to_json end |
#admin_update_sort ⇒ Object
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 |
#contact ⇒ Object
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 |
#details ⇒ Object
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 |
#index ⇒ Object
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. && a..hide == true) } end |