Created
March 20, 2013 21:15
-
-
Save sjungling/5208510 to your computer and use it in GitHub Desktop.
un-class-ified index for wishlists:index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.6.1 | |
jQuery(function($) { | |
var changeList, copyItem, createList, deleteItem, deleteList, node, updateProductInfo, updateUserInfo; | |
updateUserInfo = function() { | |
console.log("updateUserInfo called"); | |
return $.ajax({ | |
url: '/index.cfm?page=wishlists:user_info&fmt=pjax', | |
success: function(res) { | |
return $('#user-info').replaceWith(res); | |
} | |
}); | |
}; | |
updateProductInfo = function(listId) { | |
var requestUrl; | |
console.log("updateProductInfo called with WishListID: " + listId); | |
if (listId != null) { | |
requestUrl = "/index.cfm?page=wishlists:products&id=" + listId + "&fmt=pjax"; | |
} else { | |
requestUrl = "/index.cfm?page=wishlists:products&fmt=pjax"; | |
} | |
return $.ajax({ | |
url: requestUrl, | |
success: function(res) { | |
return $('#list-info').replaceWith(res); | |
} | |
}); | |
}; | |
deleteItem = function(e) { | |
var listId, productId; | |
console.log("deleteItem called"); | |
e.preventDefault(); | |
productId = $(e.currentTarget).data('wishlistproductid'); | |
listId = $('#list-info').data('wishlistid'); | |
return $.ajax({ | |
url: '/index.cfm?page=wishlists:deleteProductById&fmt=json', | |
type: 'POST', | |
dataType: 'json', | |
data: { | |
wishlistId: listId, | |
wishlistProductID: productId | |
}, | |
success: function(res) { | |
console.log("Successfully removed item " + listId + " from list"); | |
return updateProductInfo(listId); | |
}, | |
error: function(res) { | |
return console.error('Unable to remove item from list'); | |
} | |
}); | |
}; | |
deleteList = function(e) { | |
var currentWishlist, wishlistid; | |
console.log("deleteList called"); | |
e.preventDefault(); | |
wishlistid = $(e.currentTarget).data('wishlistid'); | |
currentWishlist = $('#list-info').data('wishlistid'); | |
return $.ajax({ | |
url: '/index.cfm?page=wishlists:deleteWishlist&fmt=json', | |
type: 'POST', | |
dataType: 'json', | |
data: { | |
wishlistID: wishlistid | |
}, | |
success: function(res) { | |
console.log('Successfully removed list'); | |
if (wishlistid !== currentWishlist) { | |
return updateUserInfo(); | |
} else { | |
updateUserInfo(); | |
return updateProductInfo(); | |
} | |
}, | |
error: function(res) { | |
return console.error('Unable to remove list'); | |
} | |
}); | |
}; | |
createList = function(e) { | |
var createForm, wishlistName; | |
console.log("createList called"); | |
e.preventDefault(); | |
createForm = $(e.currentTarget); | |
wishlistName = $('#wishlist-new'); | |
if (wishlistName.attr('value') !== "") { | |
return $.ajax({ | |
url: '/index.cfm?page=wishlists:createWishlist&fmt=json', | |
type: 'POST', | |
dataType: 'json', | |
data: createForm.serialize(), | |
success: function(res) { | |
createForm[0].reset(); | |
return updateUserInfo(); | |
}, | |
error: function(res) { | |
return console.error('Could not create new list'); | |
} | |
}); | |
} else { | |
console.error('No value'); | |
return false; | |
} | |
}; | |
changeList = function(e) { | |
console.log("changeList called"); | |
e.preventDefault(); | |
return updateProductInfo($(e.currentTarget).data('wishlistid')); | |
}; | |
copyItem = function(e) { | |
var productId, target, wishListMenu; | |
console.log("Copy Item"); | |
target = $(e.currentTarget); | |
productId = target.data('wishlistproductid'); | |
return wishListMenu = new WishListCopyMenu($('#wishlist-menu')); | |
}; | |
console.log("Setting up Listeners"); | |
node = $('#wishlists'); | |
node.on('click', '.delete-item', deleteItem); | |
node.on('click', '.delete-list', deleteList); | |
node.on('submit', '#wishlist-create', createList); | |
node.on('click', '.select-list', changeList); | |
return node.on('click', '.copy-item', copyItem); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment