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::
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);
}
});
};
-/**
- * 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.
*
$actions = [
[
'title' => get_string('calltofeedback_give'),
- 'url' => '#',
+ 'url' => static::make_link()->out(false),
'data' => [
- 'action' => 'give',
+ 'action' => 'give',
'record' => 1,
'hide' => 1,
],
$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;
}
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"