1
0
mirror of https://github.com/flarum/core.git synced 2025-01-18 06:38:25 +01:00

Helper method for adding menu separators

This commit is contained in:
Toby Zerner 2015-02-12 15:16:15 +10:30
parent 2bd5471699
commit 1a11194ca8
2 changed files with 17 additions and 13 deletions

View File

@ -2,7 +2,6 @@ import Ember from 'ember';
import HasItemLists from 'flarum/mixins/has-item-lists';
import DropdownButton from 'flarum/components/ui/dropdown-button';
import SeparatorItem from 'flarum/components/ui/separator-item';
export default DropdownButton.extend(HasItemLists, {
layoutName: 'components/application/user-dropdown',
@ -13,15 +12,12 @@ export default DropdownButton.extend(HasItemLists, {
label: Ember.computed.alias('user.username'),
populateItems: function(items) {
var self = this;
this.addActionItem(items, 'profile', 'Profile', 'user');
this.addActionItem(items, 'settings', 'Settings', 'cog');
items.pushObject(SeparatorItem.create());
this.addActionItem(items, 'logout', 'Log Out', 'sign-out', null, null, this);
},
actions: {
logout: function() {
this.logout();
}
this.addSeparatorItem(items);
this.addActionItem(items, 'logout', 'Log Out', 'sign-out', null, function() {
self.sendAction('logout');
});
}
})

View File

@ -2,6 +2,7 @@ import Ember from 'ember';
import TaggedArray from 'flarum/utils/tagged-array';
import ActionButton from 'flarum/components/ui/action-button';
import SeparatorItem from 'flarum/components/ui/separator-item';
export default Ember.Mixin.create({
itemLists: [],
@ -23,16 +24,15 @@ export default Ember.Mixin.create({
return items;
},
addActionItem: function(items, tag, label, icon, conditionProperty, actionName, actionTarget) {
addActionItem: function(items, tag, label, icon, conditionProperty, action) {
if (conditionProperty && !this.get(conditionProperty)) { return; }
var self = this;
actionTarget = actionTarget || self.get('controller');
var item = ActionButton.extend({
label: label,
icon: icon,
action: function() {
actionTarget.send(actionName || tag);
action: action || function() {
self.get('controller').send(tag);
}
});
@ -41,5 +41,13 @@ export default Ember.Mixin.create({
items.pushObjectWithTag(itemInstance, tag);
return itemInstance;
},
addSeparatorItem: function(items) {
var length = items.get('length');
var last = items.objectAt(length - 1);
if (last && !(last instanceof SeparatorItem)) {
items.pushObject(SeparatorItem.create());
}
}
});