caboose-rets 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 254faba117caf0a31d78445efc80d351b8604cfc
4
- data.tar.gz: e102328e3e15d0b70fc42fbb0d0221f05aa1c329
3
+ metadata.gz: 0bc1dc509dbedeb670087ec95587d543a2770385
4
+ data.tar.gz: 2c9e4966408f300681b39bacb9839d309595a062
5
5
  SHA512:
6
- metadata.gz: b789e6caadc04bbcfb3786148b0493fac621cbdab04337be83d9684b2a3e44b33eabc964df9a23d6af2e9a466f4d0f9002176a26cc7542b07f2cd7dee3921f24
7
- data.tar.gz: f862d4548e70f064e333d2499dce183d713af35a8cd55e8024720115fcaf27ad77245da088c747bdddde3a7f8450034742206c5348032d3c1905d406d52ce723
6
+ metadata.gz: f5f8fe88bc6038c340f13e4784cdbf91e6d4c0a12710ae9c82e07286f0ce1c070a717804f435fb745e878dec54fe92995d3948a753a4046689d0e4cefb7a45b4
7
+ data.tar.gz: c7a33eabf5167212b311b06349c89861ddf090af236ccca1c9e05d235acf7a84197f16bd93e7455ace19afde3eeb70688a98444576392edd394d82f8f930bdb8
@@ -2,160 +2,117 @@
2
2
  module CabooseRets
3
3
  class AgentsController < ApplicationController
4
4
 
5
- # GET /agents
5
+ # @route GET /agents
6
6
  def index
7
- @agents = Agent.where("office_mls_id = '46' ").order("last_name, first_name")
8
- @agent = Agent.where(:mls_id => '048540000').first
9
- @assistants = Agent.where(:assistant_to => '048540000').order("last_name, first_name")
7
+ @agents = Agent.where(:office_mls_id => @site.rets_office_id).order(:sort_order).reject{ |a| (a.meta && a.meta.hide == true) }
10
8
  end
11
9
 
12
- # GET /agents/:mls_id
10
+ # @route GET /agents/:mls_id
13
11
  def details
14
- mls_id = params[:mls_id]
15
- @agents = Agent.where("mls_id = '46'").order("last_name, first_name")
16
- @agent = Agent.where(:mls_id => mls_id).first || Agent.where(:mls_id => '048540000').first
17
- # @assistants = Agent.where(:assistant_to => la_code).order("last_name, first_name")
18
- @next = Agent.where("\'mls_id\' > \'#{mls_id}\' AND \'mls_id\' <> \'048540000\' AND \'office_mls_id\' = \'46\'").order("last_name, first_name").first
19
- @prev = Agent.where("\'mls_id\' < \'#{mls_id}\' AND \'mls_id\' <> \'048540000\' AND \'office_mls_id\' = \'46\'").order("last_name, first_name").first
20
- end
21
-
22
- # GET /agents/:mls_id/listings
23
- def listings
24
12
  @agent = Agent.where(:mls_id => params[:mls_id]).first
25
- is_agents = "mls_id = ? AND status = 'Active'"
26
- # is_coagents = "co_la_code = ? AND status = 'Active'"
27
-
28
- properties = Property.where(is_agents, params[:mls_id])
29
- # residential_properties += Property.where(is_coagents, params[:mls_id]).select{ |p| defined? p && p.mls_acct }
30
-
31
- @property_groups = [
32
- { type: 'Listing' , title: 'Property Listings' , url_prefix: 'properties' , properties: properties }
33
- ]
34
13
  end
35
14
 
36
15
  #=============================================================================
37
16
  # Admin functions
38
17
  #=============================================================================
39
18
 
40
- # GET /admin/agents
19
+ # @route GET /admin/agents
41
20
  def admin_index
42
- return if !user_is_allowed('agents', 'view')
21
+ return unless (user_is_allowed_to 'view', 'agents')
22
+ render :layout => 'caboose/admin'
23
+ end
43
24
 
44
- @gen = Caboose::PageBarGenerator.new(params, {
45
- 'office_mls_id' => '',
46
- 'mls_id' => '',
47
- 'first_name_like' => '',
48
- 'last_name_like' => ''
49
- },{
50
- 'model' => 'CabooseRets::Agent',
51
- 'sort' => 'last_name, first_name',
52
- 'desc' => false,
53
- 'base_url' => '/admin/agents',
54
- 'use_url_params' => false
25
+ # @route GET /admin/agents/json
26
+ def admin_json
27
+ render :json => false and return if !user_is_allowed_to 'view', 'agents'
28
+ where = "(office_mls_id = '#{@site.rets_office_id}')"
29
+ pager = Caboose::Pager.new(params, {
30
+ 'first_name_like' => '',
31
+ 'last_name_like' => ''
32
+ }, {
33
+ 'model' => 'CabooseRets::Agent',
34
+ 'sort' => 'last_name',
35
+ 'desc' => 'false',
36
+ 'base_url' => '/admin/agents',
37
+ 'items_per_page' => 50,
38
+ 'additional_where' => [ (where) ],
55
39
  })
56
- @agents = @gen.items
57
- render :layout => 'caboose/admin'
40
+ render :json => {
41
+ :pager => pager,
42
+ :models => pager.items
43
+ }
58
44
  end
59
45
 
60
- # GET /admin/agents/:id/edit
61
- def admin_edit
62
- return if !user_is_allowed('agents', 'edit')
63
- @agent = Agent.find(params[:id])
64
- @boss = @agent.assistant_to.nil? || @agent.assistant_to.strip.length == 0 ? nil : Agent.where(:mls_id => @agent.assistant_to).first
65
- render :layout => 'caboose/admin'
46
+ # @route GET /admin/agents/:id/json
47
+ def admin_json_single
48
+ render :json => false and return if !user_is_allowed_to 'edit', 'agents'
49
+ prop = Agent.find(params[:id])
50
+ render :json => prop
66
51
  end
67
52
 
68
- # GET /admin/agents/:id/edit-bio
69
- def admin_edit_bio
70
- return if !user_is_allowed('agents', 'edit')
71
- @agent = Agent.find(params[:id])
72
- render :layout => 'caboose/admin'
53
+ # @route GET /admin/agents/edit-sort
54
+ def admin_edit_sort
55
+ if !user_is_allowed_to 'edit', 'agents'
56
+ Caboose.log("invalid permissions")
57
+ else
58
+ @agents = Agent.where(:office_mls_id => @site.rets_office_id).order(:sort_order).all
59
+ render :layout => 'caboose/admin'
60
+ end
73
61
  end
74
62
 
75
- # GET /admin/agents/:id/edit-contact-info
76
- def admin_edit_contact_info
77
- return if !user_is_allowed('agents', 'edit')
78
- @agent = Agent.find(params[:id])
79
- render :layout => 'caboose/admin'
63
+ # @route PUT /admin/agents/update-sort
64
+ def admin_update_sort
65
+ resp = Caboose::StdClass.new
66
+ if !user_is_allowed_to 'edit', 'agents'
67
+ Caboose.log("invalid permissions")
68
+ else
69
+ pa = Agent.find(params[:pa_id])
70
+ pa.sort_order = params[:sort_order]
71
+ pa.save
72
+ resp.success = true
73
+ end
74
+ render :json => resp
80
75
  end
81
76
 
82
- # GET /admin/agents/:id/edit-mls-info
83
- def admin_edit_mls_info
84
- return if !user_is_allowed('agents', 'edit')
77
+ # @route GET /admin/agents/:id
78
+ def admin_edit
79
+ return unless (user_is_allowed_to 'edit', 'agents')
85
80
  @agent = Agent.find(params[:id])
86
- render :layout => 'caboose/admin'
81
+ @agent_meta = @agent.meta ? @agent.meta : AgentMeta.create(:la_code => @agent.matrix_unique_id) if @agent
82
+ render :layout => 'caboose/admin'
87
83
  end
88
84
 
89
- # POST /admin/agents/:id
85
+ # @route PUT /admin/agents/:id
90
86
  def admin_update
91
- Caboose.log(params)
92
- return if !user_is_allowed('agents', 'edit')
93
-
94
- resp = Caboose::StdClass.new({'attributes' => {}})
87
+ return unless (user_is_allowed_to 'edit', 'agents')
88
+ resp = Caboose::StdClass.new
95
89
  agent = Agent.find(params[:id])
96
-
97
- save = true
98
- params.each do |name,value|
99
- case name
100
- when 'hide'
101
- agent.hide = value
102
- when 'contact_info'
103
- agent.contact_info = value
104
- when 'bio'
105
- agent.bio = value
106
- when 'designation'
107
- agent.designation = value
108
- when 'assistant_to'
109
- agent.assistant_to = value
110
- if !value.nil? && value.length > 0 && Agent.exists?(:mls_id => value)
111
- boss = Agent.where(:mls_id => value).first
112
- resp.attributes['assistant_to'] = { 'text' => "#{boss.first_name} #{boss.last_name}" }
113
- else
114
- resp.attributes['assistant_to'] = { 'text' => "Not an assistant" }
115
- end
90
+ meta = agent.meta ? agent.meta : AgentMeta.create(:la_code => agent.matrix_unique_id)
91
+ params.each do |k,v|
92
+ case k
93
+ when "bio" then meta.bio = v
94
+ when "hide" then meta.hide = v
116
95
  end
117
96
  end
118
- resp.success = save && agent.save
97
+ agent.save
98
+ meta.save
99
+ resp.success = true
119
100
  render :json => resp
120
101
  end
121
102
 
122
- # GET /admin/agents/:id/refresh
123
- def admin_refresh
124
- agent = Agent.find(params[:id])
125
- RetsImporter.import("(LA_LA_CODE=#{agent.mls_id})", 'Agent', 'AGT')
126
- RetsImporter.download_agent_images(agent)
127
- render :json => Caboose::StdClass.new({ 'success' => "The agent's info has been updated from MLS." })
128
- end
129
103
 
130
- # GET /admin/agents/assistant-to-options
131
- def admin_assistant_to_options
132
- options = [{
133
- 'value' => '',
134
- 'text' => '-- Not an assistant --'
135
- }]
136
- Agent.where(:office_mls_id => '46').reorder('last_name, first_name').all.each do |a|
137
- options << {
138
- 'value' => a.mls_id,
139
- 'text' => "#{a.first_name} #{a.last_name}"
140
- }
141
- end
142
- render :json => options
104
+ # @route POST /admin/agents/:id/image
105
+ def admin_update_image
106
+ render :json => false and return unless user_is_allowed_to 'edit', 'agents'
107
+ resp = Caboose::StdClass.new({ 'attributes' => {} })
108
+ agent = Agent.find(params[:id])
109
+ meta = agent.meta ? agent.meta : AgentMeta.create(:la_code => agent.matrix_unique_id) if agent
110
+ meta.image = params[:image]
111
+ meta.save
112
+ resp.attributes['image'] = { 'value' => meta.image.url(:thumb) }
113
+ render :text => resp.to_json
143
114
  end
144
115
 
145
- # GET /admin/agents/agent_options
146
- def agent_options
147
- options = [{
148
- 'value' => '',
149
- 'text' => '-- No Agent --'
150
- }]
151
- Agent.where(:office_mls_id => '46').reorder('last_name, first_name').all.each do |a|
152
- options << {
153
- 'value' => a.mls_id,
154
- 'text' => "#{a.first_name} #{a.last_name}"
155
- }
156
- end
157
- render :json => options
158
- end
159
116
 
160
117
  end
161
118
  end
@@ -1,9 +1,9 @@
1
1
  class CabooseRets::Agent < ActiveRecord::Base
2
2
  self.table_name = "rets_agents"
3
3
 
4
- has_one :meta, :class_name => 'AgentMeta', :primary_key => 'matrix_unique_id', :foreign_key => 'matrix_unique_id'
4
+ has_one :meta, :class_name => 'AgentMeta', :primary_key => 'matrix_unique_id', :foreign_key => 'la_code'
5
5
  has_many :properties
6
- attr_accessible :id, :agent_number, :matrix_unique_id
6
+ attr_accessible :id, :agent_number, :matrix_unique_id, :sort_order
7
7
  after_initialize :fix_name
8
8
 
9
9
  def image
@@ -3,10 +3,12 @@ class CabooseRets::AgentMeta < ActiveRecord::Base
3
3
  self.table_name = "rets_agents_meta"
4
4
  belongs_to :agent, :foreign_key => 'matrix_unique_id', :primary_key => 'la_code'
5
5
  has_attached_file :image,
6
- :path => 'rets/agents/:la_code_:style.:extension',
6
+ :path => 'rets/agent_meta/:id_:style.:extension',
7
+ :default_url => "https://cabooseit.s3.amazonaws.com/assets/shared/default_profile.png",
7
8
  :styles => {
8
- :thumb => '100x150>',
9
- :large => '200x300>'
9
+ :thumb => '300x300>',
10
+ :medium => '600x600>',
11
+ :large => '900x900>'
10
12
  }
11
13
  do_not_validate_attachment_file_type :image
12
14
  attr_accessible :id,
@@ -9,7 +9,8 @@ class CabooseRets::Media < ActiveRecord::Base
9
9
  :styles => {
10
10
  :tiny => '160x120>',
11
11
  :thumb => '400x300>',
12
- :large => '640x480>'
12
+ :large => '640x480>',
13
+ :huge => '1200x1200>'
13
14
  }
14
15
  do_not_validate_attachment_file_type :image
15
16
  attr_accessible :date_modified, :file_name, :media_id, :media_order, :media_remarks, :media_type, :mls, :url
@@ -239,7 +239,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
239
239
  self.log "Saving images for #{p.matrix_unique_id}..."
240
240
  begin
241
241
  # url = "http://rets.wamls.mlsmatrix.com/rets/GetObject.ashx?Type=Photo&Resource=Property&ID=1026514:1"
242
- self.client.get_object(:resource => 'Property', :type => 'Photo', :location=> false, :id => "#{p.matrix_unique_id}:*") do |headers, content|
242
+ self.client.get_object(:resource => 'Property', :type => 'LargePhoto', :location=> false, :id => "#{p.matrix_unique_id}:*") do |headers, content|
243
243
  m = CabooseRets::Media.where(:media_mui => headers['content-id'], :media_order => headers['object-id']).first
244
244
  m = CabooseRets::Media.new if m.nil?
245
245
 
@@ -532,7 +532,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
532
532
  self.unlock_task_if_last_updated(task_started)
533
533
  end
534
534
 
535
- # Start the same update process in five minutes
535
+ # Start the same update process in 20 minutes
536
536
  self.log2("Adding the update rets task for 20 minutes from now...")
537
537
  q = "handler like '%update_rets%'"
538
538
  count = Delayed::Job.where(q).count
@@ -7,19 +7,19 @@ class CabooseRets::RetsPlugin < Caboose::CaboosePlugin
7
7
 
8
8
  item = {
9
9
  'id' => 'rets',
10
- 'text' => 'RETS',
10
+ 'text' => 'Real Estate',
11
11
  'children' => [],
12
12
  'modal' => true
13
13
  }
14
- item['children'] << { 'id' => 'agents' , 'href' => '/admin/agents' , 'text' => 'Agents' , 'modal' => false }
15
- item['children'] << { 'id' => 'offices' , 'href' => '/admin/offices' , 'text' => 'Offices' , 'modal' => false }
16
- item['children'] << { 'id' => 'open-houses' , 'href' => '/admin/open-houses' , 'text' => 'Open Houses' , 'modal' => false }
17
- item['children'] << { 'id' => 'residential' , 'href' => '/admin/residential' , 'text' => 'Residential Property' , 'modal' => false }
18
- item['children'] << { 'id' => 'commercial' , 'href' => '/admin/commercial' , 'text' => 'Commercial Property' , 'modal' => false }
19
- item['children'] << { 'id' => 'commercial' , 'href' => '/admin/multi-family' , 'text' => 'Multi-Family Property' , 'modal' => false }
20
- item['children'] << { 'id' => 'land' , 'href' => '/admin/land' , 'text' => 'Land Property' , 'modal' => false }
21
- item['children'] << { 'id' => 'saved-properties' , 'href' => '/saved-properties' , 'text' => 'Saved Properties' , 'modal' => false }
22
- item['children'] << { 'id' => 'saved-searches' , 'href' => '/saved-searches' , 'text' => 'Saved Searches' , 'modal' => false }
14
+ item['children'] << { 'id' => 'agents', 'icon' => 'users', 'href' => '/admin/agents' , 'text' => 'Agents' , 'modal' => false }
15
+ # item['children'] << { 'id' => 'offices' , 'href' => '/admin/offices' , 'text' => 'Offices' , 'modal' => false }
16
+ # item['children'] << { 'id' => 'open-houses' , 'href' => '/admin/open-houses' , 'text' => 'Open Houses' , 'modal' => false }
17
+ # item['children'] << { 'id' => 'residential' , 'href' => '/admin/residential' , 'text' => 'Residential Property' , 'modal' => false }
18
+ # item['children'] << { 'id' => 'commercial' , 'href' => '/admin/commercial' , 'text' => 'Commercial Property' , 'modal' => false }
19
+ # item['children'] << { 'id' => 'commercial' , 'href' => '/admin/multi-family' , 'text' => 'Multi-Family Property' , 'modal' => false }
20
+ # item['children'] << { 'id' => 'land' , 'href' => '/admin/land' , 'text' => 'Land Property' , 'modal' => false }
21
+ # item['children'] << { 'id' => 'saved-properties' , 'href' => '/saved-properties' , 'text' => 'Saved Properties' , 'modal' => false }
22
+ # item['children'] << { 'id' => 'saved-searches' , 'href' => '/saved-searches' , 'text' => 'Saved Searches' , 'modal' => false }
23
23
 
24
24
  nav << item
25
25
 
@@ -33,7 +33,8 @@ class CabooseRets::Schema < Caboose::Utilities::Schema
33
33
  [ :phone_toll_free , :text ],
34
34
  [ :phone_voice_mail , :text ],
35
35
  [ :photo_count , :text ],
36
- [ :photo_modification_timestamp , :text ]
36
+ [ :photo_modification_timestamp , :text ],
37
+ [ :sort_order , :integer ]
37
38
  ],
38
39
  CabooseRets::AgentMeta => [
39
40
  [ :la_code , :string ],
@@ -1,15 +1,72 @@
1
1
  <h1>Edit Agent</h1>
2
- <%= render :partial => 'caboose_rets/agents/admin_top_nav' %>
3
2
 
4
- <div id='agent_<%= @agent.id %>_hide' ></div>
5
- <div id='agent_<%= @agent.id %>_assistant_to' ></div>
6
- <div id='agent_<%= @agent.id %>_designation' ></div>
3
+ <p class="fixed">
4
+ <span class="title">First Name</span>
5
+ <span class="value"><%= @agent.first_name %></span>
6
+ </p>
7
7
 
8
- <p style='clear: both;'><input type='button' value='< Back' onclick="window.location='/admin/agents';" /></p>
8
+ <p class="fixed">
9
+ <span class="title">Last Name</span>
10
+ <span class="value"><%= @agent.last_name %></span>
11
+ </p>
12
+ <p class="fixed">
13
+ <span class="title"><%= 'email'.titleize %></span>
14
+ <span class="value"><%= @agent.email %></span>
15
+ </p>
16
+ <p class="fixed">
17
+ <span class="title"><%= 'cell_phone'.titleize %></span>
18
+ <span class="value"><%= @agent.cell_phone %></span>
19
+ </p>
20
+ <p class="fixed">
21
+ <span class="title"><%= 'office_phone'.titleize %></span>
22
+ <span class="value"><%= @agent.office_phone %></span>
23
+ </p>
24
+ <p class="fixed">
25
+ <span class="title"><%= 'direct_work_phone'.titleize %></span>
26
+ <span class="value"><%= @agent.direct_work_phone %></span>
27
+ </p>
28
+ <p class="fixed">
29
+ <span class="title"><%= 'fax_phone'.titleize %></span>
30
+ <span class="value"><%= @agent.fax_phone %></span>
31
+ </p>
32
+ <p class="fixed">
33
+ <span class="title">MLS ID</span>
34
+ <span class="value"><%= @agent.mls_id %></span>
35
+ </p>
36
+
37
+
38
+ <div id="agent_<%= @agent.id %>_hide"></div>
39
+
40
+ <div class="richtext-holder">
41
+ <h5>Bio</h5>
42
+ <div id="agent_<%= @agent.id %>_bio"></div>
43
+ </div>
44
+
45
+ <div id="agent_<%= @agent.id %>_image"></div>
46
+
47
+ <div id="message"></div>
48
+
49
+ <% content_for :caboose_css do %>
50
+ <style>
51
+ p.fixed span.title {
52
+ font-weight: bold;
53
+ }
54
+ span.title::after {
55
+ content: ":";
56
+ }
57
+ .richtext-holder {
58
+ margin: 20px 0;
59
+ }
60
+ .richtext-holder h5 {
61
+ font-size: 1.1em;
62
+ margin: 0 0 5px 0;
63
+ }
64
+ </style>
65
+ <% end %>
9
66
 
10
67
  <% content_for :caboose_js do %>
11
68
  <%= javascript_include_tag "caboose/model/all" %>
12
- <script type='text/javascript'>
69
+ <script type="text/javascript">
13
70
  $(document).ready(function() {
14
71
  m = new ModelBinder({
15
72
  name: 'Agent',
@@ -17,14 +74,12 @@ $(document).ready(function() {
17
74
  update_url: '/admin/agents/<%= @agent.id %>',
18
75
  authenticity_token: '<%= form_authenticity_token %>',
19
76
  attributes: [
20
- { name: 'hide' , nice_name: 'Hide from website' , type: 'checkbox' , value: <%= raw @agent.hide %>, width: 400 },
21
- { name: 'assistant_to' , nice_name: 'Assistant To' , type: 'select' , value: <%= raw Caboose.json(@agent.assistant_to) %>, width: 400, text: <%= raw Caboose.json(@boss ? "#{@boss.first_name} #{@boss.last_name}" : 'empty') %>, options_url: '/admin/agents/assistant-to-options', empty_text: 'Not an assistant' },
22
- { name: 'designation' , nice_name: 'Designation' , type: 'text' , value: <%= raw Caboose.json(@agent.designation) %>, width: 400 }
77
+ { name: 'hide', nice_name: 'Hide', type: 'checkbox', value: <%== Caboose.json(@agent_meta.hide) %>, width: 500, height: 300 },
78
+ { name: 'bio', nice_name: 'Bio', type: 'richtext', value: <%== Caboose.json(@agent_meta.bio) %>, width: 500, height: 300 },
79
+ { name: 'image' , nice_name: 'Image' , type: 'image' , value: <%= raw Caboose.json(@agent_meta.image ? @agent_meta.image.url(:thumb) : 'http://placehold.it?300x300') %>, width: 800, update_url: '/admin/agents/<%= @agent.id %>/image' }
23
80
  ]
24
- });
25
- });
26
- $(window).load(function() {
27
- var modal = new CabooseModal(800);
81
+ });
28
82
  });
29
83
  </script>
30
- <% end %>
84
+ <%== caboose_tinymce %>
85
+ <% end %>
@@ -0,0 +1,82 @@
1
+ <h1>Edit Sort Order</h1>
2
+
3
+ <a href="/admin/agents" class="caboose-btn">Back to Agents</a>
4
+
5
+
6
+ <ul class="sortable" id="sortable_agents">
7
+
8
+ <% @agents.each do |agent| %>
9
+
10
+ <li class="clearfix ui-state-default" data-paid="<%= agent.id %>">
11
+ <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
12
+ <span class="resource-title"><%= agent.full_name %></span>
13
+ </li>
14
+
15
+ <% end %>
16
+ </ul>
17
+
18
+ <% content_for :caboose_css do %>
19
+ <%= stylesheet_link_tag "jquery-ui/sortable" %>
20
+ <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
21
+ <style>
22
+ .sortable {
23
+ list-style-type: none;
24
+ padding-left: 0;
25
+ }
26
+ .sortable li {
27
+ cursor: ns-resize;
28
+ width: 800px;
29
+ padding: 3px 6px;
30
+ }
31
+ .sortable li a {
32
+ color: #0357FF;
33
+ font-size: 14px;
34
+ }
35
+ .sortable li a:hover {
36
+ text-decoration: underline;
37
+ }
38
+ .ui-state-default .ui-icon {
39
+ display: inline-block;
40
+ }
41
+ </style>
42
+ <% end %>
43
+
44
+ <% content_for :caboose_js do %>
45
+ <script>
46
+ function change_sort_order(pa_id, sort_order) {
47
+ $.ajax({
48
+ url: '/admin/agents/update-sort',
49
+ type: 'put',
50
+ data: {
51
+ pa_id: pa_id,
52
+ sort_order: sort_order
53
+ },
54
+ success: function(resp) {
55
+ if (resp.success) {
56
+
57
+ }
58
+ }
59
+ });
60
+ }
61
+ $(document).ready(function() {
62
+
63
+ $.each( $(".sortable"), function(k,v) {
64
+ var sort = $(v);
65
+ sort.sortable({
66
+ update: function(event, ui) {
67
+ var index = ui.item.index();
68
+ var start = ui.item.data('start');
69
+ var pa = ui.item.data('paid');
70
+ for(var i=0;i <= sort.find("li").length; i++){
71
+ var res = sort.find('li:nth-child(' + i + ')').data('paid');
72
+ if (res)
73
+ change_sort_order(res, i);
74
+ }
75
+ }
76
+ });
77
+
78
+ });
79
+
80
+ });
81
+ </script>
82
+ <% end %>