Skip to content

Instantly share code, notes, and snippets.

@tuplebunny
Created February 2, 2010 23:27
Show Gist options
  • Save tuplebunny/293167 to your computer and use it in GitHub Desktop.
Save tuplebunny/293167 to your computer and use it in GitHub Desktop.
$('.add_content').live('click', function() {
if(! selected_list) {
alert('Select a list first.');
return;
}
$.ajax({
type: 'POST',
url: '/lists/' + selected_list.attr('list_id') + '/add_content?content_id=' + $(this).attr('content_id') + '&list_id=' + selected_list.attr('list_id'),
dataType: 'json',
success: function(response) {
selected_list.parent().parent().find('.nodes').html(response.html);
selected_list.parent().parent().find('.nodes ul').sortable({
handle: 'span',
update: function() {
$.ajax({
type: 'GET',
url: '/lists/sort/?list_id=' + selected_list.attr('list_id'),
data: $(this).sortable('serialize'),
success: function(response) {
// selected_list.parent().parent().find('.nodes').html(response.html);
},
error: function(response) {
alert('Network/Internet/server error.');
}
});
}
});
}
});
});
$('.delete_link').live('click', function() {
if(! confirm('Delete node and content?')) { return; }
var link = $(this);
$.ajax({
type: 'POST',
url: $(this).attr('href'),
data: '_method=delete&authenticity_token=' + rails_authenticity_token + '&list_id=' + selected_list.attr('list_id'),
success: function(response) {
link.parent().parent().remove();
},
error: function(response) {
alert('Network/Internet/server error.');
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment