Skip to content

Instantly share code, notes, and snippets.

@quirkey
Forked from mrb/gist:102144
Created April 26, 2009 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save quirkey/102161 to your computer and use it in GitHub Desktop.
Save quirkey/102161 to your computer and use it in GitHub Desktop.
var Favorite = {
client_name: "",
client_id: "",
user_id: "",
add_or_remove: "",
getID: function(params){
this.client_name = params.attr("client_name");
this.client_id = params.attr("client_id");
this.user_id = params.attr("user_id");
this.add_or_remove = params.attr("add_or_remove");
},
post_action: function(params){
this.getID(params);
var fav = this;
$.post('/users/'+this.user_id+'/'+this.add_or_remove+'_favorites.js',
{
id: this.user_id,
authenticity_token: token,
client_id: this.client_id
},
function(data) {
fav.update_page.apply(fav)
});
},
update_page: function(){
$("#flash").text("Favorite Added");
$("#flash").slideDown();
$("#items").prepend("<li class='client' id="+this.client_id+">&nbsp;&nbsp;&nbsp;"+this.client_name+"</li>");
$("#"+this.client_id).show();
}
};
$.extend({
shove: function(fn, object) {
return function() {
return fn.apply(object, arguments);
}
}
});
var Favorite = {
client_name: "",
client_id: "",
user_id: "",
add_or_remove: "",
getID: function(params){
this.client_name = params.attr("client_name");
this.client_id = params.attr("client_id");
this.user_id = params.attr("user_id");
this.add_or_remove = params.attr("add_or_remove");
},
post_action: function(params){
this.getID(params);
$.post('/users/'+this.user_id+'/'+this.add_or_remove+'_favorites.js',
{
id: this.user_id,
authenticity_token: token,
client_id: this.client_id
},
$.shove(this.update_page, this));
},
update_page: function(){
$("#flash").text("Favorite Added");
$("#flash").slideDown();
$("#items").prepend("<li class='client' id="+this.client_id+">&nbsp;&nbsp;&nbsp;"+this.client_name+"</li>");
$("#"+this.client_id).show();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment