export default Ember.Service.extend({
stack_view:[],
open(obj){
},
});
export default Ember.Component.extend({
manager: Ember.inject.service(),
init:function(){
this.get('manager').set('open', this.open);
},
actions: {
open(obj){
console.log('OPEN');
},
});
export default Ember.Component.extend({ // дочерние компоненты
manager: Ember.inject.service(),
actions: {
open(){
this.get('manager').open(this);
},
}
});
<script type="text/x-handlebars" id="components/editor-tabs">
<ul>
{{#each tab in array}}
<li><a {{bind-attr href=tab.route}}>{{tab.name}}</a></li>
{{/each}}
</ul>
{{#each tab in array}}
<div {{bind-attr id=tab.tabTitle}} {{bind-attr path=tab.id}}>
{{tab.text}}
</div>
{{/each}}
</script>
App.EditorTabsComponent = Ember.Component.extend({
didInsertElement: function() {
App.Tabs = this.$().tabs();
this.array.addArrayObserver(this.array, {
willChange: function(cows, offset, removeCount, addCount){
},
didChange:function(cows, offset, removeCount, addCount){
Ember.run.scheduleOnce('afterRender', this, function(){
App.Tabs.tabs('refresh');
});
console.log('didChange', cows.length, offset, removeCount, addCount);
}
});
},
})
App.Object = DS.Model.extend({
children: DS.hasMany('object', {async: true, inverse: 'parent'}),
parent: DS.belongsTo('object', {async: true, inverse: 'children'}),
find_parents: function(elem){
var in_parent = false;
parent = this.get('parent').content
in_parent = parent === elem;
if(!in_parent && parent.get('parent').content){
in_parent = parent.find_parents(elem);
}
return in_parent;
},
});
var move_node = function(options){
var target = options.target;
var element = options.element;
// не является собой, не является потомком себя
if(element != target && !target.find_parents(element)){
var children = target.get('children');
children.pushObject(element);
///////////////////////////////////////////////////////
ИЛИ
element.set('parent', target);
element.save();
}
};
App.ChildNodeComponent = Ember.Component.extend({
attributeBindings : [ 'draggable' ],
draggable : true,
drop: function(event) {
opt = {
'target':this.get('node'),
'element':App.DragerObj,
}
move_node(opt);
}
})
<script type="text/x-handlebars" id="components/child-node">
<li>{{node.name}} {{node.type}}
{{#if node.is_folder}}
<span {{action "openNode" }}>(o)</span>
{{/if}}
</li>
{{#if node.isOpen}}
<ul>
{{#each node_ch in node.children}}
{{child-node node=node_ch}}
{{/each}}
</ul>
{{/if}}
</script>
//Какая то магия для самоссылки
var belongsTo = DS.belongsTo,
hasMany = DS.hasMany;
App.Filefolder = DS.Model.extend({
type: DS.attr('string'),
name: DS.attr('string'),
children: hasMany('filefolder', {async: true, inverse: 'parent'}),
parent: belongsTo('filefolder', {async: true, inverse: 'children'}),
isOpen: false,
is_folder: function(){
return this.get('type') == 0;
}.property('type'),
});
App.FilefoldersRoute = Ember.Route.extend({
model: function(params) {
// Берем безымянный файлфолдер (сервер подставляет корневой)
return this.store.find('filefolder', {'':''});
}
});
App.ChildNodeComponent = Ember.Component.extend({
actions: {
openNode: function() {
console.log('child component');
var model = this.get('node');
model.set('isOpen', true);
}
}
});