mirror of
https://github.com/moodle/moodle.git
synced 2025-04-26 02:44:13 +02:00
MDL-19118, comments api improvement
This commit is contained in:
parent
bb9728e873
commit
4b201bc6f5
@ -54,6 +54,11 @@ M.core_comment = {
|
||||
this.view(0);
|
||||
return false;
|
||||
}, this);
|
||||
CommentHelper.confirmoverlay = new Y.Overlay({
|
||||
bodyContent: '<a href="###" id="confirmdelete-'+this.client_id+'">'+M.str.moodle.sure+'</a> <a href="###" id="canceldelete-'+this.client_id+'">'+M.str.moodle.cancel+'</a>',
|
||||
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);
|
||||
|
@ -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 '<div style="display:none" id="cmt-tmpl">' . $this->template . '</div>';
|
||||
$CFG->commentcommentcode = true;
|
||||
if (empty($template_printed) && !empty($this->viewcap)) {
|
||||
$html .= '<div style="display:none" id="cmt-tmpl">' . $this->template . '</div>';
|
||||
$template_printed = true;
|
||||
}
|
||||
|
||||
if (!empty($this->viewcap)) {
|
||||
// print commenting icon and tooltip
|
||||
$icon = $OUTPUT->pix_url('t/collapsed');
|
||||
$html = <<<EOD
|
||||
$html .= <<<EOD
|
||||
<div class="mdl-left">
|
||||
<a id="comment-link-{$this->cid}" href="{$this->link}">
|
||||
<img id="comment-img-{$this->cid}" src="$icon" alt="{$this->linktext}" title="{$this->linktext}" />
|
||||
@ -448,7 +449,7 @@ EOD;
|
||||
} else {
|
||||
$class = 'pageno';
|
||||
}
|
||||
$str .= '<a class="'.$class.'" href="###" id="comment-page-'.$this->cid.'-'.$p.'">'.($p+1).'</a> ';
|
||||
$str .= '<a href="###" class="'.$class.'" id="comment-page-'.$this->cid.'-'.$p.'">'.($p+1).'</a> ';
|
||||
}
|
||||
$str .= '</div>';
|
||||
}
|
||||
|
@ -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';
|
||||
|
@ -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':
|
||||
|
Loading…
x
Reference in New Issue
Block a user