Skip to content
Browse files

Adds and removes tracking with ajax.

  • Loading branch information...
1 parent cb33d61 commit 7c6d6bcf7b6782d0f1dd7823a3dc961c98b18384 @adambaker committed Apr 15, 2011
Showing with 45 additions and 0 deletions.
  1. +5 −0 app/views/trails/create.json.erb
  2. +5 −0 app/views/trails/destroy.json.erb
  3. +35 −0 public/javascripts/trail.js
View
5 app/views/trails/create.json.erb
@@ -0,0 +1,5 @@
+{
+ "track": "true",
+ "user_name": "<%= current_user.name %>",
+ "user_path": "<%= user_path current_user %>"
+}
View
5 app/views/trails/destroy.json.erb
@@ -0,0 +1,5 @@
+{
+ "track": "false",
+ "user_name": "<%= current_user.name %>",
+ "user_path": "<%= user_path current_user %>"
+}
View
35 public/javascripts/trail.js
@@ -0,0 +1,35 @@
+$(function()
+ {
+ ajax_submit_button($('form.button_to input.track'),
+ function(trail)
+ {
+ var button;
+ var prev_button;
+ var change;
+ var tracker_list = $('ul.track.trackers');
+
+ if (trail.track == 'false')
+ {
+ button = $('form.button_to input.track[value=Untrack]');
+ prev_button = $('form.button_to input.track[value=Track]');
+ $('li:contains('+trail.user_name+')', tracker_list).detach();
+ change = -1;
+ }
+ else
+ {
+ button = $('form.button_to input.track[value=Track]');
+ prev_button = $('form.button_to input.track[value=Untrack]');
+ user = $('<li></li>')
+ .html('<a href="'+trail.user_path+'">'+trail.user_name+'</a>');
+ change = 1;
+ tracker_list.append(user).removeClass('hidden');
+ }
+ revise_header(tracker_list, change, 'Tracked by ');
+ button.attr('disabled', false);
+ button.hide();
+ prev_button.show();
+ }
+ );
+ }
+);
+

0 comments on commit 7c6d6bc

Please sign in to comment.
Something went wrong with that request. Please try again.