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

comments: making this clear and add comments

parent 5e2ee7c4
......@@ -4,7 +4,7 @@
* This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
*
* Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
*
* 2012 Baptiste Mouterde <baptiste.mouterde@gmail.com>
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
......@@ -59,8 +59,16 @@ function collapse_qa(header, speed) {
toggle_qa(header, speed);
}
}
/*
==========================================================
code browser stuff
==========================================================
*/
// optional function
function highlight(event) {
/* this highlight the clicked line
set on a <a>
*/
if (event != null) {
event.preventDefault();
}
......@@ -89,81 +97,9 @@ function highlight(event) {
}
$("#L" + stop + "S").focus()
}
function comment_form(id, post_url, reload_url, package_version_id, filename, parent) {
var reload_comments = load_reload(id, package_version_id, reload_url, filename)
function onSuccess(result) {
$('#comment_fs' + id).html(result);
$('#comment_fs' + id).fadeOut(5000);
reload_comments(package_version_id)
}
$("#send" + id).bind('click',function (evt) {
evt.preventDefault();
var title = $("#titlei" + id).val();
var type = $("#typei" + id).val();
var comment = $("#commenti" + id).val();
var start = $("#start" + id).val();
var stop = $("#stop" + id).val();
jQuery.ajax({
type:'POST',
url:post_url,
dataType:'json',
// 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) {
onSuccess(result)
},
error:function (xhr, ajaxOptions, thrownError) {
try {
console.log(xhr.status)
}
catch (exception) {
alert(xhr.status)
}
}
});
});
$("#typei" + id).change(function () {
$("#comment_fs" + id).removeClass();
$("#comment_fs" + id).addClass($("#typei" + id).val())
})
}
function comment_result(result, id) {
$('comment_result' + 'id').remove();
$("<span id='com_result" + id + "'>" + result.toString() + "</span").insertAfter($('#' + id).parent().parent())
}
function load_reload(id, package_version_id, url, filename) {
function reload_comments(package_version_id) {
// doing the refresh of this with an ajax request
if (filename == "") {
var data = {id:id, package_version_id:package_version_id}
}
else {
var data = {id:id, package_version_id:package_version_id, filename:filename}
}
jQuery.ajax({
type:'post',
url:url,
dataType:'json',
data:data,
success:function (result) {
$('#comments' + id).html(result)
},
error:function (xhr, ajaxOptions, thrownError) {
try {
console.log(xhr.status);
}
catch (exception) {
alert(xhr.status);
}
}
});
}
// main comment function
return reload_comments
}
function init_js() {
//testing js function : unbind / preventdefault / ajax
// first prevent default :
......@@ -185,7 +121,7 @@ function init_js() {
$('#superheader').insertBefore("<div class='info'>preventdefault is'nt working loading no js version: " + exception + "</div>")
}
//tresting unbind function
//testing unbind function
try {
$(document).add("<div class='test' id='test_unbind'></div>_")
$('#test_unbind').hover(function () {
......@@ -210,11 +146,14 @@ function init_js() {
return jQuery.ajax;
}
function score_result(output,comment_id,result){
$('<div id="score_result'+ comment_id +'">'+result+'</div>').insertAfter(output);
$('#score_result' + comment_id).fadeOut(5000);
}
function comments(id, reload_comment_url, comment_url, score_ajax_url, package_version_id, filename) {
/* this is used to make the comment stuff works
it removes the no-js stuff and hide the optional stuff
it also adds action on button
in order to avoid mako here all var must be send from the template
with something like var foo = ${c.foo}
*/
if (init_js()) {
//removing test and non js version
$('.test,.no-js').remove();
......@@ -252,7 +191,6 @@ function comments(id, reload_comment_url, comment_url, score_ajax_url, package_v
success:function (result) {
score_result(output,comment_id,result);
if (!result.indexOf('failure')>=0){
console.log('success!')
reload_comments(package_version_id);
comment_form(id, comment_url, reload_comment_url, package_version_id, filename)
}
......@@ -299,7 +237,97 @@ function comments(id, reload_comment_url, comment_url, score_ajax_url, package_v
return true
}
$(document).ready(function () {
function comment_form(id, post_url, reload_url, package_version_id, filename, parent) {
/*
this handle the form post from comments
it need all var for avoiding mako here
*/
var reload_comments = load_reload(id, package_version_id, reload_url, filename)
function onSuccess(result) {
$('#comment_fs' + id).html(result);
$('#comment_fs' + id).fadeOut(5000);
reload_comments(package_version_id)
}
$("#send" + id).bind('click',function (evt) {
evt.preventDefault();
var title = $("#titlei" + id).val();
var type = $("#typei" + id).val();
var comment = $("#commenti" + id).val();
var start = $("#start" + id).val();
var stop = $("#stop" + id).val();
jQuery.ajax({
type:'POST',
url:post_url,
dataType:'json',
// 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) {
onSuccess(result)
},
error:function (xhr, ajaxOptions, thrownError) {
try {
console.log(xhr.status)
}
catch (exception) {
alert(xhr.status)
}
}
});
});
$("#typei" + id).change(function () {
$("#comment_fs" + id).removeClass();
$("#comment_fs" + id).addClass($("#typei" + id).val())
})
}
function comment_result(result, id) {
// this handle the result of the comment submit
$('comment_result' + 'id').remove();
$("<span id='com_result" + id + "'>" + result.toString() + "</span").insertAfter($('#' + id).parent().parent())
}
function load_reload(id, package_version_id, url, filename) {
// this is returning the reload function in order to reload comments
function reload_comments(package_version_id) {
// doing the refresh of this with an ajax request
if (filename == "") {
var data = {id:id, package_version_id:package_version_id}
}
else {
var data = {id:id, package_version_id:package_version_id, filename:filename}
}
jQuery.ajax({
type:'post',
url:url,
dataType:'json',
data:data,
success:function (result) {
$('#comments' + id).html(result)
},
error:function (xhr, ajaxOptions, thrownError) {
try {
console.log(xhr.status);
}
catch (exception) {
alert(xhr.status);
}
}
});
}
return reload_comments
}
function score_result(output,comment_id,result){
$('<div id="score_result'+ comment_id +'">'+result+'</div>').insertAfter(output);
$('#score_result' + comment_id).fadeOut(5000);
}
/*
==========================================================
*/
$(document).ready(function () {
/* General stuff */
$('.confirm').click(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