Fix expand/collapse for treeview.

This commit is contained in:
Julia Radzhabova 2017-12-20 14:09:31 +03:00
parent f76532ac36
commit 760493b15a
2 changed files with 36 additions and 9 deletions

View file

@ -65,7 +65,7 @@ define([
Common.UI.TreeViewStore = Backbone.Collection.extend({ Common.UI.TreeViewStore = Backbone.Collection.extend({
model: Common.UI.TreeViewModel, model: Common.UI.TreeViewModel,
expand: function(record) { expandSubItems: function(record) {
var me = this; var me = this;
var _expand_sub_items = function(idx, expanded, level) { var _expand_sub_items = function(idx, expanded, level) {
for (var i=idx+1; i<me.length; i++) { for (var i=idx+1; i<me.length; i++) {
@ -86,7 +86,7 @@ define([
_expand_sub_items(record.get('index'), true, record.get('level')); _expand_sub_items(record.get('index'), true, record.get('level'));
}, },
collapse: function(record) { collapseSubItems: function(record) {
var start_level = record.get('level'), var start_level = record.get('level'),
index = record.get('index'); index = record.get('index');
for (var i=index+1; i<this.length; i++) { for (var i=index+1; i<this.length; i++) {
@ -98,6 +98,22 @@ define([
break; break;
} }
} }
return i-1;
},
expandAll: function() {
this.each(function(item) {
item.set('isExpanded', true);
item.set('isVisible', true);
});
},
collapseAll: function() {
for (var i=0; i<this.length; i++) {
var item = this.at(i);
item.set('isExpanded', false);
i = this.collapseSubItems(item);
}
} }
}); });
@ -176,22 +192,19 @@ define([
var isExpanded = !record.get('isExpanded'); var isExpanded = !record.get('isExpanded');
record.set('isExpanded', isExpanded); record.set('isExpanded', isExpanded);
this.store[(isExpanded) ? 'expand' : 'collapse'](record); this.store[(isExpanded) ? 'expandSubItems' : 'collapseSubItems'](record);
this.scroller.update({minScrollbarLength: 40}); this.scroller.update({minScrollbarLength: 40});
} else } else
Common.UI.DataView.prototype.onClickItem.call(this, view, record, e); Common.UI.DataView.prototype.onClickItem.call(this, view, record, e);
}, },
expandAll: function() { expandAll: function() {
this.store.each(function(item) { this.store.expandAll();
item.set('isExpanded', true);
});
this.store.expand(this.store.at(0));
this.scroller.update({minScrollbarLength: 40}); this.scroller.update({minScrollbarLength: 40});
}, },
collapseAll: function() { collapseAll: function() {
this.store.collapse(this.store.at(0)); this.store.collapseAll();
this.scroller.update({minScrollbarLength: 40}); this.scroller.update({minScrollbarLength: 40});
} }
} }

View file

@ -1,5 +1,19 @@
.treeview { .treeview {
.item { &.inner {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
.empty-text {
text-align: center;
height: 100%;
width: 100%;
color: #b2b2b2;
}
}
> .item {
display: block; display: block;
width: 100%; width: 100%;
.box-shadow(none); .box-shadow(none);