@ -6,7 +6,8 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
listen : {
controller : {
'*' : {
confirmCFRemoval : 'confirmCFRemoval'
confirmCFRemoval : 'confirmCFRemoval' ,
cfReloadStore : 'cfReLoadStore'
}
} ,
store : {
@ -129,7 +130,21 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ;
} ,
sortDestinationsetByPriority : function ( destinations ) {
getStoreNameFromRoute : function ( route ) {
switch ( route ) {
case ( '#callforward/always' ) :
return 'CallForwardAlways' ;
break ;
case ( '#callforward/afterhours' ) :
return 'CallForwardAfterHours' ;
break ;
case ( '#callforward/companyhours' ) :
return 'CallForwardCompanyHours' ;
break ;
} ;
} ,
sortDestinationsetByPriority : function ( destinations ) {
var sorted = destinations . sort ( function ( a , b ) {
return parseFloat ( a . priority ) - parseFloat ( b . priority ) ;
} ) ;
@ -155,7 +170,6 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var arrayOfModels = [ ] ;
var currentRoute = window . location . hash ;
var routeTimeset = this . getTimesetFromRoute ( currentRoute ) ;
if ( me . getView ( ) . _preventReLoad ) return ;
store . removeAll ( ) ;
// TODO optimize, too many nested loops affects performance.
// Ex. Where possible use break Ext.each by return false;
@ -164,30 +178,29 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
success : function ( response , opts ) {
var decodedResponse = Ext . decode ( response . responseText ) ;
if ( decodedResponse . _embedded ) {
var destinationsets = decodedResponse . _embedded [ 'ngcp:cfdestinationsets' ] ;
destinationsets [ 0 ] . destinations = me . sortDestinationsetByPriority ( destinationsets [ 0 ] . destinations ) ;
me . getView ( ) . _preventReLoad = true ; // assumes there is no need to reload the store
Ext . each ( cfTypeArrayOfObjects , function ( cfTypeObjects , index ) {
var cfdestinationsets = decodedResponse . _embedded [ 'ngcp:cfdestinationsets' ] ;
cfdestinationsets [ 0 ] . destinations = me . sortDestinationsetByPriority ( cfdestinationsets [ 0 ] . destinations ) ;
Ext . each ( cfTypeArrayOfObjects , function ( cfTypeObjects , index ) {
var cfType = cfTypes [ index ] ;
cfType !== 'cft' && me . addCftOwnPhone ( destinationsets[ 0 ] . destinations ) ; // if 'cft' we invoke addCftOwnPhone()
cfType !== 'cft' && me . addCftOwnPhone ( cf destinationsets[ 0 ] . destinations ) ; // cfType is 'cft' we invoke addCftOwnPhone()
Ext . each ( cfTypeObjects , function ( cfTypeObject ) {
var destinationsetName = cfTypeObject . destinationset ;
var sourcesetName = cfTypeObject . sourceset ;
var timesetName = cfTypeObject . timeset ;
if ( timesetName == routeTimeset ) {
Ext . each ( destinationsets, function ( destinationset) {
if ( destinationset. name == destinationsetName) {
for ( item in destinationset. destinations ) {
var destinationToDisplayInGrid = me . getDestinationFromSipId ( destinationset. destinations [ item ] . destination ) ;
var destinationAnnouncementId = destinationset. announcement _id ;
var destination = destinationset. destinations [ item ] . destination ;
var priority = destinationset. destinations [ item ] . priority ;
var timeout = destinationset. destinations [ item ] . timeout ;
var destinationId = destinationset. id ;
var destinationName = destinationset. name ;
var cfmappings = { } ;
cfmappings . destinationsetName = cfTypeObject . destinationset ;
cfmappings . sourcesetName = cfTypeObject . sourceset ;
cfmappings . timesetName = cfTypeObject . timeset ;
if ( cfmappings. timesetName == routeTimeset ) {
Ext . each ( cf destinationsets, function ( cf destinationset) {
if ( cf destinationset. name == cfmappings. destinationsetName && ! cfmappings . _modelCreated ) {
for ( item in cf destinationset. destinations ) {
var destinationToDisplayInGrid = me . getDestinationFromSipId ( cf destinationset. destinations [ item ] . destination ) ;
var destinationAnnouncementId = cf destinationset. announcement _id ;
var destination = cf destinationset. destinations [ item ] . destination ;
var priority = cf destinationset. destinations [ item ] . priority ;
var timeout = cf destinationset. destinations [ item ] . timeout ;
var destinationId = cf destinationset. id ;
var destinationName = cf destinationset. name ;
// Removes timeout if destination is not a number
var ringFor = ! Ext . isNumber ( parseInt ( destinationToDisplayInGrid ) ) ? '' : destinationset. destinations [ item ] . timeout ;
var ringFor = ! Ext . isNumber ( parseInt ( destinationToDisplayInGrid ) ) ? '' : cf destinationset. destinations [ item ] . timeout ;
var cbModel = Ext . create ( 'NgcpCsc.model.CallForwardDestination' , {
type : cfType ,
destination _displayed : destinationToDisplayInGrid ,
@ -196,12 +209,13 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
priority : priority ,
timeout _displayed : ringFor ,
timeout : timeout ,
sourceset : sourcesetName,
timeset : timesetName,
sourceset : cfmappings. sourcesetName,
timeset : cfmappings. timesetName,
destinationset _id : destinationId ,
destinationset _name : destinationName
} ) ;
arrayOfModels . push ( cbModel ) ;
cfmappings . _modelCreated = true ;
}
}
} ) ;
@ -229,6 +243,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
cfStoreBeforeSync : function ( store , options ) {
var me = this ;
var vm = this . getViewModel ( ) ;
var recordsToSend = [ ] ;
delete options [ 'destroy' ] ;
delete options [ 'create' ] ;
@ -276,7 +291,10 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
"value" : obj . records
} ] ,
success : function ( response , opts ) {
store . commitChanges ( ) ;
var currentRoute = window . location . hash ;
var currentStoreName = me . getStoreNameFromRoute ( currentRoute ) ;
Ext . getStore ( currentStoreName ) . load ( ) ;
vm . set ( 'last_store_synced' , currentStoreName ) ;
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
@ -286,7 +304,17 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
return false ;
} ,
cfSourcesetBeforeSync : function ( store , options ) {
cfReLoadStore : function ( ) {
var me = this ;
var vm = this . getViewModel ( ) ;
var currentRoute = window . location . hash ;
var currentStoreName = me . getStoreNameFromRoute ( currentRoute ) ;
if ( vm . get ( 'last_store_synced' ) . length > 0 && currentStoreName !== vm . get ( 'last_store_synced' ) ) {
Ext . getStore ( currentStoreName ) . load ( ) ;
} ;
} ,
cfSourcesetBeforeSync : function ( store , options ) {
// Using Ajax request here as we are using different url
// params for PATCH compared to GET
delete options [ 'destroy' ] ;
@ -535,7 +563,10 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var type = me . 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 ) ;
@ -545,6 +576,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
Ext . each ( stores , function ( store ) {
store . commitChanges ( ) ;
me . setLabelTerminationType ( store ) ;
store . _emptied = false ;
} ) ;
}
} ,