From 39467038c61056769e91e16c80130214c9811ada Mon Sep 17 00:00:00 2001 From: Shweta Chaughule Date: Mon, 16 Apr 2012 18:04:12 +0530 Subject: Dynamic fomrs created, also files added for them.Property to get type added by Johnson - Shweta and Neeharika ( Citizen Science Group ) --- objectapp/static/objectapp/js/noat.js | 51 +++++++++++++++++++++++++ objectapp/static/objectapp/js/saveat.js | 56 ++++++++++++++++++++++++++++ objectapp/static/objectapp/js/savert.js | 59 +++++++++++++++++++++++++++++ objectapp/static/objectapp/js/selectRT.js | 60 ++++++++++++++++++++++++++++++ objectapp/static/objectapp/js/setMember.js | 51 +++++++++++++++++++++++++ objectapp/static/objectapp/js/setdate.js | 45 ++++++++++++++++++++++ 6 files changed, 322 insertions(+) create mode 100644 objectapp/static/objectapp/js/noat.js create mode 100644 objectapp/static/objectapp/js/saveat.js create mode 100644 objectapp/static/objectapp/js/savert.js create mode 100644 objectapp/static/objectapp/js/selectRT.js create mode 100644 objectapp/static/objectapp/js/setMember.js create mode 100644 objectapp/static/objectapp/js/setdate.js (limited to 'objectapp/static') diff --git a/objectapp/static/objectapp/js/noat.js b/objectapp/static/objectapp/js/noat.js new file mode 100644 index 00000000..ef460caa --- /dev/null +++ b/objectapp/static/objectapp/js/noat.js @@ -0,0 +1,51 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_back").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_back").click(function(){ + absolute_url_node = document.getElementById("id_back_url") + window.location.replace(absolute_url_node.value); + }); + + }); + + diff --git a/objectapp/static/objectapp/js/saveat.js b/objectapp/static/objectapp/js/saveat.js new file mode 100644 index 00000000..55e602ac --- /dev/null +++ b/objectapp/static/objectapp/js/saveat.js @@ -0,0 +1,56 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select").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_select").change(function(){ + test = $("#id_select").val().toString() + //url = "/objects/context/test2/?id="+test + url = "/objects/dynamic/save/"+test+"/" + $.get(url, function(data){ + window.location.replace(url); + + }); + }); + + }); + + 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); + }); + + }); + + }); + + diff --git a/objectapp/static/objectapp/js/selectRT.js b/objectapp/static/objectapp/js/selectRT.js new file mode 100644 index 00000000..7dbbcd83 --- /dev/null +++ b/objectapp/static/objectapp/js/selectRT.js @@ -0,0 +1,60 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select_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_select_rt").change(function(){ + relationtype = $(this).val().toString() + left = document.getElementById("id_left") + document.getElementById("id_reltype").value = relationtype + url = "/objects/dynamicRelation/displaymem/"+ relationtype + "/" +left.value+"/" + // alert(url); + $.get(url,function(data){ + $("#id_div1").empty() + $("#id_div1").html(data) + + }); + + }); + + }); + + diff --git a/objectapp/static/objectapp/js/setMember.js b/objectapp/static/objectapp/js/setMember.js new file mode 100644 index 00000000..a71b6750 --- /dev/null +++ b/objectapp/static/objectapp/js/setMember.js @@ -0,0 +1,51 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select_mem").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_select_mem").change(function(){ + right_member = $(this).val() + document.getElementById("id_right").value = right_member; + // alert("hello "+ right_member); + + }); + + }); diff --git a/objectapp/static/objectapp/js/setdate.js b/objectapp/static/objectapp/js/setdate.js new file mode 100644 index 00000000..42cc4dc2 --- /dev/null +++ b/objectapp/static/objectapp/js/setdate.js @@ -0,0 +1,45 @@ +$ = django.jQuery + + $(document).ready(function() { + + $('input[name$="DateField"]').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')); + } + }); + + $('input[name$="DateField"]').datepicker({ dateFormat: "yy-mm-dd",minDate: new Date(1800, 1 - 1, 1), changeYear : true, changeMonth: true }); + }); -- cgit v1.2.3-70-g09d2