Skip to content

Commit 8f951e8

Browse files
rueckstiesskangas
authored andcommitted
all types and subtypes are mutually exclusive on active
1 parent beafc42 commit 8f951e8

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/field-list/type-list.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var format = require('util').format;
33
var numeral = require('numeral');
44
var tooltipMixin = require('../tooltip-mixin');
55
var _ = require('lodash');
6-
var debug = require('debug')('scout:field-list:type-list');
6+
// var debug = require('debug')('scout:field-list:type-list');
77

88
var TypeListView;
99

@@ -42,7 +42,7 @@ var TypeListItem = View.extend(tooltipMixin, {
4242
// @see https://github.com/twbs/bootstrap/issues/14769
4343
this.tooltip({
4444
title: this.tooltip_message,
45-
placement: this.hasSubtype ? 'bottom' : 'top',
45+
placement: this.isSubtype ? 'bottom' : 'top',
4646
container: 'body'
4747
}).attr('data-original-title', this.tooltip_message);
4848
}
@@ -83,7 +83,7 @@ var TypeListItem = View.extend(tooltipMixin, {
8383
'click .schema-field-wrapper': 'typeClicked'
8484
},
8585
subviews: {
86-
subtypes: {
86+
subtypeView: {
8787
hook: 'array-subtype-subview',
8888
waitFor: 'model.types',
8989
prepareView: function(el) {
@@ -96,9 +96,6 @@ var TypeListItem = View.extend(tooltipMixin, {
9696
}
9797
}
9898
},
99-
initialize: function() {
100-
this.on('change:active', this.activeChanged);
101-
},
10299
typeClicked: function(evt) {
103100
evt.stopPropagation();
104101

@@ -116,14 +113,13 @@ var TypeListItem = View.extend(tooltipMixin, {
116113
}
117114
// if type model has changed, render its minichart
118115
if (fieldView.type_model !== this.model) {
116+
fieldView.types.deactivateAll();
119117
this.active = true;
118+
this.selected = false;
120119
fieldView.type_model = this.model;
121120
fieldView.renderMinicharts();
122121
}
123122
}
124-
},
125-
activeChanged: function(view, value) {
126-
debug('active changed to %s for %s -> %s', value, view.model.parent.name, view.model.name);
127123
}
128124
});
129125

@@ -139,19 +135,30 @@ TypeListView = module.exports = View.extend({
139135
parent: 'state'
140136
},
141137
template: require('./type-list.jade'),
142-
deactivateOthers: function(view) {
138+
deactivateAll: function() {
143139
if (!this.collectionView) return;
144140
_.each(this.collectionView.views, function(typeView) {
145-
if (view !== typeView) {
146-
typeView.active = false;
147-
typeView.selected = false;
148-
}
141+
typeView.active = false;
142+
typeView.selected = false;
149143
});
144+
// also deactivate the array subtypes
145+
if (!_.get(this, 'parent.isSubtype')) {
146+
var arrayView = _.find(this.collectionView.views, function(view) {
147+
return view.model.name === 'Array';
148+
});
149+
if (arrayView) {
150+
arrayView.subtypeView.deactivateAll();
151+
}
152+
}
150153
},
151154
render: function() {
152-
this.renderWithTemplate(this);
153-
this.collectionView = this.renderCollection(this.collection, TypeListItem,
154-
this.queryByHook('types'));
155-
this.collectionView.views[0].active = true;
155+
if (!_.get(this, 'parent.isSubtype')) {
156+
this.renderWithTemplate(this);
157+
this.collectionView = this.renderCollection(this.collection, TypeListItem,
158+
this.queryByHook('types'));
159+
}
160+
if (!this.hasSubtypes) {
161+
this.collectionView.views[0].active = true;
162+
}
156163
}
157164
});

0 commit comments

Comments
 (0)