diff --git a/korektury/static/korektury/opraf.css b/korektury/static/korektury/opraf.css index ca71548a..1cea3018 100644 --- a/korektury/static/korektury/opraf.css +++ b/korektury/static/korektury/opraf.css @@ -2,6 +2,7 @@ body, .adding{ background: #f3f3f3; color: black; + overflow: auto; } .comitting { @@ -23,6 +24,7 @@ img{background:white;} /*border-bottom-left-radius: 10px; */ border-left: 2px solid yellow; border-bottom: 2px solid yellow; + z-index: 1; } .pointer-done-hi, diff --git a/korektury/static/korektury/opraf.js b/korektury/static/korektury/opraf.js index a6d6244c..b2b6a2d2 100644 --- a/korektury/static/korektury/opraf.js +++ b/korektury/static/korektury/opraf.js @@ -4,54 +4,58 @@ function place_comments_one_div(img_id, comments) if( img == null ) { return; } - var par = img.parentNode; + var par = $(img.parentNode); var w = img.clientWidth; var h = img.clientHeight; var w_skip = 10; var h_skip = 5; - var pointer_min_h = 30; + var pointer_min_h = 10; var bott_max = 0; var comments_sorted = comments.sort(function (a,b) { - return a[2] - b[2]; + return a.y - b.y; //pokus o hezci kladeni poiteru, ale nic moc - if( a[3] < b[3] ) { - return (a[2] + pointer_min_h)- b[2]; + if( a.x < b.x ) { + return (a.y + pointer_min_h)- b.y; } else { - return (a[2] - pointer_min_h)- b[2]; + return (a.y - pointer_min_h)- b.y; } }); //console.log("w:" + w); - for (c in comments_sorted) { - var id = comments_sorted[c][0]; - var x = comments_sorted[c][1]; - var y = comments_sorted[c][2]; + for (var c of comments_sorted) { + var id = c.id; + var x = c.x; + var y = c.y; - var el = document.getElementById(id); - var elp = document.getElementById(id + "-pointer"); + var elp; + var el; + + [elp, el] = create_corr_div(c); if( el == null || elp == null ) { continue; } - - par.appendChild(elp); - par.appendChild(el); + + par.append(elp); + par.append(el); var delta_y = (y > bott_max) ? 0: bott_max - y + h_skip; - elp.style.left = x; - elp.style.top = y ; - elp.style.width = w - x + w_skip; - elp.style.height = pointer_min_h + delta_y; - elp.img_id = img_id; - el.img_id = img_id; + elp.css({ + left: x, + top: y, + width : w - x + w_skip, + height : pointer_min_h + delta_y}); + //elp.img_id = img_id; + //el.img_id = img_id; - el.style.position = 'absolute'; - el.style.left = w + w_skip; - el.style.top = y + delta_y; + el.css({ + position: 'absolute', + left: w + w_skip, + top: y + delta_y}); - var bott = el.offsetTop + el.offsetHeight; + var bott = el.position().top + el.height() + 10; bott_max = ( bott_max > bott ) ? bott_max : bott; //console.log( "par.w:" + par.style.width); @@ -268,3 +272,249 @@ String.prototype.unescapeHTML = function () { ); }; + +$(function() { + + + // This function gets cookie with a given name + 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 = jQuery.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; + } + var csrftoken = getCookie('csrftoken'); + + /* + The functions below will create a header with csrftoken + */ + + function csrfSafeMethod(method) { + // these HTTP methods do not require CSRF protection + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + function sameOrigin(url) { + // test that a given url is a same-origin 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)); + } + + $.ajaxSetup({ + beforeSend: function(xhr, settings) { + if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) { + // Send the token to same-origin, relative URLs only. + // Send the token only if the method warrants CSRF protection + // Using the CSRFToken value acquired earlier + xhr.setRequestHeader("X-CSRFToken", csrftoken); + } + } + }); + +}); + +// AJAX for posting +function create_post(inputs) { + console.log("create post is working!"); // sanity check + console.log(inputs); + var dict = {}; + $.each(inputs,function(i,field){dict[field.name]=field.value}) + $.ajax({ + url : "request/", // the endpoint + type : "POST", // http method + data : dict, // data sent with the post request + + // handle a successful response + success : function(json) { + alert("Success"); + // $('#post-text').val(''); // remove the value from the input + console.log(json); // log the returned json to the console + console.log("success"); // another sanity check + }, + + // handle a non-successful response + error : function(xhr,errmsg,err) { + alert("Fail"); + // $('#results').html("