Commit 7697b5da authored by Baptiste Mouterde's avatar Baptiste Mouterde Committed by ikoalaz
Browse files

comment: remove console.log and add try/catch for useful one

add test for old browser, in order to know if we have to use the no-js version
parent 1a65b526
......@@ -82,21 +82,19 @@ function highlight(event) {
$("#L" + start + "S").addClass("hover");
return
}
console.log("loop start at " + start + " and should end at " + stop)
$('.hover').removeClass('hover');
while (start <= stop) {
console.log("now on " + start);
$("#L" + start + "S").addClass("hover");
start++
}
$("#L" + stop + "S").focus()
}
function comment_form(id, post_url, reload_url, package_version_id, filename, parent) {
console.log('parent is ' + parent)
var reload_comments = load_reload(id, package_version_id, reload_url, filename)
function onSuccess(result) {
$(result).insertAfter('#comment_fs' + id)
$('#comment_fs' + id).html(result);
$('#comment_fs' + id).fadeOut(5000);
reload_comments(package_version_id)
}
......@@ -115,12 +113,15 @@ function comment_form(id, post_url, reload_url, package_version_id, filename, pa
// sending a dict to python here
data:{revision:package_version_id, file:filename, type:type, title:title, content:comment, start:start, stop:stop, parent:parent},
success:function (result) {
console.log('comment posted')
onSuccess(result)
},
error:function (xhr, ajaxOptions, thrownError) {
console.log('comment failed!')
console.log(xhr.status);
try {
console.log(xhr.status)
}
catch (exception) {
alert(xhr.status)
}
}
});
});
......@@ -135,7 +136,6 @@ function comment_result(result, id) {
}
function load_reload(id, package_version_id, url, filename) {
function reload_comments(package_version_id) {
console.log('called reload_comments with ' + package_version_id);
// doing the refresh of this with an ajax request
if (filename == "") {
var data = {id:id, package_version_id:package_version_id}
......@@ -149,28 +149,88 @@ function load_reload(id, package_version_id, url, filename) {
dataType:'json',
data:data,
success:function (result) {
console.log('comments reloaded')
$('#comments' + id).html(result)
},
error:function (xhr, ajaxOptions, thrownError) {
console.log('request failed')
console.log(xhr.status);
try {
console.log(xhr.status);
}
catch (exception) {
alert(xhr.status);
}
}
});
}
return reload_comments
}
function init_js() {
//testing js function : unbind / preventdefault / ajax
// first prevent default :
try {
$(document).add("<a class='test' id='test_prevent_default'></>");
$('#test_prevent_default').preventDefault();
if ($('#test_prevent_default').isPReventDefault()) {
//this won't work, give up and load non-js version
try {
console.log('preventdefault isn\'t working giving up on js version')
}
catch (exception) {
$('#superheader').insertBefore("<div class='info'>preventdefault is'nt working loading no js version</div>")
}
return false
}
}
catch (exception) {
$('#superheader').insertBefore("<div class='info'>preventdefault is'nt working loading no js version: " + exception + "</div>")
}
//tresting unbind function
try {
$(document).add("<div class='test' id='test_unbind'></div>_")
$('#test_unbind').hover(function () {
alert('nothing to do here')
})
$('#test_unbind').unbind('hover');
if ($('#test_unbind').type == 'hover') {
//this won't work, post will be double aborting
try {
console.log('unbind isn\'t working giving up on js version')
}
catch (exception) {
$('#superheader').insertBefore("<div class='info'>unbind is'nt working loading no js version</div>")
}
return false
}
}
catch (exception) {
$('#superheader').insertBefore("<div class='info'>unbind is'nt working loading no js version: " + exception + "</div>")
}
//testing ajax
return jQuery.ajax;
}
function comments(id, reload_comment_url, comment_url, score_ajax_url, package_version_id, filename) {
if (init_js()) {
//removing test and non js version
$('.test,.no-js').remove();
$('.debexup ,.debexdown,.answer').show();
}
else {
//this won't work removing the comment side panel, it's sad..
$('.answer,.debexup,.debexdown').remove();
return false
}
var reload_comments = load_reload(id, package_version_id, reload_comment_url, filename)
$(".answer." + id).click(function () {
$($("#form" + id).html()).insertAfter($(this).parent().parent().parent().parent())
$("#send" + id).off('click');
console.log(package_version_id)
//$($("#form" + id).html()).insertAfter($(this).parent().parent().parent().parent())
$("#send" + id).unbind('click');
comment_form(id, comment_url, reload_comment_url, package_version_id, filename, this.value)
})
$(".debexup." + id).click(function (evt) {
evt.preventDefault()
evt.preventDefault();
var comment_id = this.id.match(/\d+/)[0];
jQuery.ajax({
type:'POST',
......@@ -179,13 +239,16 @@ function comments(id, reload_comment_url, comment_url, score_ajax_url, package_v
// sending a dict to python here
data:{ id:comment_id, value:true},
success:function (result) {
console.log('ajax post to ' + score_ajax_url + ' done')
comment_result(result, this.id);
reload_comments(package_version_id)
},
error:function (xhr, ajaxOptions, thrownError) {
console.log('ajax to ' + score_ajax_url + ' failed')
console.log(xhr.status);
try {
console.log(xhr.status);
}
catch (exception) {
alert(xhr.status);
}
}
});
});
......@@ -201,16 +264,21 @@ function comments(id, reload_comment_url, comment_url, score_ajax_url, package_v
// sending a dict to python here
data:{ id:comment_id, value:false},
success:function (result) {
console.log('ajax post to ' + score_ajax_url + ' done')
comment_result(result, this.id);
reload_comments(package_version_id)
},
error:function (xhr, ajaxOptions, thrownError) {
console.log('ajax to ' + score_ajax_url + ' failed')
console.log(xhr.status);
try {
console.log(xhr.status);
}
catch (exception) {
alert(xhr.status)
}
}
})
});
return true
}
$(document).ready(function () {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment