From 14403a8cb86bb659c2b2bc77fdba549bb4b4a36a Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 3 Feb 2022 20:23:30 +0000 Subject: [PATCH] MDL-73737 report_loglive: ensure action link popups work post-AJAX. --- report/loglive/classes/renderable.php | 2 +- report/loglive/classes/table_log_ajax.php | 21 +++++++++++++++++++ .../moodle-report_loglive-fetchlogs-debug.js | 13 ++++++++++++ .../moodle-report_loglive-fetchlogs-min.js | 2 +- .../moodle-report_loglive-fetchlogs.js | 13 ++++++++++++ .../loglive/yui/src/fetchlogs/js/fetchlogs.js | 13 ++++++++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/report/loglive/classes/renderable.php b/report/loglive/classes/renderable.php index 8c12ee97321..ff8d4107e06 100644 --- a/report/loglive/classes/renderable.php +++ b/report/loglive/classes/renderable.php @@ -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; diff --git a/report/loglive/classes/table_log_ajax.php b/report/loglive/classes/table_log_ajax.php index a1b8029c188..878c3a4a051 100644 --- a/report/loglive/classes/table_log_ajax.php +++ b/report/loglive/classes/table_log_ajax.php @@ -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); + } } diff --git a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-debug.js b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-debug.js index 2f0d62cafce..f41db8959ad 100644 --- a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-debug.js +++ b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-debug.js @@ -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. * diff --git a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-min.js b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-min.js index 603400cefc3..81bf727d278 100644 --- a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-min.js +++ b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs-min.js @@ -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"]}); \ No newline at end of file +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"]}); \ No newline at end of file diff --git a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs.js b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs.js index 2f0d62cafce..f41db8959ad 100644 --- a/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs.js +++ b/report/loglive/yui/build/moodle-report_loglive-fetchlogs/moodle-report_loglive-fetchlogs.js @@ -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. * diff --git a/report/loglive/yui/src/fetchlogs/js/fetchlogs.js b/report/loglive/yui/src/fetchlogs/js/fetchlogs.js index a4efb8ef4cb..75a8b80583f 100644 --- a/report/loglive/yui/src/fetchlogs/js/fetchlogs.js +++ b/report/loglive/yui/src/fetchlogs/js/fetchlogs.js @@ -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. *