@ -165,53 +165,42 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
return mapping . length !== 0 ;
} ,
buildArrayOfModels : function ( cfMappings , cfType , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels ) {
buildArrayOfModels : function ( cfMappings , cfType , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels , hasCftAndCfuMappings ) {
var $cf = this ;
Ext . each ( cfMappings , function ( mapping , j ) {
var cfmappings = { } ;
if ( cfType === 'cfu' && j === 1 ) { return false ; } ;
cfmappings . destinationsetName = mapping . destinationset ;
cfmappings . sourcesetName = mapping . sourceset ;
cfmappings . timesetName = mapping . timeset ;
if ( cfmappings . timesetName == routeTimeset ) {
// A destinationset can be used as mapping for mutiple call forwarding types, so
// we can not break out of this loop better than we already are. _modelCreated
// is already in place to make sure we don't go deeper in the loops if the current
// cftype already has that destinationset added as model
var currentMapping = { } ;
currentMapping . destinationsetName = mapping . destinationset ;
currentMapping . sourcesetName = mapping . sourceset ;
currentMapping . timesetName = mapping . timeset ;
if ( currentMapping . timesetName == routeTimeset ) {
Ext . each ( cfdestinationsets , function ( cfdestinationset ) {
if ( cfType !== 'cft' || ! hasCftAndCfuMappings && cfType === 'cft' ) {
if ( cfdestinationset . name == cfmappings . destinationsetName && ! cfmappings . _modelCreated ) {
if ( cfType . match ( /(cfb|cfna)/ ) || cfType === 'cfu' && cfMappings [ 0 ] . destinationset === mapping . destinationset || ! hasCftAndCfuMappings && cfType === 'cft' ) {
// _modelCreated check in place to make sure we don't add the destinationset more
// than one time if the cftype already has that destinationset added as model
if ( cfdestinationset . name == currentMapping . destinationsetName && ! currentMapping . _modelCreated ) {
cfdestinationset . destinations = $cf . sortDestinationsetByPriority ( cfdestinationset . destinations ) ;
if ( cfType === 'cft' && cfMappings [ 0 ] . destinationset === mapping . destinationset ) {
$cf . addCftOwnPhone ( cfdestinationset . destinations , cftRingTimeout ) ;
} ;
// We can not break out of this one, as we need all destinations of the given
// destinationset added to the store
for ( item in cfdestinationset . destinations ) {
var destinationToDisplayInGrid = $cf . getDestinationFromSipId ( cfdestinationset . destinations [ item ] . destination ) ;
var destinationAnnouncementId = cfdestinationset . announcement _id ;
var destination = cfdestinationset . destinations [ item ] . destination ;
var priority = cfdestinationset . destinations [ item ] . priority ;
var timeout = cfdestinationset . destinations [ item ] . timeout ;
var destinationId = cfdestinationset . id ;
var destinationName = cfdestinationset . name ;
// Removes timeout if destination is not a number
var ringFor = ! Ext . isNumber ( parseInt ( destinationToDisplayInGrid ) ) ? '' : cfdestinationset . destinations [ item ] . timeout ;
var cbModel = Ext . create ( 'NgcpCsc.model.CallForwardDestination' , {
type : cfType ,
destination _displayed : destinationToDisplayInGrid ,
destination : destination,
destination _announcement _id : destinationAnnouncementI d,
priority : priority,
destination : cfdestinationset . destinations [ item ] . destination ,
destination _announcement _id : cfdestinationset. announcement _i d,
priority : cfdestinationset. destinations [ item ] . priority,
timeout _displayed : ringFor ,
timeout : timeout,
sourceset : c fmappings . sourcesetName ,
timeset : c fmappings . timesetName ,
destinationset _id : destinationI d,
destinationset _name : destinationN ame
timeout : cfdestinationset. destinations [ item ] . timeout,
sourceset : c urrentMapping . sourcesetName ,
timeset : c urrentMapping . timesetName ,
destinationset _id : cfdestinationset. i d,
destinationset _name : cfdestinationset. n ame
} ) ;
arrayOfModels . push ( cbModel ) ;
c fmappings . _modelCreated = true ;
c urrentMapping . _modelCreated = true ;
}
}
} ;
@ -233,6 +222,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var arrayOfModels = [ ] ;
var currentRoute = window . location . hash ;
var routeTimeset = this . getTimesetFromRoute ( currentRoute ) ;
$vm . set ( 'destStoresPopulated' , false ) ;
$vm . set ( 'cft_ringtimeout' , cftRingTimeout ) ;
store . removeAll ( ) ;
Ext . Ajax . request ( {
@ -243,11 +233,12 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var cfdestinationsets = decodedResponse . _embedded [ 'ngcp:cfdestinationsets' ] ;
$cf . buildArrayOfModels ( cfbMappings , 'cfb' , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels ) ;
$cf . buildArrayOfModels ( cfuMappings , 'cfu' , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels ) ;
$cf . buildArrayOfModels ( cftMappings , 'cft' , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels );
$cf . buildArrayOfModels ( cftMappings , 'cft' , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels , hasCftAndCfuMappings );
$cf . buildArrayOfModels ( cfnaMappings , 'cfna' , routeTimeset , cfdestinationsets , cftRingTimeout , arrayOfModels ) ;
$cf . addOwnPhoneToEmptyOnline ( ) ;
if ( arrayOfModels . length > 0 ) {
$cf . populateDestinationStores ( arrayOfModels ) ;
$vm . set ( 'arrayOfDestModels' , arrayOfModels ) ;
$cf . populateDestinationStores ( ) ;
} ;
} ;
} ,
@ -259,7 +250,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ,
destinationIdExistsInArray : function ( arr , id ) {
hasDestinationWithId : function ( arr , id ) {
return arr . some ( function ( arrObj ) {
return id == arrObj . id ;
} ) ;
@ -275,7 +266,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
Ext . each ( store . getRange ( ) , function ( record ) {
var data = record . getData ( ) ;
if ( data . destination !== 'own phone' ) {
switch ( recordsToSend . length === 0 || ! me . destinationIdExistsInArray ( recordsToSend , data . destinationset _id ) ) {
switch ( recordsToSend . length === 0 || ! me . hasDestinationWithId ( recordsToSend , data . destinationset _id ) ) {
case true :
// if recordsToSend array is empty or recordsToSend does not already contain current destinationset already
if ( data . timeout ) {
@ -622,31 +613,36 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ) ;
} ,
populateDestinationStores : function ( models ) {
populateDestinationStores : function ( ) {
var $cf = this ;
var $vm = $cf . getViewModel ( ) ;
var store ;
var stores = [ ] ;
Ext . each ( models , function ( model ) {
var sourcename = $cf . getSourceNameFromSourceSet ( model . get ( 'sourceset' ) ) ;
var timename = $cf . getTimeNameFromTimeSet ( model . get ( 'timeset' ) ) ;
var type = $cf . getGridCategoryFromType ( model . get ( 'type' ) ) ;
var storeName = sourcename + timename + type ;
store = Ext . getStore ( storeName ) ;
if ( ! store . _emptied ) {
store . removeAll ( ) ;
store . _emptied = true ;
}
if ( store ) {
store . add ( model ) ;
stores . push ( store ) ;
}
} ) ;
if ( store ) {
Ext . each ( stores , function ( store ) {
store . commitChanges ( ) ;
$cf . setLabelTerminationType ( store ) ;
store . _emptied = false ;
var models = $vm . get ( 'arrayOfDestModels' ) ;
if ( models && ! $vm . get ( 'destStoresPopulated' ) ) {
Ext . each ( models , function ( model ) {
var sourcename = $cf . getSourceNameFromSourceSet ( model . get ( 'sourceset' ) ) ;
var timename = $cf . getTimeNameFromTimeSet ( model . get ( 'timeset' ) ) ;
var type = $cf . getGridCategoryFromType ( model . get ( 'type' ) ) ;
var storeName = sourcename + timename + type ;
store = Ext . getStore ( storeName ) ;
if ( store ) {
if ( ! store . _emptied ) {
store . removeAll ( ) ;
store . _emptied = true ;
}
store . add ( model ) ;
stores . push ( store ) ;
}
} ) ;
if ( store ) {
Ext . each ( stores , function ( store ) {
store . commitChanges ( ) ;
$cf . setLabelTerminationType ( store ) ;
store . _emptied = false ;
} ) ;
} ;
$vm . set ( 'destStoresPopulated' , true ) ;
} ;
} ,
@ -717,6 +713,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
return ;
}
} ) ;
$cf . populateDestinationStores ( ) ;
} else {
var models = [ ] ;
Ext . Ajax . request ( {