@ -29,10 +29,10 @@ define([
. attr ( 'id' , guid )
. addClass ( 'panel-group' ) ;
this . model . on ( 'change:selected_index' , function ( model , value , options ) {
this . update _selected _index ( model. previous ( 'selected_index' ) , value , options) ;
this . update _selected _index ( options) ;
} , this ) ;
this . model . on ( 'change:_titles' , function ( model , value , options ) {
this . update _titles ( value ) ;
this . update _titles ( options ) ;
} , this ) ;
this . on ( 'displayed' , function ( ) {
this . update _titles ( ) ;
@ -40,14 +40,23 @@ define([
this . children _views . update ( this . model . get ( 'children' ) ) ;
} ,
update _titles : function ( titles ) {
/ * *
* Update the contents of this view
*
* Called when the model is changed . The model may have been
* changed by another view or by a state update from the back - end .
* /
update : function ( options ) {
this . update _titles ( ) ;
this . update _selected _index ( options ) ;
return TabView . _ _super _ _ . update . apply ( this ) ;
} ,
update _titles : function ( ) {
/ * *
* Set tab titles
* /
if ( ! titles ) {
titles = this . model . get ( '_titles' ) ;
}
var titles = this . model . get ( '_titles' ) ;
var that = this ;
_ . each ( titles , function ( title , page _index ) {
var accordian = that . containers [ page _index ] ;
@ -60,12 +69,14 @@ define([
} ) ;
} ,
update _selected _index : function ( o ld_index , new _index , o ptions) {
update _selected _index : function ( o ptions) {
/ * *
* Only update the selection if the selection wasn ' t triggered
* by the front - end . It must be triggered by the back - end .
* /
if ( options === undefined || options . updated _view != this ) {
var old _index = this . model . previous ( 'selected_index' ) ;
var new _index = this . model . get ( 'selected_index' ) ;
this . containers [ old _index ] . find ( '.panel-collapse' ) . collapse ( 'hide' ) ;
if ( 0 <= new _index && new _index < this . containers . length ) {
this . containers [ new _index ] . find ( '.panel-collapse' ) . collapse ( 'show' ) ;
@ -211,7 +222,6 @@ define([
var tab = $ ( '<li />' )
. css ( 'list-style-type' , 'none' )
. appendTo ( this . $tabs ) ;
var tab _text = $ ( '<a />' )
. attr ( 'href' , '#' + uuid )
@ -235,6 +245,7 @@ define([
. append ( dummy )
. appendTo ( that . $tab _contents ) ;
this . update ( ) ;
return this . create _child _view ( model ) . then ( function ( view ) {
dummy . replaceWith ( view . $el ) ;
view . parent _tab = tab ;
@ -243,6 +254,7 @@ define([
// Trigger the displayed event of the child view.
that . after _displayed ( function ( ) {
view . trigger ( 'displayed' ) ;
that . update ( ) ;
} ) ;
return view ;
} ) . catch ( utils . reject ( "Couldn't add child view to box" , true ) ) ;
@ -255,23 +267,35 @@ define([
* Called when the model is changed . The model may have been
* changed by another view or by a state update from the back - end .
* /
if ( options === undefined || options . updated _view != this ) {
// Set tab titles
var titles = this . model . get ( '_titles' ) ;
var that = this ;
_ . each ( titles , function ( title , page _index ) {
var tab _text = that . containers [ page _index ] ;
if ( tab _text !== undefined ) {
tab _text . text ( title ) ;
}
} ) ;
this . update _titles ( ) ;
this . update _selected _index ( options ) ;
return TabView . _ _super _ _ . update . apply ( this ) ;
} ,
/ * *
* Updates the tab page titles .
* /
update _titles : function ( ) {
var titles = this . model . get ( '_titles' ) ;
var that = this ;
_ . each ( titles , function ( title , page _index ) {
var tab _text = that . containers [ page _index ] ;
if ( tab _text !== undefined ) {
tab _text . text ( title ) ;
}
} ) ;
} ,
/ * *
* Updates the tab page titles .
* /
update _selected _index : function ( options ) {
if ( options === undefined || options . updated _view != this ) {
var selected _index = this . model . get ( 'selected_index' ) ;
if ( 0 <= selected _index && selected _index < this . containers . length ) {
this . select _page ( selected _index ) ;
}
}
return TabView . _ _super _ _ . update . apply ( this ) ;
} ,
select _page : function ( index ) {