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() ) ){
$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 ) ) {
chmod( $file, 0777 );
$this->_error( 'ops, an error!' );
}
echo json_encode( ['success' => $name ] );
exit;

View File

@ -5,7 +5,7 @@ class Controller_api_driver_notify extends Crunchbutton_Controller_RestAccount {
public function init() {
if( $this->method() != 'post' ){
// $this->_error();
$this->_error();
}
$id_admin = c::getPagePiece( 3 );
@ -61,6 +61,13 @@ class Controller_api_driver_notify extends Crunchbutton_Controller_RestAccount {
}
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() ] );
} else {
$this->_error( 'notification not sent' );

View File

@ -39,18 +39,31 @@
</li>
<li>
<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>
</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">
<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">
<hr/>
<h2>Documents</h2>
<ul>
<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>
</li>
</ul>
@ -61,8 +74,8 @@
</li>
</ul>
</form>
<hr/>
<form name="docs" ng-if="driver.id_admin">
<hr/>
<h2>Upload zone</h2>
<ul>
<li>
@ -82,9 +95,10 @@
</li>
</ul>
</form>
<hr/>
<div class="notifications" ng-if="driver.id_admin">
<div class="notify" ng-if="driver.id_admin">
<hr/>
<h2>Notify</h2>
<button ng-click="notify()"> Notify about setup </button>
</div>
</div>
</div>

View File

@ -201,13 +201,15 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader,
var docs = function(){
// Load the docs
DriverOnboardingService.docs.list( function( data ){
console.log('data',data);
$scope.documents = data;
} );
}
DriverOnboardingService.get( function( driver ){
$scope.driver = driver;
if( !$scope.driver.id_admin ){
$scope.driver.notify = true;
}
docs();
CommunityService.listSimple( function( 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
$scope.save = function(){
if( $scope.form.$invalid ){
$scope.submitted = true;
return;
}
DriverOnboardingService.save( $scope.driver, function( json ){
if( json.success ){
$scope.navigation.link( '/drivers/onboarding/' + json.success.id_admin );
@ -256,7 +273,6 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader,
$scope.doc_uploaded = 0;
uploader.clearQueue();
} else {
console.log('response',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 ){
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 ){
@ -31,8 +33,18 @@ NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $rout
}
service.save = function( driver, callback ){
drivers.save( driver, function( driver ){
callback( driver );
var notify = driver.notify;
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' );
}
} );
}
} );
}