ENHANCEMENT: Ajax spam/ham/approve/delete ressurected. Added confirm box for delete

This commit is contained in:
Gordon Anderson 2016-02-10 11:56:14 +07:00
parent 7721c20e80
commit fd153265e9
4 changed files with 42 additions and 21 deletions

View File

@ -422,6 +422,7 @@ class CommentsExtension extends DataExtension {
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
Requirements::javascript(COMMENTS_THIRDPARTY . '/jquery-validate/jquery.validate.min.js');
Requirements::add_i18n_javascript('comments/javascript/lang');
Requirements::javascript('comments/javascript/CommentsInterface.js');
}

View File

@ -137,9 +137,17 @@
* Clicking one of the metalinks performs the operation via ajax
* this inclues the spam and approve links
*/
/* @todo Migrate to work with nested comments
commentsList.on('click', '.action-links a', function(e) {
$('.comments-holder .comments-list').on('click', 'div.comment-moderation-options a', function(e) {
var link = $(this);
if (link.hasClass('delete')) {
var confirmationMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.DELETE_CONFIRMATION');
var confirmation = window.confirm(confirmationMsg);
if (!confirmation) {
e.preventDefault();
return false;
}
}
var comment = link.parents('.comment:first');
$.ajax({
@ -149,34 +157,34 @@
if(link.hasClass('ham')) {
// comment has been marked as not spam
comment.html(html);
comment.removeClass('spam').hide().fadeIn();
comment.removeClass('spam');
}
else if(link.hasClass('approve')) {
// comment has been approved
comment.html(html);
comment.removeClass('unmoderated').hide().fadeIn();
comment.removeClass('unmoderated');
}
else if(link.hasClass('delete')) {
comment.fadeOut(1000, function() {
comment.remove();
if(commentsList.children().length == 0) {
if(commentsList.children().length === 0) {
noCommentsYet.show();
}
});
}
else if(link.hasClass('spam')) {
comment.html(html).addClass('spam').hide().fadeIn();
comment.html(html).addClass('spam');
}
},
failure: function(html) {
alert(html)
var errorMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.AJAX_ERROR');
alert(errorMsg);
}
});
e.preventDefault();
});
*/
/**
* Ajax pagination

10
javascript/lang/en.js Normal file
View File

@ -0,0 +1,10 @@
// This file was generated by silverstripe/cow from javascript/lang/src/en.js.
// See https://github.com/tractorcow/cow for details
if (typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if (typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('en', {
"CommentsInterface_singlecomment_ss.DELETE_CONFIRMATION": "Are you sure?",
"CommentsInterface_singlecomment_ss.AJAX_ERROR": "An error occurred whilst updating the comment",
});
}

View File

@ -249,6 +249,8 @@ class CommentsExtensionTest extends SapphireTest {
'framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js',
'framework/thirdparty/jquery-validate/lib/jquery.form.js',
'comments/thirdparty/jquery-validate/jquery.validate.min.js',
'framework/javascript/i18n.js',
'comments/javascript/lang/en.js',
'comments/javascript/CommentsInterface.js'
),
$backend->get_javascript()