MDL-68991 core: Prevent popup blockers blocking feedback window

Some browsers like Firefox are very inflexible with window.open()
and block it if it is not instantly invoked after the user click.

Also according to https://stackoverflow.com/a/6807615 it is best
practice to replace self:: with static::
This commit is contained in:
Shamim Rezaie
2020-06-09 21:34:44 +10:00
parent 4cdcd23fb2
commit 292a67aede
5 changed files with 27 additions and 29 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core/userfeedback",["exports","core/ajax","core/notification"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{root:"[data-region=\"core/userfeedback\"]"},actions:{}};f.actions.give="".concat(f.regions.root," [data-action=\"give\"]");f.actions.remind="".concat(f.regions.root," [data-action=\"remind\"]");a.registerEventListeners=function registerEventListeners(){document.addEventListener("click",function(a){var b=a.target.closest(f.actions.give);if(b){a.preventDefault();g().then(function(){return i(b)}).then(h).catch(c.default.exception)}var d=a.target.closest(f.actions.remind);if(d){a.preventDefault();Promise.resolve(d).then(i).then(h).catch(c.default.exception)}})};var g=function(){return b.default.call([{methodname:"core_get_userfeedback_url",args:{contextid:M.cfg.contextid}}])[0].then(function(a){if(!window.open(a)){throw new Error("Unable to open popup")}})},h=function(a){if(a.dataset.record){return b.default.call([{methodname:"core_create_userfeedback_action_record",args:{action:a.dataset.action,contextid:M.cfg.contextid}}])[0]}return Promise.resolve()},i=function(a){if(a.dataset.hide){a.closest(f.regions.root).remove()}return a}});
define ("core/userfeedback",["exports","core/ajax","core/notification"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{root:"[data-region=\"core/userfeedback\"]"},actions:{}};f.actions.give="".concat(f.regions.root," [data-action=\"give\"]");f.actions.remind="".concat(f.regions.root," [data-action=\"remind\"]");a.registerEventListeners=function registerEventListeners(){document.addEventListener("click",function(a){var b=a.target.closest(f.actions.give);if(b){a.preventDefault();if(!window.open(b.href)){throw new Error("Unable to open popup")}Promise.resolve(b).then(h).then(g).catch(c.default.exception)}var d=a.target.closest(f.actions.remind);if(d){a.preventDefault();Promise.resolve(d).then(h).then(g).catch(c.default.exception)}})};var g=function(a){if(a.dataset.record){return b.default.call([{methodname:"core_create_userfeedback_action_record",args:{action:a.dataset.action,contextid:M.cfg.contextid}}])[0]}return Promise.resolve()},h=function(a){if(a.dataset.hide){a.closest(f.regions.root).remove()}return a}});
//# sourceMappingURL=userfeedback.min.js.map
File diff suppressed because one or more lines are too long
+6 -22
View File
@@ -42,8 +42,12 @@ export const registerEventListeners = () => {
if (giveAction) {
e.preventDefault();
giveFeedback()
.then(() => hideRoot(giveAction))
if (!window.open(giveAction.href)) {
throw new Error('Unable to open popup');
}
Promise.resolve(giveAction)
.then(hideRoot)
.then(recordAction)
.catch(Notification.exception);
}
@@ -60,26 +64,6 @@ export const registerEventListeners = () => {
});
};
/**
* The action function that is called when users choose to give feedback.
*
* @returns {Promise<void>}
*/
const giveFeedback = () => {
return Ajax.call([{
methodname: 'core_get_userfeedback_url',
args: {
contextid: M.cfg.contextid,
}
}])[0]
.then(url => {
if (!window.open(url)) {
throw new Error('Unable to open popup');
}
return;
});
};
/**
* Record the action that the user took.
*
+5 -5
View File
@@ -57,9 +57,9 @@ class core_userfeedback {
$actions = [
[
'title' => get_string('calltofeedback_give'),
'url' => '#',
'url' => static::make_link()->out(false),
'data' => [
'action' => 'give',
'action' => 'give',
'record' => 1,
'hide' => 1,
],
@@ -103,13 +103,13 @@ class core_userfeedback {
$lastactiontime = max($give ?: 0, $remind ?: 0);
switch ($CFG->userfeedback_nextreminder) {
case self::REMIND_AFTER_UPGRADE:
$lastupgrade = self::last_major_upgrade_time();
case static::REMIND_AFTER_UPGRADE:
$lastupgrade = static::last_major_upgrade_time();
if ($lastupgrade >= $lastactiontime) {
return $lastupgrade + ($CFG->userfeedback_remindafter * DAYSECS) < time();
}
break;
case self::REMIND_PERIODICALLY:
case static::REMIND_PERIODICALLY:
return $lastactiontime + ($CFG->userfeedback_remindafter * DAYSECS) < time();
break;
}
+14
View File
@@ -34,3 +34,17 @@ Feature: Gathering user feedback
And I reload the page
Then I should not see "Give feedback" in the "region-main" "region"
And I should not see "Remind me later" in the "region-main" "region"
@javascript
Scenario: Users should not see the notification after they click on the give feedback link
Given the following config values are set as admin:
| enableuserfeedback | 1 |
| userfeedback_nextreminder | 2 |
| userfeedback_remindafter | 90 |
When I log in as "admin"
And I follow "Dashboard" in the user menu
And I click on "Give feedback" "link"
And I close all opened windows
And I reload the page
Then I should not see "Give feedback" in the "region-main" "region"
And I should not see "Remind me later" in the "region-main" "region"