Make avatar edit menu extensible

This commit is contained in:
Toby Zerner 2015-05-18 14:58:23 +09:30
parent 82dc0cdd7b
commit 3fcf8f3da5

View File

@ -1,6 +1,9 @@
import Component from 'flarum/component'; import Component from 'flarum/component';
import avatar from 'flarum/helpers/avatar'; import avatar from 'flarum/helpers/avatar';
import icon from 'flarum/helpers/icon'; import icon from 'flarum/helpers/icon';
import listItems from 'flarum/helpers/list-items';
import ItemList from 'flarum/utils/item-list';
import ActionButton from 'flarum/components/action-button';
import LoadingIndicator from 'flarum/components/loading-indicator'; import LoadingIndicator from 'flarum/components/loading-indicator';
export default class AvatarEditor extends Component { export default class AvatarEditor extends Component {
@ -20,13 +23,32 @@ export default class AvatarEditor extends Component {
m('a.dropdown-toggle[href=javascript:;][data-toggle=dropdown]', {onclick: this.quickUpload.bind(this)}, [ m('a.dropdown-toggle[href=javascript:;][data-toggle=dropdown]', {onclick: this.quickUpload.bind(this)}, [
this.loading() ? LoadingIndicator.component() : icon('pencil icon') this.loading() ? LoadingIndicator.component() : icon('pencil icon')
]), ]),
m('ul.dropdown-menu', [ m('ul.dropdown-menu', listItems(this.controlItems().toArray()))
m('li', m('a[href=javascript:;]', {onclick: this.upload.bind(this)}, [icon('upload icon'), ' Upload'])),
m('li', m('a[href=javascript:;]', {onclick: this.remove.bind(this)}, [icon('times icon'), ' Remove']))
])
]); ]);
} }
controlItems() {
var items = new ItemList();
items.add('upload',
ActionButton.component({
icon: 'upload',
label: 'Upload',
onclick: this.upload.bind(this)
})
);
items.add('remove',
ActionButton.component({
icon: 'times',
label: 'Remove',
onclick: this.remove.bind(this)
})
);
return items;
}
quickUpload(e) { quickUpload(e) {
if (!this.props.user.avatarUrl()) { if (!this.props.user.avatarUrl()) {
e.preventDefault(); e.preventDefault();