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

@ -80,7 +80,7 @@ class CommentsExtension extends DataExtension {
*/
public function populateDefaults() {
$defaults = $this->owner->config()->defaults;
// Set if comments should be enabled by default
if(isset($defaults['ProvideComments'])) {
$this->owner->ProvideComments = $defaults['ProvideComments'];
@ -292,7 +292,7 @@ class CommentsExtension extends DataExtension {
public function getCommentsEnabled() {
// Don't display comments form for pseudo-pages (such as the login form)
if(!$this->owner->exists()) return false;
// Determine which flag should be used to determine if this is enabled
if($this->owner->getCommentsOption('enabled_cms')) {
return $this->owner->ProvideComments;
@ -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

@ -9,7 +9,7 @@
*/
$('.comments-holder-container form').entwine({
onmatch: function() {
// @todo Reinstate preview-comment functionality
/**
@ -56,7 +56,7 @@
this._super();
}
});
/**
* Comment reply form
*/
@ -74,7 +74,7 @@
this._super();
}
});
/**
* Toggle on/off reply form
*/
@ -83,7 +83,7 @@
var allForms = $( ".comment-reply-form-holder" ),
formID = $( this ).prop('href').replace(/^[^#]*#/, '#'),
form = $(formID).closest('.comment-reply-form-holder');
// Prevent focus
e.preventDefault();
if(form.is(':visible')) {
@ -94,7 +94,7 @@
}
}
});
/**
* Preview comment by fetching it from the server via ajax.
@ -132,16 +132,24 @@
$(':input', form).on('change keydown', function() {
previewEl.removeClass('loading').hide();
});*/
/**
* 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({
url: $(this).attr('href'),
cache: false,
@ -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) {
comment.remove();
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

@ -243,12 +243,14 @@ class CommentsExtensionTest extends SapphireTest {
$cf = $item->CommentsForm();
$backend = Requirements::backend();
$this->assertEquals(
$this->assertEquals(
array(
'framework/thirdparty/jquery/jquery.js',
'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()