-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to prevent accidental signout
- Loading branch information
1 parent
ac61d1a
commit 4f089a4
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as SITE from "globals-site"; | ||
import * as CONFIG from "globals-config"; | ||
import * as T from "text"; | ||
|
||
export default (e: { siteHeader: HTMLElement }) => { | ||
const signinButton = e.siteHeader.querySelector("#" + SITE.ID.signinButton); | ||
const signoutButton = e.siteHeader.querySelector("#" + SITE.ID.signoutButton); | ||
if (signoutButton === null) { | ||
return signinButton !== null; | ||
} | ||
const parent = signoutButton.parentElement as HTMLElement; | ||
const safeSignoutForm = signoutButton.cloneNode(true); | ||
signoutButton.remove(); | ||
safeSignoutForm.addEventListener("click", function() { | ||
if (confirm(T.general.signout_confirmation)) { | ||
const request = new Taiga.Xhr.JsonRpc.Request(); | ||
request.setUrl(SITE.PATH.SIGNOUT); | ||
request.setMethod("signout"); | ||
request.onError(errorHandler); | ||
request.onSuccess(() => window.location.reload()); | ||
request.send(); | ||
} | ||
}); | ||
parent.appendChild(safeSignoutForm); | ||
} | ||
|
||
function errorHandler() { | ||
const dialog = new Common.Windows.MessageDialog(); | ||
dialog.addClass(SITE.CLASS.errorDialog); | ||
dialog.setMessage(T.general.signout_error); | ||
dialog.setModal(true); | ||
dialog.openWindow(); | ||
dialog.centerOnScreen(); | ||
} | ||
|
||
declare namespace Common { | ||
namespace Windows { | ||
class MessageDialog { | ||
addClass(x: string): void | ||
setMessage(x: string): void | ||
setModal(x: boolean): void | ||
openWindow(): void | ||
centerOnScreen(): void | ||
} | ||
} | ||
} | ||
|
||
declare namespace Taiga { | ||
namespace Xhr { | ||
namespace JsonRpc { | ||
class Request { | ||
setUrl(x: string): void | ||
setMethod(x: string): void | ||
setParams(x: { csrf: string }): void | ||
onError(f: () => void): void | ||
onSuccess(f: () => void): void | ||
send(): void | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters