Newer
Older
* :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
*/
CubicWeb.require('python.js');
CubicWeb.require('htmlhelpers.js');
CubicWeb.require('ajax.js');
function _getText(textarea) {
if (typeof(FCKeditor) != 'undefined') {
var fck = FCKeditorAPI.GetInstance(textarea.id);
if (fck) {
return fck.GetHTML();
}
}
return textarea.value;
}
/* this function is called on inlined-comment editions
Sylvain Thénault
committed
* It calls the [add|eid]_comment method on the jsoncontroller and [re]load
* only the view for the added or edited comment
Sylvain Thénault
committed
function processComment(eid, funcname, creation) {
var divId = 'comment' + eid + 'Slot'
var divNode = jQuery('#'+divId);
var textarea = divNode.find('textarea')[0];
if (funcname) {
var format = 'text/html'; // no select widget if fckeditor is used
var select = divNode.find('select')[0];
if (select) {
format = firstSelected(select);
}
Sylvain Thénault
committed
d = asyncRemoteExec(funcname, eid, _getText(textarea), format);
d.addCallback(function (neweid) {
if (creation) {
var commentNode = jQuery('#comment'+ eid);
var ul = null;
if (!commentNode.length) {
// we are adding a comment to the top level entity
commentNode = jQuery('#commentsectionComponent');
klass = 'comment';
} else {
klass = 'section';
}
ul = commentNode.find('> ul:first');
if (!ul.length) {
ul = jQuery(UL({'class': klass}));
commentNode.append(ul);
}
ul.append(LI({'id': 'comment'+ neweid, 'class': 'comment'},
DIV({'id': 'comment'+ neweid + 'Div'})));
divNode.remove();
eid = neweid;

sand
committed
}
Sylvain Thénault
committed
replacePageChunk('comment' + eid + 'Div', rql_for_eid(eid), 'treeitem');
Sylvain Thénault
committed
} else {
// comment cancelled, close div holding the form
divNode.remove();
// on edition, show back the comment's content
if (!creation) {
jQuery('#comment' + eid + 'Div div').show();
}
Sylvain Thénault
committed
function showLoginBox() {
toggleVisibility('popupLoginBox');
$('html, body').animate({scrollTop:0}, 'fast');
return false;
}
Sandrine Ribeau
committed
Sylvain Thénault
committed
CubicWeb.provide('comment.js');