mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 07:42:48 +08:00
66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
|
import Ember from 'ember';
|
||
|
|
||
|
export default Ember.ArrayProxy.extend({
|
||
|
|
||
|
content: null,
|
||
|
|
||
|
namedViews: null,
|
||
|
|
||
|
init: function() {
|
||
|
this.set('content', Ember.A());
|
||
|
this.set('namedViews', Ember.Object.create());
|
||
|
this._super();
|
||
|
},
|
||
|
|
||
|
// Add an item to the container.
|
||
|
addItem: function(name, viewClass, index) {
|
||
|
// view = this.createChildView(view);
|
||
|
|
||
|
if (typeof index == 'undefined') {
|
||
|
index = this.get('length');
|
||
|
}
|
||
|
this.replace(index, 0, [viewClass]);
|
||
|
this.get('namedViews').set(name, viewClass);
|
||
|
},
|
||
|
|
||
|
// Remove an item from the container.
|
||
|
removeItem: function(name) {
|
||
|
this.removeObject(this.get('namedViews').get(name));
|
||
|
this.get('namedViews').set(name, null);
|
||
|
},
|
||
|
|
||
|
// Replace an item in the container with another one.
|
||
|
replaceItem: function(name, viewClass) {
|
||
|
// view = this.createChildView(view);
|
||
|
|
||
|
var oldView = this.get('namedViews').get(name);
|
||
|
var index = this.indexOf(oldView);
|
||
|
this.replace(index, 1, [viewClass])
|
||
|
this.get('namedViews').set(name, viewClass);
|
||
|
},
|
||
|
|
||
|
// Move an item in the container to a new position.
|
||
|
moveItem: function(name, index) {
|
||
|
var view = this.get('namedViews').get(name);
|
||
|
this.removeItem(name);
|
||
|
this.addItem(name, view, index);
|
||
|
},
|
||
|
|
||
|
firstItem: function() {
|
||
|
return this.objectAt(0);
|
||
|
}.property(),
|
||
|
|
||
|
secondItem: function() {
|
||
|
return this.objectAt(1);
|
||
|
}.property(),
|
||
|
|
||
|
remainingItems: function() {
|
||
|
return this.slice(2);
|
||
|
}.property(),
|
||
|
|
||
|
getItem: function(name) {
|
||
|
return this.get('namedViews').get(name);
|
||
|
}
|
||
|
|
||
|
});
|