mirror of
https://github.com/flarum/framework.git
synced 2025-01-21 20:08:46 +08:00
8683025ef6
This means the component instance is created in the template, meaning properties can be overridden in the view helper. It also just makes more sense - a view instance doesn’t need to exist until it is rendered in the template.
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
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: [],
|
|
|
|
initItemLists: Ember.on('didInsertElement', function() {
|
|
var self = this;
|
|
this.get('itemLists').forEach(function(name) {
|
|
self.initItemList(name);
|
|
});
|
|
}),
|
|
|
|
initItemList: function(name) {
|
|
this.set(name, this.populateItemList(name));
|
|
},
|
|
|
|
populateItemList: function(name) {
|
|
var items = TaggedArray.create();
|
|
this.trigger('populate'+name.charAt(0).toUpperCase()+name.slice(1), items);
|
|
this.removeUnneededSeparatorItems(items);
|
|
return items;
|
|
},
|
|
|
|
addActionItem: function(items, tag, label, icon, conditionProperty, action) {
|
|
if (conditionProperty && !this.get(conditionProperty)) { return; }
|
|
|
|
var self = this;
|
|
var item = ActionButton.extend({
|
|
label: label,
|
|
icon: icon,
|
|
action: action || function() {
|
|
self.get('controller').send(tag);
|
|
}
|
|
});
|
|
|
|
items.pushObjectWithTag(item, tag);
|
|
|
|
return item;
|
|
},
|
|
|
|
addSeparatorItem: function(items) {
|
|
items.pushObject(SeparatorItem);
|
|
},
|
|
|
|
removeUnneededSeparatorItems: function(items) {
|
|
var prevItem = null;
|
|
items.forEach(function(item) {
|
|
if (prevItem === SeparatorItem && item === SeparatorItem) {
|
|
items.removeObject(item);
|
|
return;
|
|
}
|
|
prevItem = item;
|
|
});
|
|
if (prevItem === SeparatorItem) {
|
|
items.removeObject(prevItem);
|
|
}
|
|
}
|
|
});
|