From 7638571b823c1eaf7d6a5f8511757babf48a550d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 4 May 2015 10:44:03 +0930 Subject: [PATCH] Show login modal when starting a discussion as a guest --- framework/core/js/forum/src/components/index-page.js | 6 +++++- framework/core/js/forum/src/components/login-modal.js | 4 +++- framework/core/js/lib/components/modal.js | 3 ++- framework/core/less/lib/modals.less | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/framework/core/js/forum/src/components/index-page.js b/framework/core/js/forum/src/components/index-page.js index eb20353d6..a8ffb5185 100644 --- a/framework/core/js/forum/src/components/index-page.js +++ b/framework/core/js/forum/src/components/index-page.js @@ -7,6 +7,7 @@ import mixin from 'flarum/utils/mixin'; import DiscussionList from 'flarum/components/discussion-list'; import WelcomeHero from 'flarum/components/welcome-hero'; import ComposerDiscussion from 'flarum/components/composer-discussion'; +import LoginModal from 'flarum/components/login-modal'; import SelectInput from 'flarum/components/select-input'; import ActionButton from 'flarum/components/action-button'; @@ -124,7 +125,10 @@ export default class IndexPage extends Component { app.composer.load(new ComposerDiscussion({ user: app.session.user() })); app.composer.show(); } else { - // signup + app.modal.show(new LoginModal({ + message: 'You must be logged in to do that.', + callback: this.newDiscussion.bind(this) + })); } } diff --git a/framework/core/js/forum/src/components/login-modal.js b/framework/core/js/forum/src/components/login-modal.js index 0cccca498..7ae76edf3 100644 --- a/framework/core/js/forum/src/components/login-modal.js +++ b/framework/core/js/forum/src/components/login-modal.js @@ -17,6 +17,7 @@ export default class LoginModal extends Component { m('button.btn.btn-icon.btn-link.close.back-control', {onclick: app.modal.close.bind(app.modal)}, icon('times')), m('form', {onsubmit: this.login.bind(this)}, [ m('div.modal-header', m('h3.title-control', 'Log In')), + this.props.message ? m('div.modal-alert.alert', this.props.message) : '', m('div.modal-body', [ m('div.form-centered', [ m('div.form-group', [ @@ -47,8 +48,9 @@ export default class LoginModal extends Component { login(e) { e.preventDefault(); this.loading(true); - app.session.login(this.email(), this.password()).then(function() { + app.session.login(this.email(), this.password()).then(() => { app.modal.close(); + this.props.callback && this.props.callback(); }, (response) => { this.loading(false); m.redraw(); diff --git a/framework/core/js/lib/components/modal.js b/framework/core/js/lib/components/modal.js index 4167f6c08..b8746c2c5 100644 --- a/framework/core/js/lib/components/modal.js +++ b/framework/core/js/lib/components/modal.js @@ -16,13 +16,14 @@ export default class Modal extends Component { } show(component) { + clearTimeout(this.hideTimeout); this.component = component; m.redraw(true); this.$().modal('show'); } close() { - this.$().modal('hide'); + this.hideTimeout = setTimeout(() => this.$().modal('hide')); } destroy() { diff --git a/framework/core/less/lib/modals.less b/framework/core/less/lib/modals.less index faf0130c4..d9bae6d77 100644 --- a/framework/core/less/lib/modals.less +++ b/framework/core/less/lib/modals.less @@ -8,6 +8,9 @@ opacity: 0.9; } } +.modal-alert { + text-align: center; +} .modal-body { background-color: @fl-body-secondary-color; padding: 25px;