MDL-73737 report_loglive: ensure action link popups work post-AJAX.

This commit is contained in:
Paul Holden 2022-02-03 20:23:30 +00:00
parent 1d99ba19a2
commit 4471724bab
6 changed files with 62 additions and 2 deletions

View File

@ -198,7 +198,7 @@ class report_loglive_renderable implements renderable {
} else {
if (defined('REPORT_LOGLIVE_REFRESH')) {
// Backward compatibility.
$this->refresh = REPORT_LOGLIVE_REFERESH;
$this->refresh = REPORT_LOGLIVE_REFRESH;
} else {
// Default.
$this->refresh = 60;

View File

@ -58,4 +58,25 @@ class report_loglive_table_log_ajax extends report_loglive_table_log {
$result = array('logs' => $html, 'until' => $until);
return json_encode($result);
}
/**
* Popup actions do not function when they are rendered in response to an AJAX request, encode within the link itself
*
* @param moodle_url $url
* @param string $text
* @param string $name
* @return string
*/
protected function action_link(moodle_url $url, $text, $name = 'popup') {
global $OUTPUT;
$link = new action_link($url, $text, null, [
'data-action' => 'action-popup',
'data-popup-action' => json_encode(
new popup_action('click', $url, $name, ['height' => 440, 'width' => 700])
),
]);
return $OUTPUT->render($link);
}
}

View File

@ -26,6 +26,7 @@ var CSS = {
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
ACTIONLINK: '[data-action="action-popup"]',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
@ -76,6 +77,7 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.one(SELECTORS.TBODY).delegate('click', this.openActionLink, SELECTORS.ACTIONLINK, this);
Y.one(SELECTORS.PAUSEBUTTON).on('click', this.toggleUpdate, this);
},
@ -165,6 +167,17 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner.hide();
},
/**
* Open a report action link
*
* @param {Event} event
* @method openActionLink
*/
openActionLink: function(event) {
var popupAction = JSON.parse(event.target.get('dataset').popupAction);
window.openpopup(event, popupAction.jsfunctionargs);
},
/**
* Toggle live update.
*

View File

@ -1 +1 @@
YUI.add("moodle-report_loglive-fetchlogs",function(r,e){function t(){t.superclass.constructor.apply(this,arguments)}var i="newrow",l={NEWROW:"."+i,TBODY:".flexible tbody",PAUSEBUTTON:"#livelogs-pause-button",SPINNER:"."+"spinner"};r.extend(t,r.Base,{callBack:{},spinner:{},pauseButton:{},initializer:function(){0===this.get("page")&&(this.callBack=r.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0)),this.spinner=r.one(l.SPINNER),this.pauseButton=r.one(l.PAUSEBUTTON),this.spinner.hide(),r.one(l.PAUSEBUTTON).on("click",this.toggleUpdate,this)},fetchRecentLogs:function(){var e,t;this.spinner.show(),e={logreader:this.get("logreader"),since:this.get("since"),page:this.get("page"),id:this.get("courseid")},e={method:"get",context:this,on:{complete:this.updateLogTable},data:e},t=M.cfg.wwwroot+"/report/loglive/loglive_ajax.php",r.io(t,e)},updateLogTable:function(e,t){var i,n,o;r.later(600,this,"hideLoadingIcon");try{if((i=r.JSON.parse(t.responseText)).error)return r.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(i)}),this}catch(s){return r.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}this.set("since",i.until),t=i.logs,(n=r.one(l.TBODY))&&t&&((o=n.get("firstChild"))&&n.insertBefore(t,o),n.get("children").slice(this.get("perpage")).remove(),r.later(5e3,this,"removeHighlight",i.until))},removeHighlight:function(e){r.all(".time"+e).removeClass(i)},hideLoadingIcon:function(){this.spinner.hide()},toggleUpdate:function(){this.callBack?(this.callBack.cancel(),this.callBack="",this.pauseButton.setContent(M.util.get_string("resume","report_loglive"))):(this.callBack=r.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0),this.pauseButton.setContent(M.util.get_string("pause","report_loglive")))}},{NAME:"fetchLogs",ATTRS:{since:null,courseid:0,page:0,perpage:100,interval:60,logreader:"logstore_standard"}}),r.namespace("M.report_loglive.FetchLogs").init=function(e){return new t(e)}},"@VERSION@",{requires:["base","event","node","io","node-event-delegate"]});
YUI.add("moodle-report_loglive-fetchlogs",function(a,e){function t(){t.superclass.constructor.apply(this,arguments)}var i="newrow",r={NEWROW:"."+i,TBODY:".flexible tbody",ACTIONLINK:'[data-action="action-popup"]',PAUSEBUTTON:"#livelogs-pause-button",SPINNER:"."+"spinner"};a.extend(t,a.Base,{callBack:{},spinner:{},pauseButton:{},initializer:function(){0===this.get("page")&&(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0)),this.spinner=a.one(r.SPINNER),this.pauseButton=a.one(r.PAUSEBUTTON),this.spinner.hide(),a.one(r.TBODY).delegate("click",this.openActionLink,r.ACTIONLINK,this),a.one(r.PAUSEBUTTON).on("click",this.toggleUpdate,this)},fetchRecentLogs:function(){var e,t;this.spinner.show(),e={logreader:this.get("logreader"),since:this.get("since"),page:this.get("page"),id:this.get("courseid")},e={method:"get",context:this,on:{complete:this.updateLogTable},data:e},t=M.cfg.wwwroot+"/report/loglive/loglive_ajax.php",a.io(t,e)},updateLogTable:function(e,t){var i,n,o;a.later(600,this,"hideLoadingIcon");try{if((i=a.JSON.parse(t.responseText)).error)return a.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(i)}),this}catch(s){return a.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}this.set("since",i.until),t=i.logs,(n=a.one(r.TBODY))&&t&&((o=n.get("firstChild"))&&n.insertBefore(t,o),n.get("children").slice(this.get("perpage")).remove(),a.later(5e3,this,"removeHighlight",i.until))},removeHighlight:function(e){a.all(".time"+e).removeClass(i)},hideLoadingIcon:function(){this.spinner.hide()},openActionLink:function(e){var t=JSON.parse(e.target.get("dataset").popupAction);window.openpopup(e,t.jsfunctionargs)},toggleUpdate:function(){this.callBack?(this.callBack.cancel(),this.callBack="",this.pauseButton.setContent(M.util.get_string("resume","report_loglive"))):(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0),this.pauseButton.setContent(M.util.get_string("pause","report_loglive")))}},{NAME:"fetchLogs",ATTRS:{since:null,courseid:0,page:0,perpage:100,interval:60,logreader:"logstore_standard"}}),a.namespace("M.report_loglive.FetchLogs").init=function(e){return new t(e)}},"@VERSION@",{requires:["base","event","node","io","node-event-delegate"]});

View File

@ -26,6 +26,7 @@ var CSS = {
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
ACTIONLINK: '[data-action="action-popup"]',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
@ -76,6 +77,7 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.one(SELECTORS.TBODY).delegate('click', this.openActionLink, SELECTORS.ACTIONLINK, this);
Y.one(SELECTORS.PAUSEBUTTON).on('click', this.toggleUpdate, this);
},
@ -165,6 +167,17 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner.hide();
},
/**
* Open a report action link
*
* @param {Event} event
* @method openActionLink
*/
openActionLink: function(event) {
var popupAction = JSON.parse(event.target.get('dataset').popupAction);
window.openpopup(event, popupAction.jsfunctionargs);
},
/**
* Toggle live update.
*

View File

@ -24,6 +24,7 @@ var CSS = {
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
ACTIONLINK: '[data-action="action-popup"]',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
@ -74,6 +75,7 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.one(SELECTORS.TBODY).delegate('click', this.openActionLink, SELECTORS.ACTIONLINK, this);
Y.one(SELECTORS.PAUSEBUTTON).on('click', this.toggleUpdate, this);
},
@ -163,6 +165,17 @@ Y.extend(FetchLogs, Y.Base, {
this.spinner.hide();
},
/**
* Open a report action link
*
* @param {Event} event
* @method openActionLink
*/
openActionLink: function(event) {
var popupAction = JSON.parse(event.target.get('dataset').popupAction);
window.openpopup(event, popupAction.jsfunctionargs);
},
/**
* Toggle live update.
*