@ -1665,22 +1665,26 @@ define(function(require) {
popup = args . popup ;
template . find ( '.create_user' ) . on ( 'click' , function ( ) {
var action = $ ( this ) . data ( 'action' ) ;
if ( monster . ui . valid ( template . find ( '#form_user_creation' ) ) ) {
var $buttons = template . find ( '.create_user' ) ,
dataForm = _ . merge ( monster . ui . getFormData ( 'form_user_creation' ) , {
user : {
device : {
family : template . find ( '#device_model' ) . find ( ':selected' ) . data ( 'family' )
}
if ( ! monster . ui . valid ( template . find ( '#form_user_creation' ) ) ) {
return ;
}
var action = $ ( this ) . data ( 'action' ) ,
$buttons = template . find ( '.create_user' ) ,
dataForm = _ . merge ( monster . ui . getFormData ( 'form_user_creation' ) , {
user : {
device : {
family : template . find ( '#device_model' ) . find ( ':selected' ) . data ( 'family' )
}
} ) ,
formattedData = self . usersFormatCreationData ( dataForm ) ;
}
} ) ,
formattedData = self . usersFormatCreationData ( dataForm ) ;
$buttons . prop ( 'disabled' , true ) ;
$buttons . prop ( 'disabled' , true ) ;
self . usersCreate ( formattedData , function ( data ) {
self . usersCreate ( {
data : formattedData ,
success : function ( data ) {
popup . dialog ( 'close' ) . remove ( ) ;
switch ( action ) {
@ -1692,10 +1696,11 @@ define(function(require) {
self . usersRender ( { userId : data . user . id } ) ;
break ;
}
} , function ( ) {
} ,
error : function ( ) {
$buttons . prop ( 'disabled' , false ) ;
} ) ;
}
}
} ) ;
} ) ;
template . find ( '#notification_email' ) . on ( 'change' , function ( ) {
@ -3898,8 +3903,16 @@ define(function(require) {
} ) ;
} ,
usersCreate : function ( data , success , error ) {
/ * *
* Creates an user , with all its related components
* @ param { Object } args
* @ param { Object } args . data User formatted data
* @ param { Function } args . success Success callback
* @ param { Function } args . error Error callback
* /
usersCreate : function ( args ) {
var self = this ,
data = args . data ,
deviceData = _ . get ( data , 'user.device' ) ;
delete data . user . device ;
@ -3914,12 +3927,7 @@ define(function(require) {
data . user . id = _dataUser . id ;
callback ( null , _dataUser ) ;
} ,
error : function ( parsedError ) {
if ( parsedError . error === '402' ) {
error ( ) ;
return ;
}
error : function ( ) {
callback ( true ) ;
} ,
onChargesCancelled : function ( ) {
@ -3941,6 +3949,16 @@ define(function(require) {
success : function ( _dataVM ) {
data . callflow . flow . children . _ . data . id = _dataVM . id ;
callback ( null , _dataUser ) ;
} ,
error : function ( ) {
callback ( true ) ;
} ,
onChargesCancelled : function ( ) {
// VMBox won't be created, so let's remove its data
data . extra . createVmbox = false ;
delete data . vmbox ;
delete data . callflow . flow . children . _ ;
callback ( null , _dataUser ) ;
}
} ) ;
} ,
@ -3971,30 +3989,30 @@ define(function(require) {
}
deviceData . owner_id = _dataUser . id ;
self . usersAddUserDevice ( {
data : deviceData ,
data : {
data : deviceData
} ,
success : function ( _device ) {
callback ( null ) ;
} ,
error : function ( parsedError ) {
if ( parsedError . error === '402' ) {
error ( ) ;
return ;
}
error : function ( ) {
callback ( true ) ;
} ,
onChargesCancelled : function ( ) {
// Allow to complete without errors, although the device won't be created
callback ( null ) ;
}
} ) ;
}
] ,
function ( err ) {
if ( err ) {
error ( ) ;
args . error ( ) ;
return ;
}
success ( data ) ;
args . success ( data ) ;
} ) ;
} ,
@ -4193,21 +4211,31 @@ define(function(require) {
} ) ;
} ,
/ * *
* Creates a device for a user
* @ param { Object } args
* @ param { Object } args . data Data to be sent by the SDK to the API
* @ param { Object } args . data . data Data provided for the device to be created
* @ param { Function } [ args . success ] Success callback
* @ param { Function } [ args . error ] Error callback
* @ param { Function } [ args . onChargesCancelled ] Callback to be executed when charges are
* not accepted
* /
usersAddUserDevice : function ( args ) {
var self = this ,
dataDevice = args . data ;
var self = this ;
self . callApi ( {
resource : 'device.create' ,
data : {
accountId : self . accountId ,
data : dataDevice
data : _ . merge ( {
accountId : self . accountId
} , args . data ) ,
success : function ( data ) {
args . hasOwnProperty ( 'success' ) && args . success ( data . data ) ;
} ,
success : function ( device ) {
args . hasOwnProperty ( 'success ' ) && args . success ( device ) ;
error : function ( parsedError ) {
args . hasOwnProperty ( 'error ' ) && args . error ( parsedError ) ;
} ,
err or: function ( error ) {
args . hasOwnProperty ( 'err or' ) && args . error ( error ) ;
onCha rgesCancelled : function ( ) {
args . hasOwnProperty ( 'onCha rgesCancelled ' ) && args . onChargesCancelled ( ) ;
}
} ) ;
} ,
@ -4422,10 +4450,13 @@ define(function(require) {
/ * *
* Creates a Voicemail Box
* @ param { Object } args
* @ param { Object } args . data Data to be sent by the SDK to the API
* @ param { Object } args . data . data Data provided for the Voicemail Box to be created
* @ param { Function } args . success Success callback
* @ param { Function } args . error Error callback
* @ param { Object } args . data Data to be sent by the SDK to the API
* @ param { Object } args . data . data Data provided for the Voicemail Box to be
* created
* @ param { Function } [ args . success ] Success callback
* @ param { Function } [ args . error ] Error callback
* @ param { Function } [ args . onChargesCancelled ] Callback to be executed when charges are
* not accepted
* /
usersCreateVMBox : function ( args ) {
var self = this ;
@ -4440,6 +4471,9 @@ define(function(require) {
} ,
error : function ( parsedError ) {
args . hasOwnProperty ( 'error' ) && args . error ( parsedError ) ;
} ,
onChargesCancelled : function ( ) {
args . hasOwnProperty ( 'onChargesCancelled' ) && args . onChargesCancelled ( ) ;
}
} ) ;
} ,