@ -438,30 +438,9 @@ Group.prototype.add = function(item) {
// add to
// add to
if ( item . data . subgroup !== undefined ) {
if ( item . data . subgroup !== undefined ) {
if ( this . subgroups [ item . data . subgroup ] === undefined ) {
this . subgroups [ item . data . subgroup ] = {
height : 0 ,
top : 0 ,
start : item . data . start ,
end : item . data . end ,
visible : false ,
index : this . subgroupIndex ,
items : [ ]
} ;
this . subgroupIndex ++ ;
}
if ( new Date ( item . data . start ) < new Date ( this . subgroups [ item . data . subgroup ] . start ) ) {
this . subgroups [ item . data . subgroup ] . start = item . data . start ;
}
if ( new Date ( item . data . end ) > new Date ( this . subgroups [ item . data . subgroup ] . end ) ) {
this . subgroups [ item . data . subgroup ] . end = item . data . end ;
}
this . subgroups [ item . data . subgroup ] . items . push ( item ) ;
this . _addToSubgroup ( item ) ;
this . orderSubgroups ( ) ;
}
}
this . orderSubgroups ( ) ;
if ( this . visibleItems . indexOf ( item ) == - 1 ) {
if ( this . visibleItems . indexOf ( item ) == - 1 ) {
var range = this . itemSet . body . range ; // TODO: not nice accessing the range like this
var range = this . itemSet . body . range ; // TODO: not nice accessing the range like this
@ -469,6 +448,34 @@ Group.prototype.add = function(item) {
}
}
} ;
} ;
Group . prototype . _addToSubgroup = function ( item , subgroupId ) {
subgroupId = subgroupId || item . data . subgroup ;
if ( subgroupId != undefined && this . subgroups [ subgroupId ] === undefined ) {
this . subgroups [ subgroupId ] = {
height : 0 ,
top : 0 ,
start : item . data . start ,
end : item . data . end ,
visible : false ,
index : this . subgroupIndex ,
items : [ ]
} ;
this . subgroupIndex ++ ;
}
if ( new Date ( item . data . start ) < new Date ( this . subgroups [ subgroupId ] . start ) ) {
this . subgroups [ subgroupId ] . start = item . data . start ;
}
if ( new Date ( item . data . end ) > new Date ( this . subgroups [ subgroupId ] . end ) ) {
this . subgroups [ subgroupId ] . end = item . data . end ;
}
this . subgroups [ subgroupId ] . items . push ( item ) ;
} ;
Group . prototype . _updateSubgroupsSizes = function ( ) {
Group . prototype . _updateSubgroupsSizes = function ( ) {
var me = this ;
var me = this ;
if ( me . subgroups ) {
if ( me . subgroups ) {
@ -539,22 +546,30 @@ Group.prototype.remove = function(item) {
if ( index != - 1 ) this . visibleItems . splice ( index , 1 ) ;
if ( index != - 1 ) this . visibleItems . splice ( index , 1 ) ;
if ( item . data . subgroup !== undefined ) {
if ( item . data . subgroup !== undefined ) {
var subgroup = this . subgroups [ item . data . subgroup ] ;
this . _removeFromSubgroup ( item ) ;
this . orderSubgroups ( ) ;
}
} ;
Group . prototype . _removeFromSubgroup = function ( item , subgroupId ) {
subgroupId = subgroupId || item . data . subgroup ;
if ( subgroupId != undefined ) {
var subgroup = this . subgroups [ subgroupId ] ;
if ( subgroup ) {
if ( subgroup ) {
var itemIndex = subgroup . items . indexOf ( item ) ;
var itemIndex = subgroup . items . indexOf ( item ) ;
subgroup . items . splice ( itemIndex , 1 ) ;
if ( ! subgroup . items . length ) {
delete this . subgroups [ item . data . subgroup ] ;
this . subgroupIndex -- ;
} else {
this . _updateSubgroupsSizes ( ) ;
// Check the item is actually in this subgroup. How should items not in the group be handled?
if ( itemIndex >= 0 ) {
subgroup . items . splice ( itemIndex , 1 ) ;
if ( ! subgroup . items . length ) {
delete this . subgroups [ subgroupId ] ;
} else {
this . _updateSubgroupsSizes ( ) ;
}
}
}
this . orderSubgroups ( ) ;
}
}
}
}
} ;
} ;
/ * *
/ * *
* Remove an item from the corresponding DataSet
* Remove an item from the corresponding DataSet
* @ param { Item } item
* @ param { Item } item
@ -735,6 +750,10 @@ Group.prototype._checkIfVisibleWithReference = function(item, visibleItems, visi
}
}
} ;
} ;
Group . prototype . changeSubgroup = function ( item , oldSubgroup , newSubgroup ) {
this . _removeFromSubgroup ( item , oldSubgroup ) ;
this . _addToSubgroup ( item , newSubgroup ) ;
this . orderSubgroups ( ) ;
} ;
module . exports = Group ;
module . exports = Group ;