Make the FormModal component more flexible

This commit is contained in:
Toby Zerner 2015-06-12 16:40:20 +09:30
parent 333bb3529d
commit fe94f2a123
7 changed files with 13 additions and 15 deletions

View File

@ -18,7 +18,7 @@ export default class ChangeEmailModal extends FormModal {
return super.view({ return super.view({
className: 'modal-sm change-email-modal', className: 'modal-sm change-email-modal',
title: 'Change Email', title: 'Change Email',
body: this.success() body: m('div.form-centered', this.success()
? [ ? [
m('p.help-text', 'We\'ve sent a confirmation email to ', m('strong', this.email()), '. If it doesn\'t arrive soon, check your spam folder.'), m('p.help-text', 'We\'ve sent a confirmation email to ', m('strong', this.email()), '. If it doesn\'t arrive soon, check your spam folder.'),
m('div.form-group', [ m('div.form-group', [
@ -37,7 +37,7 @@ export default class ChangeEmailModal extends FormModal {
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled}, 'Save Changes') m('button.btn.btn-primary.btn-block[type=submit]', {disabled}, 'Save Changes')
]) ])
] ])
}); });
} }

View File

@ -5,12 +5,12 @@ export default class ChangePasswordModal extends FormModal {
return super.view({ return super.view({
className: 'modal-sm change-password-modal', className: 'modal-sm change-password-modal',
title: 'Change Password', title: 'Change Password',
body: [ body: m('div.form-centered', [
m('p.help-text', 'Click the button below and check your email for a link to change your password.'), m('p.help-text', 'Click the button below and check your email for a link to change your password.'),
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Send Password Reset Email') m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Send Password Reset Email')
]) ])
] ])
}); });
} }

View File

@ -11,7 +11,7 @@ export default class DeleteAccountModal extends FormModal {
return super.view({ return super.view({
className: 'modal-sm change-password-modal', className: 'modal-sm change-password-modal',
title: 'Delete Account', title: 'Delete Account',
body: [ body: m('div.form-centered', [
m('p.help-text', 'Hold up there skippy! If you delete your account, there\'s no going back. All of your posts will be kept, but no longer associated with your account.'), m('p.help-text', 'Hold up there skippy! If you delete your account, there\'s no going back. All of your posts will be kept, but no longer associated with your account.'),
m('div.form-group', [ m('div.form-group', [
m('input.form-control[name=confirm][placeholder=Type "DELETE" to proceed]', {oninput: m.withAttr('value', this.confirmation)}) m('input.form-control[name=confirm][placeholder=Type "DELETE" to proceed]', {oninput: m.withAttr('value', this.confirmation)})
@ -19,7 +19,7 @@ export default class DeleteAccountModal extends FormModal {
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading() || this.confirmation() != 'DELETE'}, 'Delete Account') m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading() || this.confirmation() != 'DELETE'}, 'Delete Account')
]) ])
] ])
}); });
} }

View File

@ -19,7 +19,7 @@ export default class ForgotPasswordModal extends FormModal {
return super.view({ return super.view({
className: 'modal-sm forgot-password', className: 'modal-sm forgot-password',
title: 'Forgot Password', title: 'Forgot Password',
body: this.success() body: m('div.form-centered', this.success()
? [ ? [
m('p.help-text', 'We\'ve sent you an email containing a link to reset your password. Check your spam folder if you don\'t receive it within the next minute or two.'), m('p.help-text', 'We\'ve sent you an email containing a link to reset your password. Check your spam folder if you don\'t receive it within the next minute or two.'),
m('div.form-group', [ m('div.form-group', [
@ -34,7 +34,7 @@ export default class ForgotPasswordModal extends FormModal {
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Recover Password') m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Recover Password')
]) ])
] ])
}); });
} }

View File

@ -23,9 +23,7 @@ export default class FormModal extends Component {
m('form', {onsubmit: this.onsubmit.bind(this)}, [ m('form', {onsubmit: this.onsubmit.bind(this)}, [
m('div.modal-header', m('h3.title-control', options.title)), m('div.modal-header', m('h3.title-control', options.title)),
alert ? m('div.modal-alert', alert) : '', alert ? m('div.modal-alert', alert) : '',
m('div.modal-body', [ m('div.modal-body', options.body),
m('div.form-centered', options.body)
]),
options.footer ? m('div.modal-footer', options.footer) : '' options.footer ? m('div.modal-footer', options.footer) : ''
]) ])
]), ]),

View File

@ -18,7 +18,7 @@ export default class LoginModal extends FormModal {
return super.view({ return super.view({
className: 'modal-sm login-modal', className: 'modal-sm login-modal',
title: 'Log In', title: 'Log In',
body: [ body: m('div.form-centered', [
m('div.form-group', [ m('div.form-group', [
m('input.form-control[name=email][placeholder=Username or Email]', {value: this.email(), onchange: m.withAttr('value', this.email), disabled: this.loading()}) m('input.form-control[name=email][placeholder=Username or Email]', {value: this.email(), onchange: m.withAttr('value', this.email), disabled: this.loading()})
]), ]),
@ -28,7 +28,7 @@ export default class LoginModal extends FormModal {
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Log In') m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Log In')
]) ])
], ]),
footer: [ footer: [
m('p.forgot-password-link', m('a[href=javascript:;]', {onclick: () => { m('p.forgot-password-link', m('a[href=javascript:;]', {onclick: () => {
var email = this.email(); var email = this.email();

View File

@ -22,7 +22,7 @@ export default class SignupModal extends FormModal {
var vdom = super.view({ var vdom = super.view({
className: 'modal-sm signup-modal'+(welcomeUser ? ' signup-modal-success' : ''), className: 'modal-sm signup-modal'+(welcomeUser ? ' signup-modal-success' : ''),
title: 'Sign Up', title: 'Sign Up',
body: [ body: m('div.form-centered', [
m('div.form-group', [ m('div.form-group', [
m('input.form-control[name=username][placeholder=Username]', {value: this.username(), onchange: m.withAttr('value', this.username), disabled: this.loading()}) m('input.form-control[name=username][placeholder=Username]', {value: this.username(), onchange: m.withAttr('value', this.username), disabled: this.loading()})
]), ]),
@ -35,7 +35,7 @@ export default class SignupModal extends FormModal {
m('div.form-group', [ m('div.form-group', [
m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Sign Up') m('button.btn.btn-primary.btn-block[type=submit]', {disabled: this.loading()}, 'Sign Up')
]) ])
], ]),
footer: [ footer: [
m('p.log-in-link', [ m('p.log-in-link', [
'Already have an account? ', 'Already have an account? ',