X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Funbound_reservation_static%2Fjs%2Fcreatepost.js;fp=portal%2Fstatic%2Funbound_reservation_static%2Fjs%2Fcreatepost.js;h=fbf547912e0e9b6f3c684e584bbeae794493418a;hb=729a9dbb380b51a217194ba2a4e5978186fe50b0;hp=0000000000000000000000000000000000000000;hpb=c4bd5da6e2630eddf1262aa8d808dbb48b097d53;p=unfold.git diff --git a/portal/static/unbound_reservation_static/js/createpost.js b/portal/static/unbound_reservation_static/js/createpost.js new file mode 100644 index 00000000..fbf54791 --- /dev/null +++ b/portal/static/unbound_reservation_static/js/createpost.js @@ -0,0 +1,130 @@ +$(function() { + + + // Submit post on submit + // $('#b1').bind('click', function(event){ + // event.preventDefault(); + // console.log("form submitted!") // sanity check + // create_post(); + // }); + +$('#b1').bind('click', function(event){ + event.preventDefault(); + console.log("form submitted!") // sanity check + jsondata=document.getElementById("jsondata").value; + user_data=document.getElementById("user_slices").value; + create_post(jsondata, user_data,1); + }); + $('#b2').bind('click', function(event){ + event.preventDefault(); + console.log("form submitted!") // sanity check + //jsondata=document.getElementById("jsondata").value; + //user_data=document.getElementById("user_slices").value; + create_post(jsondata, user_data,2); + }); + // AJAX for posting + function create_post(jsondata, user_data,b) { + + $("button").hide(300); + $("#but").show(6000); + $('#but').html(' loading...'); + console.log("create post is working!") +console.log(JSON.stringify(jsondata)); +var obj = jQuery.parseJSON(jsondata); +console.log(JSON.stringify(obj)); + // sanity check + var myEvent = {"resources":[{"type": "Node"},{"type": "Node"}]}; + console.log(JSON.stringify(myEvent)); + //jsondata=JSON.parse(JSON.parse(json).jsondata); + jsondata=jsondata.replace("\\", ""); + console.log(obj); + $.ajax({ + url : "create_post/", // the endpoint + type : "POST", // http method + data : {"name" : user_data, "mitsos" : JSON.stringify(obj), "b": b}, // data sent with the post request + // handle a successful response + complete:function(){ + //alert("Request completed"); + $("#but").hide(); + $("button").show(); + $("#b2").show(); + }, + success : function(data,status) { + + console.log(data,status); // log the returned json to the console + + var obj = JSON.parse(data); + // alert(data); + for (var i = 0; i < obj.resource_response.resources.length; i++) { + var k=i+1; + var m='#'+k; + input_2 = " Node-"+k+""+ + //"