/** * JS Url Maps * Maps Django url to callable JS objects, contauns a method for replaceing placegolder args * with real args * Auth: Chris Reeves, POKE, 2010-03-29 */ /** USAGE ===== BASIC ---------------- Each url is degined as a method, for example POKE.url_maps.example() would return a url to www.example.com/example. ADVANCED ---------------- Some urls may require placeholder arguments for django to perform the reverse url method, so we might define this like: {[%] url example1 arg1,arg2 [%]} This script has a method fo swapping placeholder args with the desired correct args, for example: POKE.url_maps.example2 = function(arg1, arg2) { dict = { arg1: { placeholder: 'arg1', arg: arg1 }, arg2: { placeholfer: 'arg2', arg: arg2 } return this.reaplce_holders('{[%] url exaple2 arg1,arg2 [%]}', dict); } } this will return back a url with the corret arguments, you can then call this: POKE.url_maps.example2(21312, 4823); which will return something like: www.example2.com/example2/21312/4823/ Which you can then use in an ajax call There is probably a more eligant way of achieving this, if you think of a way let me know :) Note: django template ({%) tags in these comments are noted as {[%] url [%]} to prevent django from interpreting these as real requests. **/ // URL maps namespace POKE.url_maps = {} // Reaceplace placeholders method // Takes url as 1st arg and dictionary object as second arg POKE.url_maps.replace_holders = function(url, dict) { for(arg in dict) { var obj = dict[arg]; url = url.replace('/' + obj.placeholder + '/', '/' + obj.arg + '/'); } return url; } // Static URL POKE.url_maps.static_url = function() { return 'http://assets.orangerockcorps.fr/cdn/1319016004/static/'; } // Carousel admin function for re-ordering carousel slides, called // on drop of table row firering ajax call to this url which maps to a // django view, this does not have any arguments POKE.url_maps.reorder_carousel_slides = function() { return '/carousel/reorder-slides/'; }