@ -13,33 +13,49 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
'*' : {
cfStoreLoaded : 'cfStoreLoaded' ,
cfTimesetStoreLoaded : 'cfTimesetStoreLoaded' ,
cfSourcesetStoreLoaded : 'cfSourcesetStoreLoaded'
cfSourcesetStoreLoaded : 'cfSourcesetStoreLoaded' ,
cfStoreBeforeSync : 'cfStoreBeforeSync' ,
cfSourcesetBeforeSync : 'cfSourcesetBeforeSync' ,
cfTimesetBeforeSync : 'cfTimesetBeforeSync'
}
}
} ,
destinationDropped : function ( node , data , overModel , dropPosition , eOpts ) {
// TODO: Leaving uncommented code here for upcoming task #17654
// var store = Ext.getStore('everybody-always-CallForwardBusy');
// Ext.each(store.getRange(), function(record) {
// console.log(record.get('destination_cleaned'));
// })
} ,
cfTimesetStoreLoaded : function ( store , data ) {
var me = this ;
var arrayOfModels = [ ] ;
var timesets ;
if ( data . getData ( ) . _embedded == undefined ) {
return ;
} else {
timesets = data . getData ( ) . _embedded [ 'ngcp:cftimesets' ] ;
}
store . removeAll ( ) ;
Ext . each ( data , function ( timeset ) {
Ext . each ( timesets , function ( timeset ) {
var timesetName = timeset . name ;
var timesetId = timeset . id ;
if ( timesetName == 'After Hours' || timesetName == 'Company Hours' ) {
me . setVmToTrue ( timesetName ) ;
if ( /(After|Company)\s(Hours)/ . test ( timesetName ) ) {
var times = me . getModelValuesFromTimesData ( timeset . times [ 0 ] ) ;
Ext . each ( times . days , function ( weekday ) {
var c b Model = Ext . create ( 'NgcpCsc.model.CallForward' , {
var c f Model = Ext . create ( 'NgcpCsc.model.CallForward' , {
id : Ext . id ( ) ,
timeset _name : timesetName ,
timeset _id : timesetId ,
time _from : times . timeFrom ,
time _to : times . timeTo ,
day : weekday ,
closed : false // TODO: (For PUT/PATCH ticket) decide
// if we should keep this, or solve this
// differently, or not at all
closed : false
} ) ;
arrayOfModels . push ( c b Model) ;
arrayOfModels . push ( cfModel ) ;
} ) ;
} ;
} ) ;
@ -47,26 +63,52 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
me . populateTimesetStores ( arrayOfModels ) ;
} ;
} ,
setVmToTrue : function ( name ) {
var vm = this . getViewModel ( ) ;
switch ( name ) {
case 'After Hours' :
vm . set ( 'after_hours_exists_in_api' , true ) ;
break ;
case 'Company Hours' :
vm . set ( 'company_hours_exists_in_api' , true ) ;
break ;
case 'List A' :
vm . set ( 'list_a_exists_in_api' , true ) ;
break ;
case 'List B' :
vm . set ( 'list_b_exists_in_api' , true ) ;
break ;
} ;
} ,
cfSourcesetStoreLoaded : function ( store , data ) {
var me = this ;
var arrayOfModels = [ ] ;
store . removeAll ( ) ;
Ext . each ( data , function ( sourceset ) {
var sourcesetName = sourceset . name ;
var sourcesetId = sourceset . id ;
Ext . each ( sourceset . sources , function ( sourceEntry ) {
var cbModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
id : Ext . id ( ) ,
sourceset _name : sourcesetName ,
sourceset _id : sourcesetId ,
source : sourceEntry . source
if ( data . getData ( ) . _embedded == undefined ) {
return ;
} else {
var sourcesets = data . getData ( ) . _embedded [ 'ngcp:cfsourcesets' ] ;
store . removeAll ( ) ;
Ext . each ( sourcesets , function ( sourceset ) {
var sourcesetName = sourceset . name ;
var sourcesetId = sourceset . id ;
me . setVmToTrue ( sourcesetName ) ;
Ext . each ( sourceset . sources , function ( sourceEntry ) {
var cfModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
id : Ext . id ( ) ,
sourceset _name : sourcesetName ,
sourceset _id : sourcesetId ,
source : sourceEntry . source
} ) ;
arrayOfModels . push ( cfModel ) ;
} ) ;
arrayOfModels . push ( cbModel ) ;
} ) ;
} ) ;
if ( arrayOfModels . length > 0 ) {
me . populateSourcesetStores ( arrayOfModels ) ;
} ;
if ( arrayOfModels . length > 0 ) {
me . populateSourcesetStores ( arrayOfModels ) ;
} ;
}
} ,
getTimesetFromRoute : function ( route ) {
@ -82,6 +124,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
break ;
} ;
} ,
cfStoreLoaded : function ( store , data ) {
var me = this ;
var cfTypeArrayOfObjects = [ data . get ( 'cfu' ) , data . get ( 'cft' ) , data . get ( 'cfb' ) , data . get ( 'cfna' ) ] ;
@ -90,59 +133,59 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var arrayOfModels = [ ] ;
var currentRoute = window . location . hash ;
var routeTimeset = this . getTimesetFromRoute ( currentRoute ) ;
if ( me . getView ( ) . _preventReLoad ) {
return ;
}
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;
Ext . Ajax . request ( {
url : window . location . origin + '/api/cfdestinationsets/?subscriber_id=' + localStorage . getItem ( 'subscriber_id' ) ,
url : '/api/cfdestinationsets/?subscriber_id=' + localStorage . getItem ( 'subscriber_id' ) ,
success : function ( response , opts ) {
var decodedResponse = Ext . decode ( response . responseText ) ;
var destinationsets = decodedResponse . _embedded [ 'ngcp:cfdestinationsets' ] ;
me . getView ( ) . _preventReLoad = true ; // assumes there is no need to reload the store
Ext . each ( cfTypeArrayOfObjects , function ( cfTypeObjects , index ) {
var cfType = cfTypes [ index ] ;
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 destinationToUse = me . getDestinationFromSipId ( destinationset . destinations [ item ] . destination ) ;
var destinationAnnouncementId = destinationset . announcement _id ;
var destination = destinationset . destinations [ item ] . destination ;
var priority = destinationset . destinations [ item ] . priority ;
var simpleDestination = destinationset . destinations [ item ] . simple _destination ;
var destinationId = destinationset . id ;
var destinationName = destinationset . name ;
var ringFor = destinationToUse == 'Voicemail' ? '' : destinationset . destinations [ item ] . timeout ;
var cbModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
type : cfType ,
destination _cleaned : destinationToUse ,
destination _announcement _id : destinationAnnouncementId ,
destination : destination ,
priority : priority ,
simple _destination : simpleDestination ,
ring _for : ringFor ,
sourceset : sourcesetName ,
timeset : timesetName ,
destinationset _id : destinationId ,
destinationset _name : destinationName
} ) ;
arrayOfModels . push ( cbModel ) ;
if ( decodedResponse . _embedded ) {
var destinationsets = decodedResponse . _embedded [ 'ngcp:cfdestinationsets' ] ;
me . getView ( ) . _preventReLoad = true ; // assumes there is no need to reload the store
Ext . each ( cfTypeArrayOfObjects , function ( cfTypeObjects , index ) {
var cfType = cfTypes [ index ] ;
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 destinationToUse = me . getDestinationFromSipId ( destinationset . destinations [ item ] . destination ) ;
var destinationAnnouncementId = destinationset . announcement _id ;
var destination = destinationset . destinations [ item ] . destination ;
var priority = destinationset . destinations [ item ] . priority ;
var simpleDestination = destinationset . destinations [ item ] . simple _destination ;
var destinationId = destinationset . id ;
var destinationName = destinationset . name ;
var ringFor = destinationToUse == 'Voicemail' ? '' : destinationset . destinations [ item ] . timeout ;
var cbModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
type : cfType ,
destination _cleaned : destinationToUse ,
destination _announcement _id : destinationAnnouncementId ,
destination : destination ,
priority : priority ,
simple _destination : simpleDestination ,
ring _for : ringFor ,
sourceset : sourcesetName ,
timeset : timesetName ,
destinationset _id : destinationId ,
destinationset _name : destinationName
} ) ;
arrayOfModels . push ( cbModel ) ;
}
}
}
} ) ;
} ;
} ) ;
} ;
} ) ;
} ) ;
} ) ;
if ( arrayOfModels . length > 0 ) {
me . populateDestinationStores ( arrayOfModels ) ;
}
if ( arrayOfModels . length > 0 ) {
me . populateDestinationStores ( arrayOfModels ) ;
} ;
} ;
} ,
failure : function ( response , opts ) {
@ -152,9 +195,124 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ,
destinationIdExistsInArray : function ( arr , id ) {
return arr . some ( function ( arrObj ) {
return id == arrObj . id ;
} ) ;
} ,
cfStoreBeforeSync : function ( store , options ) {
console . log ( 'cfStoreBeforeSync' ) ;
// TODO: (For PUT/PATCH ticket) Base on on CB module implementation
// TODO: #17654 Ensure we also have ability to display and write all
// required destination types, like voicemail, fax, conference, etc
var me = this ;
var recordsToSend = [ ] ;
delete options [ 'destroy' ] ;
delete options [ 'create' ] ;
Ext . each ( store . getRange ( ) , function ( record ) {
var data = record . getData ( ) ;
switch ( recordsToSend . length === 0 || ! me . destinationIdExistsInArray ( recordsToSend , data . destinationset _id ) ) {
case true :
recordsToSend . push ( { id : data . destinationset _id , records : [ { "announcement_id" : null , "destination" : data . simple _destination , "priority" : data . priority , "timeout" : data . ring _for } ] } ) ;
break ;
case false :
recordsToSend . forEach ( function ( obj , index ) {
if ( obj . id == data . destinationset _id ) {
recordsToSend [ index ] . records . push ( { "announcement_id" : null , "destination" : data . simple _destination , "priority" : data . priority , "timeout" : data . ring _for } ) ;
}
} )
} ;
} ) ;
Ext . each ( recordsToSend , function ( obj ) {
Ext . Ajax . request ( {
url : '/api/cfdestinationsets/' + obj . id ,
method : 'PATCH' ,
headers : { 'Content-Type' : 'application/json-patch+json' } ,
jsonData : [ {
"op" : "add" ,
"path" : "/destinations" ,
"value" : obj . records
} ] ,
success : function ( response , opts ) {
store . commitChanges ( ) ;
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
}
} ) ;
} ) ;
return false ;
} ,
cfSourcesetBeforeSync : function ( store , options ) {
// Using Ajax request here as we are using different url
// params for PATCH compared to GET
delete options [ 'destroy' ] ;
delete options [ 'create' ] ;
delete options [ 'update' ] ;
var sourcesetId = store . last ( ) . get ( 'sourceset_id' ) ;
var recordsToSend = [ ] ;
Ext . each ( store . getRange ( ) , function ( record ) {
var data = record . getData ( ) ;
recordsToSend . push ( { "source" : data . source } ) ;
} ) ;
Ext . Ajax . request ( {
url : '/api/cfsourcesets/' + sourcesetId ,
method : 'PATCH' ,
headers : { 'Content-Type' : 'application/json-patch+json' } ,
jsonData : [ {
"op" : "add" ,
"path" : "/sources" ,
"value" : recordsToSend
} ] ,
success : function ( response , opts ) {
store . commitChanges ( ) ;
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
}
} ) ;
return false ;
} ,
timesBasedOnRecords : function ( store ) {
// TODO: Started this, but then discovered the issue leading to creation
// of #18401. Leaving the code in place for upcoming task #18401
var recordsToSend = [ ] ;
Ext . each ( store . getRange ( ) , function ( record ) {
var data = record . getData ( ) ;
// console.log(data.time_from);
// console.log(data.time_to);
// For fields of data that have been changed in the grid, data is in
// this format:
// Tue Jan 01 2008 13:00:00 GMT+0100 (CET)
} ) ;
return recordsToSend ;
} ,
cfTimesetBeforeSync : function ( store , options ) {
delete options [ 'destroy' ] ;
delete options [ 'create' ] ;
delete options [ 'update' ] ;
var timesetId = store . last ( ) . get ( 'timeset_id' ) ;
// var recordsToSend = this.timesBasedOnRecords(store);
// TODO: Example ajax request for #18401
// Ext.Ajax.request({
// url: '/api/cftimesets/' + timesetId,
// method: 'PATCH',
// headers: { 'Content-Type': 'application/json-patch+json' },
// jsonData: [{
// "op": "add",
// "path": "/times",
// "value": recordsToSend
// }],
// success: function(response, opts) {
// console.log('server-side success with status code ' + response.status);
// },
// failure: function(response, opts) {
// console.log('server-side failure with status code ' + response.status);
// }
// });
return false ;
} ,
getDestinationFromSipId : function ( destination ) {
@ -181,6 +339,20 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
}
} ,
getTypeFromTypeName : function ( type ) {
switch ( type ) {
case 'Online' :
return 'cfu' ;
break ;
case 'Busy' :
return 'cfb' ;
break ;
case 'Offline' :
return 'cfna' ;
break ;
}
} ,
getSourceNameFromSourceSet : function ( sourceset ) {
switch ( sourceset ) {
case 'List A' :
@ -195,6 +367,20 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
}
} ,
getSourceSetFromSourceName : function ( sourceset ) {
switch ( sourceset ) {
case 'listA' :
return 'List A' ;
break ;
case 'listB' :
return 'List B' ;
break ;
case null :
return null ;
break ;
}
} ,
getTimeNameFromTimeSet : function ( timeset ) {
switch ( timeset ) {
case 'After Hours' :
@ -209,6 +395,19 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
}
} ,
getTimeSetFromTimeSource : function ( timeset ) {
switch ( timeset ) {
case 'afterHours' :
return 'After Hours' ;
break ;
case 'companyHours' :
return 'Company Hours' ;
break ;
case null :
return null ;
break ;
}
} ,
getModuleFromRoute : function ( currentRoute ) {
switch ( currentRoute ) {
@ -266,26 +465,12 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ;
} ,
populateSourcesetStores : function ( models ) {
var storeListAAlways = Ext . getStore ( 'CallForwardListA' ) ;
var storeListBAlways = Ext . getStore ( 'CallForwardListB' ) ;
storeListAAlways . removeAll ( ) ;
storeListBAlways . removeAll ( ) ;
Ext . each ( models , function ( model ) {
if ( model . get ( 'sourceset_name' ) == 'List A' ) {
storeListAAlways . add ( model ) ;
} else if ( model . get ( 'sourceset_name' ) == 'List B' ) {
storeListBAlways . add ( model ) ;
} ;
} ) ;
storeListAAlways . commitChanges ( ) ;
storeListBAlways . commitChanges ( ) ;
} ,
populateDestinationStores : function ( models ) {
var me = this ;
var gridName = this . getGridCategoryFromType ( models [ 0 ] . get ( 'type' ) ) ;
var store ;
// TODO: #17654 New grid logic and styling with conditions for cft/cfu,
// and remove first ring section
Ext . each ( models , function ( model ) {
var sourcename = me . getSourceNameFromSourceSet ( model . get ( 'sourceset' ) ) ;
var timename = me . getTimeNameFromTimeSet ( model . get ( 'timeset' ) ) ;
@ -301,23 +486,29 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
}
} ,
cfdestinationsetsClick : function ( ) {
console . log ( 'cfdestinationsetsClick' ) ;
} ,
cfsourcesetsClick : function ( ) {
console . log ( 'cfsourcesetsClick' ) ;
} ,
cftimesetsClick : function ( ) {
console . log ( 'cftimesetsClick' ) ;
populateSourcesetStores : function ( models ) {
var storeListAAlways = Ext . getStore ( 'CallForwardListA' ) ;
var storeListBAlways = Ext . getStore ( 'CallForwardListB' ) ;
storeListAAlways . removeAll ( ) ;
storeListBAlways . removeAll ( ) ;
Ext . each ( models , function ( model ) {
if ( model . get ( 'sourceset_name' ) == 'List A' ) {
storeListAAlways . add ( model ) ;
} else if ( model . get ( 'sourceset_name' ) == 'List B' ) {
storeListBAlways . add ( model ) ;
} ;
} ) ;
storeListAAlways . commitChanges ( ) ;
storeListBAlways . commitChanges ( ) ;
} ,
editingPhoneDone : function ( editor , context ) {
var record = context . record ;
var grid = context . grid ;
var store = grid . getStore ( ) ;
record . set ( "edit" , false ) ;
grid . getView ( ) . refresh ( ) ;
store . sync ( ) ;
} ,
beforePhoneEdit : function ( editor , context ) {
@ -405,25 +596,104 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
return target . indexOf ( string ) > - 1 ;
} ,
saveEmptyRowToStore : function ( grid ) {
writeNewSourceToStore : function ( grid ) {
var vm = this . getViewModel ( ) ;
var store = grid . getStore ( ) ;
var plugin = grid . getPlugin ( 'celleditingSource' ) ;
var newRowIndex = store . getCount ( ) + 1 ;
var record = store . getAt ( store . getCount ( ) - 1 ) ;
if ( record == null || ( record . data . phone !== ' ' && record . data . phone !== '' ) ) {
// Need to add whitespace in record when using widgetcolumn
store . add ( {
"phone" : " " ,
"edit" : true
} ) ;
} ;
plugin . startEditByPosition ( {
row : newRowIndex ,
column : 0
var record = store . last ( ) ;
var sourcesetName = grid . id . split ( '-' ) [ 0 ] == 'listA' ? 'List A' : 'List B' ;
var listAId = null ;
var listBId = null ;
var listExistsInApi = false ;
Ext . Ajax . request ( {
url : '/api/cfsourcesets/?subscriber_id=' + localStorage . getItem ( 'subscriber_id' ) ,
success : function ( response , opts ) {
var decodedResponse = Ext . decode ( response . responseText ) ;
if ( decodedResponse . _embedded ) {
var sourcesets = decodedResponse . _embedded [ 'ngcp:cfsourcesets' ] ;
Ext . each ( sourcesets , function ( destinationset , index ) {
if ( destinationset . name == 'List A' ) {
listAId = destinationset . id ;
} else if ( destinationset . name == 'List B' ) {
listBId = destinationset . id ;
}
if ( sourcesetName == 'List A' && listAId !== null ) {
listExistsInApi = true ;
} else if ( sourcesetName == 'List B' && listBId !== null ) {
listExistsInApi = true ;
}
} ) ;
} ;
switch ( ! store . last ( ) ) {
case false :
if ( record == null || ( record . data . source !== ' ' && record . data . source !== '' ) ) {
var cfSourcesetModel = Ext . create ( 'NgcpCsc.model.CallForwardSourceset' , {
id : Ext . id ( ) ,
source : " " ,
sourceset _name : record . get ( 'sourceset_name' ) ,
sourceset _id : record . get ( 'sourceset_id' ) ,
edit : true
} ) ;
store . add ( cfSourcesetModel ) ;
} ;
break ;
case true : // if store empty we need to create new sourceset
switch ( listExistsInApi ) {
case true :
var cfSourcesetModel = Ext . create ( 'NgcpCsc.model.CallForwardSourceset' , {
id : Ext . id ( ) ,
source : " " ,
sourceset _name : sourcesetName ,
sourceset _id : listAId || listBId ,
edit : true
} ) ;
store . add ( cfSourcesetModel ) ;
break ;
case false :
var subscriberId = localStorage . getItem ( 'subscriber_id' ) ;
Ext . Ajax . request ( {
url : '/api/cfsourcesets/' ,
method : 'POST' ,
jsonData : {
name : sourcesetName ,
subscriber _id : subscriberId
} ,
success : function ( response , opts ) {
var sourcesetId = response . getResponseHeader ( 'Location' ) . split ( '/' ) [ 3 ] ;
var cfSourcesetModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
id : Ext . id ( ) ,
source : " " ,
sourceset _name : sourcesetName ,
sourceset _id : sourcesetId ,
edit : true
} ) ;
store . add ( cfSourcesetModel ) ;
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
}
} ) ;
break ;
}
break ;
}
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
} ,
callback : function ( ) {
plugin . startEditByPosition ( {
row : newRowIndex ,
column : 0
} ) ;
}
} ) ;
} ,
addEmptyRow : function ( button ) {
addEmpty Sourceset Row: function ( button ) {
var buttonIdSplit = button . id . split ( '-' ) ;
var buttonPrefixOne = buttonIdSplit [ 0 ] ;
var buttonPrefixTwo = buttonIdSplit [ 1 ] ;
@ -431,11 +701,11 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
switch ( buttonSuffix ) {
case 'addListAButton' :
var grid = Ext . getCmp ( buttonPrefixOne + '-' + buttonPrefixTwo + '-cf-sourceset-list-a-grid' ) ;
this . saveEmptyRow ToStore( grid ) ;
this . writeNewSource ToStore( grid ) ;
break ;
case 'addListBButton' :
var grid = Ext . getCmp ( buttonPrefixOne + '-' + buttonPrefixTwo + '-cf-sourceset-list-b-grid' ) ;
this . saveEmptyRow ToStore( grid ) ;
this . writeNewSource ToStore( grid ) ;
break ;
} ;
} ,
@ -453,6 +723,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var store = record . store ;
if ( store ) {
store . remove ( record ) ;
store . sync ( ) ;
}
} ,
@ -596,13 +867,10 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
case true :
switch ( Ext . isEmpty ( newNumber ) && newDest === 'Number' ) {
case true :
me . fireEvent ( 'showmessage' , false , 'Number is required. Please retry.' ) ;
me . fireEvent ( 'showmessage' , false , Ngcp . csc . locales . callforward . number _is _required [ localStorage . getItem ( 'languageSelected' ) ] ) ;
break ;
case false :
targetStore . add ( {
"phone" : newDest ,
"ring_for" : ""
} ) ;
me . writeNewDestinationToStore ( targetStore , newDest , "" ) ;
me . hideThenFieldsByStoreName ( vm , storeNameStripped ) ;
break ;
} ;
@ -611,16 +879,13 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
case false :
switch ( Ext . isNumber ( parseInt ( newNumber ) ) ) {
case false :
me . fireEvent ( 'showmessage' , false , 'Only numbers allowed. Please retry.' ) ;
me . fireEvent ( 'showmessage' , false , Ngcp . csc . locales . callforward . only _numbers _allowed [ localStorage . getItem ( 'languageSelected' ) ] ) ;
vm . set ( storeNameCategory + '_then_number' , '' ) ;
break ;
case true :
var newTimeout = newDest === 'Number' ? vm . get ( storeNameCategory + '_then_timeout' ) : '' ;
var newPhone = newDest === 'Number' ? newNumber : newDest ;
targetStore . add ( {
"phone" : newPhone ,
"ring_for" : newTimeout
} ) ;
me . writeNewDestinationToStore ( targetStore , newPhone , parseInt ( newTimeout ) ) ;
vm . set ( storeNameCategory + '_then_number' , '' ) ;
me . hideThenFieldsByStoreName ( vm , storeNameStripped ) ;
break ;
@ -629,6 +894,126 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ;
} ,
createNewStandardSet : function ( url , name , subscriberId ) {
var vm = this . getViewModel ( ) ;
Ext . Ajax . request ( {
url : url ,
method : 'POST' ,
jsonData : {
name : name ,
subscriber _id : subscriberId
} ,
success : function ( response , opts ) {
switch ( name ) {
case 'List A' :
vm . set ( 'list_a_exists_in_api' , true ) ;
break ;
case 'List B' :
vm . set ( 'list_b_exists_in_api' , true ) ;
break ;
case 'After Hours' :
vm . set ( 'after_hours_exists_in_api' , true ) ;
break ;
case 'Company Hours' :
vm . set ( 'company_hours_exists_in_api' , true ) ;
break ;
}
}
} ) ;
} ,
createNewMapping : function ( subscriberId , newType , newDestinationsetName , newSourceset , newTimeset ) {
Ext . Ajax . request ( {
url : '/api/cfmappings/' + subscriberId ,
method : 'PATCH' ,
headers : { 'Content-Type' : 'application/json-patch+json' } ,
jsonData : [ {
"op" : "add" ,
"path" : "/" + newType ,
"value" : [ { "destinationset" : newDestinationsetName , "sourceset" : newSourceset , "timeset" : newTimeset } ]
} ]
} ) ;
} ,
writeNewDestinationToStore : function ( store , destination , timeout ) {
var me = this ;
var vm = this . getViewModel ( ) ;
var simpleDestination = destination ;
var priority = 1 ;
var storeCount = store . getCount ( ) ;
var ringFor = destination == 'Voicemail' ? '' : timeout ;
var destinationCleaned = destination ;
var storeIdSplit = store . storeId . split ( '-' ) ;
var newSourcesetName = storeIdSplit [ 0 ] == 'everybody' ? null : storeIdSplit [ 0 ] ;
var newTimesetName = storeIdSplit [ 1 ] == 'always' ? null : storeIdSplit [ 1 ] ;
var newTypeName = storeIdSplit [ 2 ] . slice ( 11 ) ;
var newSourceset = this . getSourceSetFromSourceName ( newSourcesetName ) ;
var newTimeset = this . getTimeSetFromTimeSource ( newTimesetName ) ;
var newType = this . getTypeFromTypeName ( newTypeName ) ;
var newDomain = localStorage . getItem ( 'domain' ) ;
// TODO: #17654 Consider the fact that one destinationset can be in
// several grids, so if you write one, update all other grids with
// that same destinationset id
if ( ! store . last ( ) ) { // if store empty we need to create new destset
var newDestinationsetName = 'csc_defined_' + newType ;
var subscriberId = localStorage . getItem ( 'subscriber_id' ) ;
Ext . Ajax . request ( {
url : '/api/cfdestinationsets/' ,
method : 'POST' ,
defaultHeaders : 'Prefer: return=representation' ,
jsonData : {
name : newDestinationsetName ,
subscriber _id : subscriberId
} ,
success : function ( response , opts ) {
var destinationsetId = response . getResponseHeader ( 'Location' ) . split ( '/' ) [ 3 ] ;
var cfModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
type : newType ,
destination _cleaned : destinationCleaned ,
destination _announcement _id : null ,
destination : 'sip:' + destination + '@' + newDomain ,
// Keeping priority 1 as default for now, as we'll handle priotity
// with grid "drag-and-drop" widget plugin in upcoming task
priority : 1 ,
simple _destination : destination ,
ring _for : ringFor ,
sourceset : newSourceset ,
timeset : newTimeset ,
destinationset _id : destinationsetId ,
destinationset _name : newDestinationsetName
} ) ;
store . add ( cfModel ) ;
store . sync ( ) ;
// Creates new sourceset/timeset if variable is not set to null
newSourceset && me . createNewStandardSet ( '/api/cfsourcesets/' , newSourceset , subscriberId ) ;
newTimeset && me . createNewStandardSet ( '/api/cftimesets/' , newTimeset , subscriberId ) ;
me . createNewMapping ( subscriberId , newType , newDestinationsetName , newSourceset , newTimeset ) ;
} ,
failure : function ( response , opts ) {
console . log ( 'server-side failure with status code ' + response . status ) ;
}
} ) ;
} else {
var lastRecordInStore = store . last ( ) ;
var cfModel = Ext . create ( 'NgcpCsc.model.CallForward' , {
type : lastRecordInStore . get ( 'type' ) ,
destination _cleaned : destinationCleaned ,
destination _announcement _id : null ,
destination : 'sip:' + destination + '@' + newDomain ,
priority : 1 ,
simple _destination : destination ,
ring _for : ringFor ,
sourceset : lastRecordInStore . get ( 'sourceset' ) ,
timeset : lastRecordInStore . get ( 'timeset' ) ,
destinationset _id : lastRecordInStore . get ( 'destinationset_id' ) ,
destinationset _name : lastRecordInStore . get ( 'destinationset_name' )
} ) ;
store . add ( cfModel ) ;
store . sync ( ) ;
}
} ,
addNewDestination : function ( element ) {
var me = this ;
var vm = this . getViewModel ( ) ;
@ -649,8 +1034,15 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
} ;
} ,
saveGrid : function ( el ) {
this . fireEvent ( 'showmessage' , true , Ngcp . csc . locales . common . save _success [ localStorage . getItem ( 'languageSelected' ) ] ) ;
saveTimesetGrid : function ( el ) {
var storeName = el . id . split ( '-' ) [ 0 ] + '-Timeset' ;
var store = Ext . getStore ( storeName ) ;
store . sync ( ) ;
}
// TODO #18401, maybe use a blur or change listener on editors in grid
// editingTimeDone: function () {
//
// }
} ) ;