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=fa2748b94d4e22de4be4152ab050400be7846da0;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..fa2748b9
--- /dev/null
+++ b/portal/static/unbound_reservation_static/js/createpost__.js
@@ -0,0 +1,121 @@
+$(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);
+ });
+ // AJAX for posting
+ function create_post(jsondata, user_data) {
+ $("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(jsondata);
+ $.ajax({
+ url : "create_post/", // the endpoint
+ type : "POST", // http method
+ data : {"name" : user_data, "body" : JSON.stringify(obj)}, // data sent with the post request
+ // handle a successful response
+ complete:function(){
+ //alert("Request completed");
+ $("#but").hide();
+ $("button").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+""+
+ //"