partial #2969 - driver's notifications / status

This commit is contained in:
Daniel Camargo 2014-05-15 12:59:42 -03:00
parent 8b86147ee5
commit 0483561c0f
5 changed files with 62 additions and 14 deletions

View File

@ -23,12 +23,11 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun
} }
if( !file_exists( Crunchbutton_Driver_Document_Status::path() ) ){ if( !file_exists( Crunchbutton_Driver_Document_Status::path() ) ){
$this->_error( '"www/upload//drivers-doc/" folder doens`t exist!' ); $this->_error( '"www/upload/drivers-doc/" folder doens`t exist!' );
} }
if ( copy( $_FILES[ 'file' ][ 'tmp_name' ], $file ) ) { if ( copy( $_FILES[ 'file' ][ 'tmp_name' ], $file ) ) {
chmod( $file, 0777 ); chmod( $file, 0777 );
$this->_error( 'ops, an error!' );
} }
echo json_encode( ['success' => $name ] ); echo json_encode( ['success' => $name ] );
exit; exit;

View File

@ -5,7 +5,7 @@ class Controller_api_driver_notify extends Crunchbutton_Controller_RestAccount {
public function init() { public function init() {
if( $this->method() != 'post' ){ if( $this->method() != 'post' ){
// $this->_error(); $this->_error();
} }
$id_admin = c::getPagePiece( 3 ); $id_admin = c::getPagePiece( 3 );
@ -61,6 +61,13 @@ class Controller_api_driver_notify extends Crunchbutton_Controller_RestAccount {
} }
if( $isOk ){ if( $isOk ){
// log
$log = new Crunchbutton_Driver_Log();
$log->id_admin = $driver->id_admin;
$log->action = 'notified';
$log->info = $phone . ': ' . join( $message );
$log->datetime = date('Y-m-d H:i:s');
$log->save();
echo json_encode( [ 'success' => $driver->exports() ] ); echo json_encode( [ 'success' => $driver->exports() ] );
} else { } else {
$this->_error( 'notification not sent' ); $this->_error( 'notification not sent' );

View File

@ -39,18 +39,31 @@
</li> </li>
<li> <li>
<label for="driverEmail"> <label for="driverEmail">
<div class="label">email:</div> <div class="label">Email:</div>
<div class="input"><input type="email" name="driverEmail" ng-model="driver.email" placeholder="Email"></div> <div class="input"><input type="email" name="driverEmail" ng-model="driver.email" placeholder="Email"></div>
</label> </label>
<div class="error" ng-show="submitted && form.driverEmail.$invalid"> <div class="error" ng-show="submitted && form.driverEmail.$invalid">
<small class="error" ng-show="form.driverEmail.$invalid">Enter a valid email.</small> <small class="error" ng-show="form.driverEmail.$invalid">Enter a valid email.</small>
</div> </div>
</li> </li>
<li ng-if="!driver.id_admin">
<label for="driverNotification">
<div class="label">Send setup notification?:</div>
<div class="input"><input type="checkbox" name="driverNotification" ng-model="driver.notify"></div>
</label>
<div class="error" ng-show="submitted && form.driverEmail.$invalid">
<small class="error" ng-show="form.driverEmail.$invalid">Enter a valid email.</small>
</div>
</li>
<li ng-if="driver.id_admin"> <li ng-if="driver.id_admin">
<hr/>
<h2>Documents</h2> <h2>Documents</h2>
<ul> <ul>
<li ng-repeat="doc in documents"> <li ng-repeat="doc in documents">
<div>{{doc.name}} <span ng-show="doc.status"><a href="{{doc.status.url}}" target="_blank">Download</a></span> <div>
{{doc.name}}
<span ng-show="doc.status"> <a href="{{doc.status.url}}" target="_blank">Download</a></span>
<span ng-show="!doc.status"> <span ng-click="setDocument(doc.id_driver_document)" target="_blank">Send</span></span>
</div> </div>
</li> </li>
</ul> </ul>
@ -61,8 +74,8 @@
</li> </li>
</ul> </ul>
</form> </form>
<hr/>
<form name="docs" ng-if="driver.id_admin"> <form name="docs" ng-if="driver.id_admin">
<hr/>
<h2>Upload zone</h2> <h2>Upload zone</h2>
<ul> <ul>
<li> <li>
@ -82,9 +95,10 @@
</li> </li>
</ul> </ul>
</form> </form>
<hr/> <div class="notify" ng-if="driver.id_admin">
<div class="notifications" ng-if="driver.id_admin"> <hr/>
<h2>Notify</h2>
<button ng-click="notify()"> Notify about setup </button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -201,13 +201,15 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader,
var docs = function(){ var docs = function(){
// Load the docs // Load the docs
DriverOnboardingService.docs.list( function( data ){ DriverOnboardingService.docs.list( function( data ){
console.log('data',data);
$scope.documents = data; $scope.documents = data;
} ); } );
} }
DriverOnboardingService.get( function( driver ){ DriverOnboardingService.get( function( driver ){
$scope.driver = driver; $scope.driver = driver;
if( !$scope.driver.id_admin ){
$scope.driver.notify = true;
}
docs(); docs();
CommunityService.listSimple( function( data ){ CommunityService.listSimple( function( data ){
$scope.communities = data; $scope.communities = data;
@ -215,13 +217,28 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader,
} ); } );
} ); } );
$scope.notify = function(){
DriverOnboardingService.notifySetup( $scope.driver.id_admin, function( json ){
if( json.success ){
$scope.flash.setMessage( 'Notification sent!' );
} else {
$scope.flash.setMessage( 'Notification not sent: ' + json.error , 'error' );
}
} );
}
$scope.setDocument = function( id_driver_document ){
$scope.doc_uploaded = id_driver_document
}
// method save that saves the driver // method save that saves the driver
$scope.save = function(){ $scope.save = function(){
if( $scope.form.$invalid ){ if( $scope.form.$invalid ){
$scope.submitted = true; $scope.submitted = true;
return; return;
} }
DriverOnboardingService.save( $scope.driver, function( json ){ DriverOnboardingService.save( $scope.driver, function( json ){
if( json.success ){ if( json.success ){
$scope.navigation.link( '/drivers/onboarding/' + json.success.id_admin ); $scope.navigation.link( '/drivers/onboarding/' + json.success.id_admin );
@ -256,7 +273,6 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader,
$scope.doc_uploaded = 0; $scope.doc_uploaded = 0;
uploader.clearQueue(); uploader.clearQueue();
} else { } else {
console.log('response',response.error);
App.alert( 'Upload error: ' + response.error ); App.alert( 'Upload error: ' + response.error );
} }
}); });

View File

@ -20,7 +20,9 @@ NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $rout
service.notifySetup = function( id_admin, callback ){ service.notifySetup = function( id_admin, callback ){
var message = 'setup'; var message = 'setup';
service.notify( id_admin, message, callback ); if( id_admin ){
service.notify( id_admin, message, callback );
}
} }
service.notify = function( id_admin, message, callback ){ service.notify = function( id_admin, message, callback ){
@ -31,8 +33,18 @@ NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $rout
} }
service.save = function( driver, callback ){ service.save = function( driver, callback ){
drivers.save( driver, function( driver ){ var notify = driver.notify;
callback( driver ); drivers.save( driver, function( json ){
callback( json );
if( json.success && notify ){
service.notifySetup( json.success.id_admin, function( json ){
if( json.success ){
$rootScope.flash.setMessage( 'Notification sent!' );
} else {
$rootScope.flash.setMessage( 'Notification not sent: ' + json.error , 'error' );
}
} );
}
} ); } );
} }