REFACTOR: Remove container from ajax
This commit is contained in:
parent
df8ae6891c
commit
ac498ae2a0
@ -1,10 +1,14 @@
|
||||
import Component from "@ember/component";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import logout from "discourse/lib/logout";
|
||||
import I18n from "I18n";
|
||||
import { setLogoffCallback } from "discourse/lib/ajax";
|
||||
|
||||
export default Component.extend({
|
||||
tagName: "",
|
||||
documentTitle: service(),
|
||||
_showingLogout: false,
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
@ -16,11 +20,13 @@ export default Component.extend({
|
||||
this.session.hasFocus = true;
|
||||
|
||||
this.appEvents.on("notifications:changed", this, this._updateNotifications);
|
||||
setLogoffCallback(() => this.displayLogoff());
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
setLogoffCallback(null);
|
||||
document.removeEventListener("visibilitychange", this._focusChanged);
|
||||
document.removeEventListener("resume", this._focusChanged);
|
||||
document.removeEventListener("freeze", this._focusChanged);
|
||||
@ -52,5 +58,22 @@ export default Component.extend({
|
||||
} else if (!this.hasFocus) {
|
||||
this.documentTitle.setFocus(true);
|
||||
}
|
||||
},
|
||||
|
||||
displayLogoff() {
|
||||
if (this._showingLogout) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._showingLogout = true;
|
||||
this.messageBus.stop();
|
||||
bootbox.dialog(
|
||||
I18n.t("logout"),
|
||||
{ label: I18n.t("refresh"), callback: logout },
|
||||
{
|
||||
onEscape: () => logout(),
|
||||
backdrop: "static"
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
import I18n from "I18n";
|
||||
import { run } from "@ember/runloop";
|
||||
import userPresent from "discourse/lib/user-presence";
|
||||
import logout from "discourse/lib/logout";
|
||||
import Session from "discourse/models/session";
|
||||
import { Promise } from "rsvp";
|
||||
import Site from "discourse/models/site";
|
||||
@ -11,7 +9,7 @@ import User from "discourse/models/user";
|
||||
|
||||
let _trackView = false;
|
||||
let _transientHeader = null;
|
||||
let _showingLogout = false;
|
||||
let _logoffCallback;
|
||||
|
||||
export function setTransientHeader(key, value) {
|
||||
_transientHeader = { key, value };
|
||||
@ -21,19 +19,13 @@ export function viewTrackingRequired() {
|
||||
_trackView = true;
|
||||
}
|
||||
|
||||
export function setLogoffCallback(cb) {
|
||||
_logoffCallback = cb;
|
||||
}
|
||||
|
||||
export function handleLogoff(xhr) {
|
||||
if (xhr && xhr.getResponseHeader("Discourse-Logged-Out") && !_showingLogout) {
|
||||
_showingLogout = true;
|
||||
const messageBus = Discourse.__container__.lookup("message-bus:main");
|
||||
messageBus.stop();
|
||||
bootbox.dialog(
|
||||
I18n.t("logout"),
|
||||
{ label: I18n.t("refresh"), callback: logout },
|
||||
{
|
||||
onEscape: () => logout(),
|
||||
backdrop: "static"
|
||||
}
|
||||
);
|
||||
if (xhr && xhr.getResponseHeader("Discourse-Logged-Out") && _logoffCallback) {
|
||||
_logoffCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user