1
0
mirror of https://github.com/flarum/core.git synced 2025-07-20 08:11:27 +02:00
Files
php-flarum/js/forum/src/components/form-modal.js
2015-06-12 16:40:20 +09:30

57 lines
1.5 KiB
JavaScript

import Component from 'flarum/component';
import LoadingIndicator from 'flarum/components/loading-indicator';
import Alert from 'flarum/components/alert';
import icon from 'flarum/helpers/icon';
export default class FormModal extends Component {
constructor(props) {
super(props);
this.alert = m.prop();
this.loading = m.prop(false);
}
view(options) {
var alert = this.alert();
if (alert) {
alert.props.dismissible = false;
}
return m('div.modal-dialog', {className: options.className, config: this.element}, [
m('div.modal-content', [
m('a[href=javascript:;].btn.btn-icon.btn-link.close.back-control', {onclick: this.hide.bind(this)}, icon('times')),
m('form', {onsubmit: this.onsubmit.bind(this)}, [
m('div.modal-header', m('h3.title-control', options.title)),
alert ? m('div.modal-alert', alert) : '',
m('div.modal-body', options.body),
options.footer ? m('div.modal-footer', options.footer) : ''
])
]),
LoadingIndicator.component({className: 'modal-loading'+(this.loading() ? ' active' : '')})
])
}
ready() {
this.$(':input:first').select();
}
hide() {
app.modal.close();
}
handleErrors(errors) {
if (errors) {
this.alert(new Alert({
type: 'warning',
message: errors.map((error, k) => [error.detail, k < errors.length - 1 ? m('br') : ''])
}));
}
m.redraw();
if (errors) {
this.$('[name='+errors[0].path+']').select();
}
}
}