|
|
@ -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("<div class='alert-box alert radius' data-alert>Oops! We have encountered an error: "+errmsg+
|
|
|
|
// " <a href='#' class='close'>×</a></div>"); // add the error to the dom
|
|
|
|
console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
|
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function create_corr_div(corr){ |
|
|
|
/* |
|
|
|
<div onclick='img_click(this,event)' |
|
|
|
id='op{{o.id}}-pointer' |
|
|
|
class='pointer{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}'> |
|
|
|
</div> |
|
|
|
*/ |
|
|
|
var corr_status = ''; |
|
|
|
switch (corr.status){ |
|
|
|
case 'opraveno': |
|
|
|
corr_status='-done'; |
|
|
|
break; |
|
|
|
case 'neni-chyba': |
|
|
|
corr_status='-wontfix'; |
|
|
|
} |
|
|
|
var pointer; |
|
|
|
pointer = $("<div>",{ |
|
|
|
id:'op'+corr.id+'-pointer', |
|
|
|
class: 'pointer'+corr_status, |
|
|
|
onclick: 'img_click(this,event)' |
|
|
|
}); |
|
|
|
|
|
|
|
var all_buttons; |
|
|
|
all_buttons = $('<div>'); |
|
|
|
|
|
|
|
var header; |
|
|
|
header = $('<div>',{class:'corr-header'}).append( |
|
|
|
$('<div>',{class:'author',id:'op'+corr.id+'-autor'}).append(corr.autor), |
|
|
|
all_buttons); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
<div name='op{{o.id}}' id='op{{o.id}}' |
|
|
|
class='box{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}' |
|
|
|
onmouseover='box_onmouseover(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})' |
|
|
|
onmouseout='box_onmouseout(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})'> |
|
|
|
|
|
|
|
<div class='corr-header'> |
|
|
|
<div class='author' id='op{{o.id}}-autor'>{{o.autor}}</div> |
|
|
|
<div class='float-right'> |
|
|
|
<!-- Existujici korektura !--> |
|
|
|
<form class="corr-form" action='' method='POST'> |
|
|
|
{% csrf_token %} |
|
|
|
<input type='hidden' name="au" value="{{o.autor}}"/> |
|
|
|
<input type='hidden' name='pdf' value='{{pdf.id}}'> |
|
|
|
<input type='hidden' name='id' value='{{o.id}}'> |
|
|
|
<input type='hidden' name='scroll'> |
|
|
|
|
|
|
|
{% if o.komentare %} |
|
|
|
<button name='action' value='del' type='button' |
|
|
|
title="Opravu nelze smazat – už ji někdo okomentoval"> |
|
|
|
<img src="{% static "korektury/imgs/delete-gr.png"%}"/> |
|
|
|
</button> |
|
|
|
{% else %} |
|
|
|
<button type='submit' name='action' value='del' title='Smaž opravu'> |
|
|
|
<img src="{% static "korektury/imgs/delete.png"%}"/> |
|
|
|
</button> |
|
|
|
{% endif %} |
|
|
|
|
|
|
|
{% if o.status = 'opraveno' or o.status = 'neni_chyba' %} |
|
|
|
<button type='submit' name='action' value='undone' title='Označ jako neopravené'> |
|
|
|
<img src="{% static "korektury/imgs/undo.png"%}"/> |
|
|
|
</button> |
|
|
|
{% else %} |
|
|
|
<button type='submit' name='action' value='done' title='Označ jako opravené'> |
|
|
|
<img src="{% static "korektury/imgs/check.png"%}"/> |
|
|
|
</button> |
|
|
|
<button type='submit' name='action' value='wontfix' title='Označ jako irelevantní '> |
|
|
|
<img src="{% static "korektury/imgs/cross.png" %}"/> |
|
|
|
</button> |
|
|
|
{% endif %} |
|
|
|
</form> |
|
|
|
<!-- /Existujici korektura !--> |
|
|
|
|
|
|
|
{% if o.komentare %} |
|
|
|
<button type='button' title="Korekturu nelze upravit – už ji někdo okomentoval"> |
|
|
|
<img src="{% static "korektury/imgs/edit-gr.png" %}"/> |
|
|
|
</button> |
|
|
|
{% else %} |
|
|
|
<button type='button' onclick='box_edit(this,"update");' title='Oprav opravu'> |
|
|
|
<img src="{% static "korektury/imgs/edit.png" %}"/> |
|
|
|
</button> |
|
|
|
{% endif %} |
|
|
|
<button type='button' onclick='box_edit(this, "comment");' title='Komentovat'> |
|
|
|
<img src="{% static "korektury/imgs/comment.png" %}"/> |
|
|
|
</button> |
|
|
|
<button type='button' onclick='toggle_visibility(this);' title='Skrýt/Zobrazit'> |
|
|
|
<img src="{% static "korektury/imgs/hide.png" %}"/> |
|
|
|
</button> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> */ |
|
|
|
var body; |
|
|
|
body = $('<div>',{class:'corr-body', id:'op'+corr.id+'-body'}).append( |
|
|
|
$('<div>',{id:'op'+corr.id+'-text'}).append(corr.text) |
|
|
|
); |
|
|
|
/* |
|
|
|
+<div class='corr-body' id='op{{o.id}}-body'> |
|
|
|
+<div id='op{{o.id}}-text'>{{o.text}}</div> |
|
|
|
|
|
|
|
{% for k in o.komentare %} |
|
|
|
<hr> |
|
|
|
<div class='comment' id='k{{k.id}}'> |
|
|
|
<div class='corr-header'> |
|
|
|
<div class='author'>{{k.autor}}</div> |
|
|
|
<div class="float-right"> |
|
|
|
<!-- Komentar !--> |
|
|
|
<form class="corr-form" action='' method='POST'> |
|
|
|
{% csrf_token %} |
|
|
|
<input type='hidden' name='pdf' value='{{pdf.id}}'> |
|
|
|
<input type='hidden' name='id' value='{{k.id}}'> |
|
|
|
<input type='hidden' name='scroll'> |
|
|
|
<button type='submit' name='action' value='del-comment' title='Smaž komentář' |
|
|
|
onclick='return confirm("Opravdu smazat komentář?")'> |
|
|
|
<img src="{% static "korektury/imgs/delete.png" %}"/> |
|
|
|
</button> |
|
|
|
</form> |
|
|
|
<!-- /Komentar !--> |
|
|
|
<button type='button' onclick='update_comment(this);' title='Uprav komentář'> |
|
|
|
<img src="{% static "korektury/imgs/edit.png"%}"/> |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div id='kt{{k.id}}'>{{k.text}}</div> |
|
|
|
</div> |
|
|
|
{% endfor %} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{% endfor %} |
|
|
|
|
|
|
|
*/ |
|
|
|
var corr_div; |
|
|
|
corr_div = $('<div>',{ |
|
|
|
name: corr.id, |
|
|
|
id: corr.id, |
|
|
|
'class': 'box'+corr_status, |
|
|
|
onmouseover: 'box_onmouseover(this,'+(corr_status==''?'\'\'':corr_status)+')', |
|
|
|
onmouseout: 'box_onmouseout(this,'+(corr_status==''?'\'\'':corr_status)+')' |
|
|
|
}).append(header,body) |
|
|
|
return [pointer,corr_div]; |
|
|
|
} |
|
|
|
|
|
|
|
function show_corrections(corrs){ |
|
|
|
var num_pages; |
|
|
|
var pages; |
|
|
|
pages = (corrs.map(function(cur,idx,arr){ |
|
|
|
return cur.strana; |
|
|
|
})); |
|
|
|
|
|
|
|
num_pages = Math.max.apply(null,pages); |
|
|
|
|
|
|
|
for(var i=0;i<num_pages;i++){ |
|
|
|
page_corrs = corrs.filter(function(element,idx,arr){return element.strana==i?1:0}); |
|
|
|
place_comments_one_div('img-'+i,page_corrs); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|