@@ -3,7 +3,7 @@ var format = require('util').format;
3
3
var numeral = require ( 'numeral' ) ;
4
4
var tooltipMixin = require ( '../tooltip-mixin' ) ;
5
5
var _ = require ( 'lodash' ) ;
6
- var debug = require ( 'debug' ) ( 'scout:field-list:type-list' ) ;
6
+ // var debug = require('debug')('scout:field-list:type-list');
7
7
8
8
var TypeListView ;
9
9
@@ -42,7 +42,7 @@ var TypeListItem = View.extend(tooltipMixin, {
42
42
// @see https://github.com/twbs/bootstrap/issues/14769
43
43
this . tooltip ( {
44
44
title : this . tooltip_message ,
45
- placement : this . hasSubtype ? 'bottom' : 'top' ,
45
+ placement : this . isSubtype ? 'bottom' : 'top' ,
46
46
container : 'body'
47
47
} ) . attr ( 'data-original-title' , this . tooltip_message ) ;
48
48
}
@@ -83,7 +83,7 @@ var TypeListItem = View.extend(tooltipMixin, {
83
83
'click .schema-field-wrapper' : 'typeClicked'
84
84
} ,
85
85
subviews : {
86
- subtypes : {
86
+ subtypeView : {
87
87
hook : 'array-subtype-subview' ,
88
88
waitFor : 'model.types' ,
89
89
prepareView : function ( el ) {
@@ -96,9 +96,6 @@ var TypeListItem = View.extend(tooltipMixin, {
96
96
}
97
97
}
98
98
} ,
99
- initialize : function ( ) {
100
- this . on ( 'change:active' , this . activeChanged ) ;
101
- } ,
102
99
typeClicked : function ( evt ) {
103
100
evt . stopPropagation ( ) ;
104
101
@@ -116,14 +113,13 @@ var TypeListItem = View.extend(tooltipMixin, {
116
113
}
117
114
// if type model has changed, render its minichart
118
115
if ( fieldView . type_model !== this . model ) {
116
+ fieldView . types . deactivateAll ( ) ;
119
117
this . active = true ;
118
+ this . selected = false ;
120
119
fieldView . type_model = this . model ;
121
120
fieldView . renderMinicharts ( ) ;
122
121
}
123
122
}
124
- } ,
125
- activeChanged : function ( view , value ) {
126
- debug ( 'active changed to %s for %s -> %s' , value , view . model . parent . name , view . model . name ) ;
127
123
}
128
124
} ) ;
129
125
@@ -139,19 +135,30 @@ TypeListView = module.exports = View.extend({
139
135
parent : 'state'
140
136
} ,
141
137
template : require ( './type-list.jade' ) ,
142
- deactivateOthers : function ( view ) {
138
+ deactivateAll : function ( ) {
143
139
if ( ! this . collectionView ) return ;
144
140
_ . 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 ;
149
143
} ) ;
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
+ }
150
153
} ,
151
154
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
+ }
156
163
}
157
164
} ) ;
0 commit comments