Skip to content

Commit

Permalink
MDL-23912 core_comment: update count after deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetha Chan authored and Sam Hemelryk committed Nov 24, 2014
1 parent 27bfd2c commit 7168885
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
34 changes: 20 additions & 14 deletions comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ M.core_comment = {
var ta = Y.one('#dlg-content-'+this.client_id);
var scope = this;
var value = ta.get('value');
if (value && value != M.str.moodle.addcomment) {
if (value && value != M.util.get_string('addcomment', 'moodle')) {
var params = {'content': value};
this.request({
action: 'add',
Expand All @@ -81,9 +81,9 @@ M.core_comment = {
var newcomment = Y.Node.create(result.html);
container.appendChild(newcomment);
var ids = result.ids;
var linktext = Y.one('#comment-link-text-'+cid);
if (linktext) {
linktext.set('innerHTML', M.str.moodle.comments + ' ('+obj.count+')');
var linkText = Y.one('#comment-link-text-' + cid);
if (linkText) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', obj.count));
}
for(var i in ids) {
var attributes = {
Expand Down Expand Up @@ -178,7 +178,7 @@ M.core_comment = {
val = val.replace('___name___', list[i].fullname);
}
if (list[i]['delete']||newcmt) {
list[i].content = '<div class="comment-delete"><a href="#" id ="comment-delete-'+this.client_id+'-'+list[i].id+'" title="'+M.str.moodle.deletecomment+'"><img alt="" src="'+M.util.image_url('t/delete', 'core')+'" /></a></div>' + list[i].content;
list[i].content = '<div class="comment-delete"><a href="#" id ="comment-delete-'+this.client_id+'-'+list[i].id+'" title="'+M.util.get_string('deletecomment', 'moodle')+'"><img alt="" src="'+M.util.image_url('t/delete', 'core')+'" /></a></div>' + list[i].content;
}
val = val.replace('___time___', list[i].time);
val = val.replace('___picture___', list[i].avatar);
Expand All @@ -201,9 +201,9 @@ M.core_comment = {
scope: scope,
params: params,
callback: function(id, ret, args) {
var linktext = Y.one('#comment-link-text-'+scope.client_id);
if (ret.count && linktext) {
linktext.set('innerHTML', M.str.moodle.comments + ' ('+ret.count+')');
var linkText = Y.one('#comment-link-text-' + scope.client_id);
if (ret.count && linkText) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', ret.count));
}
var container = Y.one('#comment-list-'+scope.client_id);
var pagination = Y.one('#comment-pagination-'+scope.client_id);
Expand All @@ -215,7 +215,7 @@ M.core_comment = {
}
if (ret.error == 'require_login') {
var result = {};
result.html = M.str.moodle.commentsrequirelogin;
result.html = M.util.get_string('commentsrequirelogin', 'moodle');
} else {
var result = scope.render(ret.list);
}
Expand All @@ -231,10 +231,16 @@ M.core_comment = {
},

dodelete: function(id) { // note: delete is a reserved word in javascript, chrome and safary do not like it at all here!
var scope = this;
var params = {'commentid': id};
var scope = this,
cid = scope.client_id,
params = {'commentid': id};
function remove_dom(type, anim, cmt) {
cmt.remove();
var linkText = Y.one('#comment-link-text-' + cid),
comments = Y.all('#comment-list-' + cid + ' li');
if (linkText && comments) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', comments.size()));
}
}
this.request({
action: 'delete',
Expand Down Expand Up @@ -374,13 +380,13 @@ M.core_comment = {
return false;
}
if (focus) {
if (t.get('value') == M.str.moodle.addcomment) {
if (t.get('value') == M.util.get_string('addcomment', 'moodle')) {
t.set('value', '');
t.setStyle('color', 'black');
}
}else{
if (t.get('value') == '') {
t.set('value', M.str.moodle.addcomment);
t.set('value', M.util.get_string('addcomment', 'moodle'));
t.setStyle('color','grey');
t.set('rows', 2);
}
Expand Down Expand Up @@ -425,7 +431,7 @@ M.core_comment = {
return;
}
var args = {};
args.message = M.str.admin.confirmdeletecomments;
args.message = M.util.get_string('confirmdeletecomments', 'admin');
args.callback = function() {
var url = M.cfg.wwwroot + '/comment/index.php';

Expand Down
13 changes: 9 additions & 4 deletions comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,15 @@ public static function init(moodle_page $page = null) {
self::$comment_page = optional_param('comment_page', '', PARAM_INT);
self::$comment_area = optional_param('comment_area', '', PARAM_AREA);

$page->requires->string_for_js('addcomment', 'moodle');
$page->requires->string_for_js('deletecomment', 'moodle');
$page->requires->string_for_js('comments', 'moodle');
$page->requires->string_for_js('commentsrequirelogin', 'moodle');
$page->requires->strings_for_js(array(
'addcomment',
'comments',
'commentscount',
'commentsrequirelogin',
'deletecomment',
),
'moodle'
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
$string['collapsecategory'] = 'Collapse {$a}';
$string['commentincontext'] = 'Find this comment in context';
$string['comments'] = 'Comments';
$string['commentscount'] = 'Comments ({$a})';
$string['commentsnotenabled'] = 'Comments feature is not enabled';
$string['commentsrequirelogin'] = 'You need to login to view the comments';
$string['comparelanguage'] = 'Compare and edit current language';
Expand Down

0 comments on commit 7168885

Please sign in to comment.