From 4b201bc6f5ed62a0ce12422a57b154c2cde40e9b Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Wed, 7 Apr 2010 06:42:17 +0000 Subject: [PATCH] MDL-19118, comments api improvement --- comment/comment.js | 45 ++++++++++++++++++++++++++++------- comment/lib.php | 15 ++++++------ lang/en_utf8/moodle.php | 1 + lib/outputrequirementslib.php | 4 ++-- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/comment/comment.js b/comment/comment.js index 466f9f4319e..1a5e3c39ee4 100644 --- a/comment/comment.js +++ b/comment/comment.js @@ -54,6 +54,11 @@ M.core_comment = { this.view(0); return false; }, this); + CommentHelper.confirmoverlay = new Y.Overlay({ +bodyContent: ''+M.str.moodle.sure+' '+M.str.moodle.cancel+'', + visible: false + }); + CommentHelper.confirmoverlay.render(document.body); }, post: function() { var ta = Y.one('#dlg-content-'+this.client_id); @@ -124,7 +129,7 @@ M.core_comment = { complete: function(id,o,p) { if (!o) { alert('IO FATAL'); - return; + return false; } var data = Y.JSON.parse(o.responseText); if (data.error) { @@ -179,7 +184,7 @@ M.core_comment = { var scope = this; var container = Y.one('#comment-ctrl-'+this.client_id); var params = { - 'page': page, + 'page': page } this.request({ scope: scope, @@ -206,7 +211,7 @@ 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}; - + scope.cancel_delete(); function remove_dom(type, anmi, cmt) { cmt.remove(); } @@ -251,20 +256,42 @@ M.core_comment = { Y.all('div.comment-content a').each( function(node, id) { var theid = node.get('id'); - var re = new RegExp("comment-delete-"+scope.client_id+"-(\\d+)", "i"); - var result = theid.match(re); - if (result[1]) { + var parseid = new RegExp("comment-delete-"+scope.client_id+"-(\\d+)", "i"); + var commentid = theid.match(parseid); + if (commentid[1]) { Y.Event.purgeElement('#'+theid, false, 'click'); } node.on('click', function(e, node) { + var width = CommentHelper.confirmoverlay.bodyNode.getStyle('width'); + var re = new RegExp("(\\d+).*", "i"); + var result = width.match(re); if (result[1]) { - this.dodelete(result[1]); + width = Number(result[1]); + } else { + width = 0; } - //this.load(result[1]); + CommentHelper.confirmoverlay.set('xy', [e.pageX-(width/2), e.pageY+10]); + CommentHelper.confirmoverlay.set('visible', true); + // XXX: YUI3 bug, a temp workaround in firefox, still have problem on webkit + CommentHelper.confirmoverlay.bodyNode.setStyle('visibility', 'visible'); + Y.one('#canceldelete-'+scope.client_id).on('click', function() { + scope.cancel_delete(); + }); + Y.Event.purgeElement('#confirmdelete-'+scope.client_id, false, 'click'); + Y.one('#confirmdelete-'+scope.client_id).on('click', function() { + if (commentid[1]) { + scope.dodelete(commentid[1]); + } + }); }, scope, node); } ); }, + cancel_delete: function() { + CommentHelper.confirmoverlay.set('visible', false); + // XXX: YUI3 bug, a temp workaround in firefox, still have problem on webkit + CommentHelper.confirmoverlay.bodyNode.setStyle('visibility', 'hidden'); + }, register_pagination: function() { var scope = this; // page buttons @@ -348,7 +375,7 @@ M.core_comment = { checked=true; } } - for (var i in comments) { + for (i in comments) { comments[i].checked = !checked; } this.set('checked', !checked); diff --git a/comment/lib.php b/comment/lib.php index 6cdaff8553c..b4358c9865f 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -260,7 +260,8 @@ EOD; * @return mixed */ public function output($return = true) { - global $CFG, $PAGE, $OUTPUT; + global $PAGE, $OUTPUT; + static $template_printed; $this->link = $PAGE->url; $murl = new moodle_url($this->link); @@ -295,18 +296,18 @@ EOD; $strsubmit = get_string('submit'); $strcancel = get_string('cancel'); $sesskey = sesskey(); - + $html = ''; // print html template // Javascript will use the template to render new comments - if (empty($CFG->commentcommentcode) && !empty($this->viewcap)) { - echo ''; - $CFG->commentcommentcode = true; + if (empty($template_printed) && !empty($this->viewcap)) { + $html .= ''; + $template_printed = true; } if (!empty($this->viewcap)) { // print commenting icon and tooltip $icon = $OUTPUT->pix_url('t/collapsed'); - $html = << {$this->linktext} @@ -448,7 +449,7 @@ EOD; } else { $class = 'pageno'; } - $str .= ''.($p+1).' '; + $str .= ''.($p+1).' '; } $str .= ''; } diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index f0db75dee1e..095b45aed2f 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1614,6 +1614,7 @@ $string['success'] = 'Success'; $string['summary'] = 'Summary'; $string['summaryof'] = 'Summary of $a'; $string['supplyinfo'] = 'More details'; +$string['sure'] = 'Sure'; $string['switchrolereturn'] = 'Return to my normal role'; $string['switchroleto'] = 'Switch role to...'; $string['tag'] = 'Tag'; diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index d42efa46511..403b1d00fb0 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -364,8 +364,8 @@ class page_requirements_manager { case 'core_comment': $module = array('name' => 'core_comment', 'fullpath' => '/comment/comment.js', - 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'), - 'strings' => array(array('confirmdeletecomments', 'admin')) + 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation', 'overlay'), + 'strings' => array(array('confirmdeletecomments', 'admin'), array('sure', 'moodle'), array('cancel', 'moodle')) ); break; case 'core_role':