mirror of
https://github.com/discourse/discourse.git
synced 2025-04-25 09:44:27 +08:00
DEV: Update action syntax for routes/application.js (#27282)
This commit is contained in:
parent
d02e40e989
commit
0b10e335ae
@ -21,14 +21,12 @@ import getURL from "discourse-common/lib/get-url";
|
||||
import I18n from "discourse-i18n";
|
||||
import NotActivatedModal from "../components/modal/not-activated";
|
||||
|
||||
function unlessStrictlyReadOnly(method, message) {
|
||||
return function () {
|
||||
function unlessStrictlyReadOnly(cb, message) {
|
||||
if (this.site.isReadOnly && !this.site.isStaffWritesOnly) {
|
||||
this.dialog.alert(message);
|
||||
} else {
|
||||
this[method]();
|
||||
cb();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const ApplicationRoute = DiscourseRoute.extend({
|
||||
@ -74,20 +72,25 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
return true;
|
||||
},
|
||||
|
||||
actions: {
|
||||
@action
|
||||
toggleMobileView() {
|
||||
mobile.toggleMobileView();
|
||||
},
|
||||
|
||||
@action
|
||||
toggleSidebar() {
|
||||
this.controllerFor("application").send("toggleSidebar");
|
||||
},
|
||||
|
||||
logout: unlessStrictlyReadOnly(
|
||||
"_handleLogout",
|
||||
I18n.t("read_only_mode.logout_disabled")
|
||||
),
|
||||
@action
|
||||
logout() {
|
||||
unlessStrictlyReadOnly.apply(this, [
|
||||
() => this._handleLogout(),
|
||||
I18n.t("read_only_mode.logout_disabled"),
|
||||
]);
|
||||
},
|
||||
|
||||
@action
|
||||
_collectTitleTokens(tokens) {
|
||||
tokens.push(this.siteTitle);
|
||||
if (
|
||||
@ -100,6 +103,7 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
this.documentTitle.setTitle(tokens.join(" - "));
|
||||
},
|
||||
|
||||
@action
|
||||
composePrivateMessage(user, post) {
|
||||
const recipients = user ? user.get("username") : "";
|
||||
const reply = post
|
||||
@ -123,6 +127,7 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
});
|
||||
},
|
||||
|
||||
@action
|
||||
error(err, transition) {
|
||||
const xhrOrErr = err.jqXHR ? err.jqXHR : err;
|
||||
const exceptionController = this.controllerFor("exception");
|
||||
@ -166,11 +171,15 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
return shouldBubble;
|
||||
},
|
||||
|
||||
showLogin: unlessStrictlyReadOnly(
|
||||
"handleShowLogin",
|
||||
I18n.t("read_only_mode.login_disabled")
|
||||
),
|
||||
@action
|
||||
showLogin() {
|
||||
unlessStrictlyReadOnly.apply(this, [
|
||||
() => this.handleShowLogin(),
|
||||
I18n.t("read_only_mode.login_disabled"),
|
||||
]);
|
||||
},
|
||||
|
||||
@action
|
||||
showCreateAccount(createAccountProps = {}) {
|
||||
if (this.site.isReadOnly) {
|
||||
this.dialog.alert(I18n.t("read_only_mode.login_disabled"));
|
||||
@ -179,23 +188,28 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@action
|
||||
showForgotPassword() {
|
||||
this.modal.show(ForgotPassword);
|
||||
},
|
||||
|
||||
@action
|
||||
showNotActivated(props) {
|
||||
this.modal.show(NotActivatedModal, { model: props });
|
||||
},
|
||||
|
||||
@action
|
||||
showUploadSelector() {
|
||||
document.getElementById("file-uploader").click();
|
||||
},
|
||||
|
||||
@action
|
||||
showKeyboardShortcutsHelp() {
|
||||
this.modal.show(KeyboardShortcutsHelp);
|
||||
},
|
||||
|
||||
// Close the current modal, and destroy its state.
|
||||
@action
|
||||
closeModal(initiatedBy) {
|
||||
return this.modal.close(initiatedBy);
|
||||
},
|
||||
@ -205,22 +219,27 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
This is useful if you want to prompt for confirmation. hideModal, ask "Are you sure?",
|
||||
user clicks "No", reopenModal. If user clicks "Yes", be sure to call closeModal.
|
||||
**/
|
||||
@action
|
||||
hideModal() {
|
||||
return this.modal.hide();
|
||||
},
|
||||
|
||||
@action
|
||||
reopenModal() {
|
||||
return this.modal.reopen();
|
||||
},
|
||||
|
||||
@action
|
||||
editCategory(category) {
|
||||
DiscourseURL.routeTo(`/c/${Category.slugFor(category)}/edit`);
|
||||
},
|
||||
|
||||
@action
|
||||
checkEmail(user) {
|
||||
user.checkEmail();
|
||||
},
|
||||
|
||||
@action
|
||||
createNewTopicViaParams(title, body, categoryId, tags) {
|
||||
deprecated(
|
||||
"createNewTopicViaParam on the application route is deprecated. Use the composer service instead",
|
||||
@ -234,6 +253,7 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
});
|
||||
},
|
||||
|
||||
@action
|
||||
createNewMessageViaParams({
|
||||
recipients = "",
|
||||
topicTitle = "",
|
||||
@ -251,7 +271,6 @@ const ApplicationRoute = DiscourseRoute.extend({
|
||||
hasGroups,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
handleShowLogin() {
|
||||
if (this.siteSettings.enable_discourse_connect) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user