mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 05:44:58 +08:00
Helper method for adding menu separators
This commit is contained in:
parent
7001c83fb3
commit
d89bcef816
|
@ -2,7 +2,6 @@ import Ember from 'ember';
|
||||||
|
|
||||||
import HasItemLists from 'flarum/mixins/has-item-lists';
|
import HasItemLists from 'flarum/mixins/has-item-lists';
|
||||||
import DropdownButton from 'flarum/components/ui/dropdown-button';
|
import DropdownButton from 'flarum/components/ui/dropdown-button';
|
||||||
import SeparatorItem from 'flarum/components/ui/separator-item';
|
|
||||||
|
|
||||||
export default DropdownButton.extend(HasItemLists, {
|
export default DropdownButton.extend(HasItemLists, {
|
||||||
layoutName: 'components/application/user-dropdown',
|
layoutName: 'components/application/user-dropdown',
|
||||||
|
@ -13,15 +12,12 @@ export default DropdownButton.extend(HasItemLists, {
|
||||||
label: Ember.computed.alias('user.username'),
|
label: Ember.computed.alias('user.username'),
|
||||||
|
|
||||||
populateItems: function(items) {
|
populateItems: function(items) {
|
||||||
|
var self = this;
|
||||||
this.addActionItem(items, 'profile', 'Profile', 'user');
|
this.addActionItem(items, 'profile', 'Profile', 'user');
|
||||||
this.addActionItem(items, 'settings', 'Settings', 'cog');
|
this.addActionItem(items, 'settings', 'Settings', 'cog');
|
||||||
items.pushObject(SeparatorItem.create());
|
this.addSeparatorItem(items);
|
||||||
this.addActionItem(items, 'logout', 'Log Out', 'sign-out', null, null, this);
|
this.addActionItem(items, 'logout', 'Log Out', 'sign-out', null, function() {
|
||||||
},
|
self.sendAction('logout');
|
||||||
|
});
|
||||||
actions: {
|
|
||||||
logout: function() {
|
|
||||||
this.logout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Ember from 'ember';
|
||||||
|
|
||||||
import TaggedArray from 'flarum/utils/tagged-array';
|
import TaggedArray from 'flarum/utils/tagged-array';
|
||||||
import ActionButton from 'flarum/components/ui/action-button';
|
import ActionButton from 'flarum/components/ui/action-button';
|
||||||
|
import SeparatorItem from 'flarum/components/ui/separator-item';
|
||||||
|
|
||||||
export default Ember.Mixin.create({
|
export default Ember.Mixin.create({
|
||||||
itemLists: [],
|
itemLists: [],
|
||||||
|
@ -23,16 +24,15 @@ export default Ember.Mixin.create({
|
||||||
return items;
|
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; }
|
if (conditionProperty && !this.get(conditionProperty)) { return; }
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
actionTarget = actionTarget || self.get('controller');
|
|
||||||
var item = ActionButton.extend({
|
var item = ActionButton.extend({
|
||||||
label: label,
|
label: label,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
action: function() {
|
action: action || function() {
|
||||||
actionTarget.send(actionName || tag);
|
self.get('controller').send(tag);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -41,5 +41,13 @@ export default Ember.Mixin.create({
|
||||||
items.pushObjectWithTag(itemInstance, tag);
|
items.pushObjectWithTag(itemInstance, tag);
|
||||||
|
|
||||||
return itemInstance;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user