2016-11-01 14:21:35 -03:00
'use strict' ;
2016-11-16 14:11:18 -03:00
angular . module ( 'copayApp.controllers' ) . controller ( 'sendController' , function ( $scope , $state , $log , $timeout , $stateParams , $ionicNavBarDelegate , $ionicHistory , $ionicConfig , $window , gettextCatalog , popupService , configService , lodash , feedbackService , ongoingProcess , platformInfo ) {
2016-11-01 14:21:35 -03:00
2016-11-08 11:49:03 -03:00
$scope . sendFeedback = function ( feedback , skip ) {
2016-11-07 17:31:13 -03:00
var config = configService . getSync ( ) ;
2016-11-16 14:11:18 -03:00
var isWP = platformInfo . isWP ;
var isIOS = platformInfo . isIOS ;
var isAndroid = platformInfo . isAndroid ;
2016-11-09 12:09:22 -03:00
2016-11-07 17:31:13 -03:00
var dataSrc = {
2016-11-09 12:09:22 -03:00
"Email" : lodash . values ( config . emailFor ) [ 0 ] || ' ' ,
"Feedback" : skip ? ' ' : feedback ,
2016-11-16 14:11:18 -03:00
"Score" : $stateParams . score || ' ' ,
"AppVersion" : $window . version ,
"Platform" : ionic . Platform . platform ( ) ,
"DeviceVersion" : ionic . Platform . version ( )
2016-11-07 17:31:13 -03:00
} ;
2016-11-09 12:09:22 -03:00
ongoingProcess . set ( 'sendingFeedback' , true ) ;
feedbackService . send ( dataSrc , function ( err ) {
ongoingProcess . set ( 'sendingFeedback' , false ) ;
if ( err ) {
popupService . showAlert ( gettextCatalog . getString ( 'Error' ) , gettextCatalog . getString ( 'Could not send feedback' ) ) ;
return ;
}
2016-11-15 17:38:48 -03:00
if ( ! $stateParams . score ) {
2016-11-15 18:55:07 -03:00
popupService . showAlert ( gettextCatalog . getString ( 'Thank you!' ) , gettextCatalog . getString ( 'A member of the team will review your feedback as soon as possible.' ) , function ( ) {
$scope . feedback . value = '' ;
$ionicHistory . nextViewOptions ( {
disableAnimate : true ,
historyRoot : true
} ) ;
$ionicHistory . clearHistory ( ) ;
$timeout ( function ( ) {
$state . go ( 'tabs.settings' ) ;
} ) ;
2016-11-15 17:38:48 -03:00
} ) ;
return ;
}
2016-11-16 11:16:20 -03:00
$state . go ( 'tabs.rate.complete' , {
2016-11-08 11:49:03 -03:00
score : $stateParams . score ,
skipped : skip
} ) ;
2016-11-01 14:21:35 -03:00
} ) ;
} ;
2016-11-15 17:38:48 -03:00
$scope . $on ( "$ionicView.beforeEnter" , function ( event , data ) {
2016-11-16 11:16:20 -03:00
$scope . score = ( data . stateParams && data . stateParams . score ) ? parseInt ( data . stateParams . score ) : null ;
2016-11-15 17:38:48 -03:00
$scope . feedback = { } ;
2016-11-16 11:16:20 -03:00
if ( $scope . score ) {
$ionicNavBarDelegate . showBackButton ( false ) ;
$ionicConfig . views . swipeBackEnabled ( false ) ;
2016-11-16 14:11:18 -03:00
} else $ionicNavBarDelegate . showBackButton ( true ) ;
2016-11-16 11:16:20 -03:00
2016-11-15 17:38:48 -03:00
switch ( $scope . score ) {
case 1 :
$scope . reaction = gettextCatalog . getString ( "Ouch!" ) ;
$scope . comment = gettextCatalog . getString ( "There's obviously something we're doing wrong." ) + ' ' + gettextCatalog . getString ( "How could we improve your experience?" ) ;
break ;
case 2 :
$scope . reaction = gettextCatalog . getString ( "Oh no!" ) ;
$scope . comment = gettextCatalog . getString ( "There's obviously something we're doing wrong." ) + ' ' + gettextCatalog . getString ( "How could we improve your experience?" ) ;
break ;
case 3 :
$scope . reaction = gettextCatalog . getString ( "Hmm..." ) ;
$scope . comment = gettextCatalog . getString ( "We'd love to do better." ) + ' ' + gettextCatalog . getString ( "How could we improve your experience?" ) ;
break ;
case 4 :
$scope . reaction = gettextCatalog . getString ( "Thanks!" ) ;
$scope . comment = gettextCatalog . getString ( "That's exciting to hear. We'd love to earn that fifth star from you – how could we improve your experience?" ) ;
break ;
case 5 :
$scope . reaction = gettextCatalog . getString ( "Thank you!" ) ;
2016-11-15 16:35:30 -05:00
$scope . comment = gettextCatalog . getString ( "We're always looking for ways to improve BitPay." ) + ' ' + gettextCatalog . getString ( "Is there anything we could do better?" ) ;
2016-11-15 17:38:48 -03:00
break ;
default :
$scope . reaction = gettextCatalog . getString ( "Feedback!" ) ;
2016-11-15 16:35:30 -05:00
$scope . comment = gettextCatalog . getString ( "We're always looking for ways to improve BitPay. How could we improve your experience?" ) ;
2016-11-15 17:38:48 -03:00
break ;
}
} ) ;
2016-11-01 14:21:35 -03:00
} ) ;