diff options
author | Shweta Chaughule <shwettach@gmail.com> | 2012-04-16 18:04:12 +0530 |
---|---|---|
committer | Shweta Chaughule <shwettach@gmail.com> | 2012-04-16 18:04:12 +0530 |
commit | 39467038c61056769e91e16c80130214c9811ada (patch) | |
tree | 688cd059c80cbc536a43a06506f95cbcfceb05fd /objectapp/static/objectapp/js/savert.js | |
parent | 0aff6c0944e356efd6989093be174180a1a77e93 (diff) | |
download | gnowsys-39467038c61056769e91e16c80130214c9811ada.tar.gz |
Dynamic fomrs created, also files added for them.Property to get type added by Johnson - Shweta and Neeharika ( Citizen Science Group )
Diffstat (limited to 'objectapp/static/objectapp/js/savert.js')
-rw-r--r-- | objectapp/static/objectapp/js/savert.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/objectapp/static/objectapp/js/savert.js b/objectapp/static/objectapp/js/savert.js new file mode 100644 index 00000000..0e1f8b07 --- /dev/null +++ b/objectapp/static/objectapp/js/savert.js @@ -0,0 +1,59 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_submit_rt").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_submit_rt").click(function(){ + left = document.getElementById("id_left") + rt = document.getElementById("id_reltype") + right = document.getElementById("id_right") + absolute_url = document.getElementById("id_back_url") + url = "/objects/dynamicRelation/save/"+ left.value + "/" +rt.value+"/"+right.value+"/" + // alert(url); + $.get(url,function(data){ + window.location.replace(absolute_url.value); + }); + + }); + + }); + + |