From c5ec5b216ffaf65b31805f6afe0a3853ce12547e Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Thu, 15 May 2014 14:51:23 -0300 Subject: [PATCH] partial #2969 delete old files started setup screen --- .../cockpit2/api/driver/documents/index.php | 5 +++++ include/library/Crunchbutton/Admin.php | 11 +++++++---- .../frontend/drivers-onboarding-form.phtml | 2 +- .../frontend/drivers-onboarding-setup.phtml | 7 +++++++ www/assets/cockpit/js/cockpit.js | 19 ++++++++++++++++--- www/assets/cockpit/js/controllers.drivers.js | 19 +++++++++++++------ 6 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 include/views/default/cockpit2/frontend/drivers-onboarding-setup.phtml diff --git a/include/controllers/default/cockpit2/api/driver/documents/index.php b/include/controllers/default/cockpit2/api/driver/documents/index.php index e0f1ecb5a..0cae72cd5 100644 --- a/include/controllers/default/cockpit2/api/driver/documents/index.php +++ b/include/controllers/default/cockpit2/api/driver/documents/index.php @@ -48,6 +48,11 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun if( !$docStatus->id_driver_document_status ){ $docStatus->id_admin = $id_admin; $docStatus->id_driver_document = $id_driver_document; + } else { + $oldFile = Crunchbutton_Driver_Document_Status::path() . $docStatus->file; + if( file_exists( $oldFile ) ){ + @unlink( $oldFile ); + } } // todo: delete old doc $docStatus->datetime = date('Y-m-d H:i:s'); diff --git a/include/library/Crunchbutton/Admin.php b/include/library/Crunchbutton/Admin.php index ea5b245df..4bee5c13c 100644 --- a/include/library/Crunchbutton/Admin.php +++ b/include/library/Crunchbutton/Admin.php @@ -163,11 +163,14 @@ class Crunchbutton_Admin extends Cana_Table { } public function communitiesHeDeliveriesFor(){ + $deliveryFor = []; - $communities = Crunchbutton_Community::q( 'SELECT * FROM community ORDER BY name ASC' ); - foreach( $communities as $community ){ - if( $community->driverDeliveryHere( $this->id_admin ) ){ - $deliveryFor[] = $community; + if( $this->id_admin ){ + $communities = Crunchbutton_Community::q( 'SELECT * FROM community ORDER BY name ASC' ); + foreach( $communities as $community ){ + if( $community->driverDeliveryHere( $this->id_admin ) ){ + $deliveryFor[] = $community; + } } } return $deliveryFor; diff --git a/include/views/default/cockpit2/frontend/drivers-onboarding-form.phtml b/include/views/default/cockpit2/frontend/drivers-onboarding-form.phtml index d5c45418d..5d903e24b 100644 --- a/include/views/default/cockpit2/frontend/drivers-onboarding-form.phtml +++ b/include/views/default/cockpit2/frontend/drivers-onboarding-form.phtml @@ -81,7 +81,7 @@
  • diff --git a/include/views/default/cockpit2/frontend/drivers-onboarding-setup.phtml b/include/views/default/cockpit2/frontend/drivers-onboarding-setup.phtml new file mode 100644 index 000000000..6e763eb49 --- /dev/null +++ b/include/views/default/cockpit2/frontend/drivers-onboarding-setup.phtml @@ -0,0 +1,7 @@ +
    + +
    +
    + +
    +
    diff --git a/www/assets/cockpit/js/cockpit.js b/www/assets/cockpit/js/cockpit.js index b21ce0233..09fd86e49 100644 --- a/www/assets/cockpit/js/cockpit.js +++ b/www/assets/cockpit/js/cockpit.js @@ -114,6 +114,11 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l controller: 'DriversOnboardingFormCtrl', templateUrl: 'assets/view/drivers-onboarding-form.html' }) + .when('/setup/:phone', { + action: 'drivers-setup', + controller: 'DriversOnboardingSetupCtrl', + templateUrl: 'assets/view/drivers-onboarding-setup.html' + }) .otherwise({ action: 'home', controller: 'DefaultCtrl', @@ -265,10 +270,18 @@ NGApp.controller('AppController', function ($scope, $route, $http, $routeParams, /* todo: check user's permission too */ NGApp.run( function ( $rootScope, $location, MainNavigationService ) { $rootScope.$on( '$routeChangeStart', function ( event, next, current ) { - if ( $location.url() != '/login' && !$rootScope.account.isLoggedIn() ) { - MainNavigationService.link( '/login' ); + if( !$rootScope.account.isLoggedIn() ){ + var isAllowed = false; + angular.forEach( [ '/login', '/setup' ], function( allowed ){ + if( $location.url().indexOf( allowed ) >= 0 ){ + isAllowed = true; + } + } ); + if( !isAllowed ) { + MainNavigationService.link( '/login' ); + } } - if ( $location.url() == '/login' && $rootScope.account.isLoggedIn() ) { + if( $location.url() == '/login' && $rootScope.account.isLoggedIn() ) { MainNavigationService.link( '/' ); } }); diff --git a/www/assets/cockpit/js/controllers.drivers.js b/www/assets/cockpit/js/controllers.drivers.js index ebc0e59b8..91dd9ff6f 100644 --- a/www/assets/cockpit/js/controllers.drivers.js +++ b/www/assets/cockpit/js/controllers.drivers.js @@ -256,7 +256,6 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader, // Upload control stuff $scope.doc_uploaded = 0; - var uploader = $scope.uploader = $fileUploader.create({ scope: $scope, url: '/api/driver/documents/upload/', @@ -264,16 +263,20 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader, } ); uploader.bind( 'success', function( event, xhr, item, response ) { + $scope.$apply(); if( response.success ){ var doc = { id_admin : $scope.driver.id_admin, id_driver_document : $scope.doc_uploaded, file : response.success }; - DriverOnboardingService.docs.save( doc, function(){ - docs(); - $scope.flash.setMessage( 'File saved!' ); + DriverOnboardingService.docs.save( doc, function( json ){ + if( json.success ){ + docs(); + $scope.flash.setMessage( 'File saved!' ); + } else { + $scope.flash.setMessage( 'File not saved: ' + json.error ); + } } ); - $scope.doc_uploaded = 0; uploader.clearQueue(); } else { - App.alert( 'Upload error: ' + response.error ); + $scope.flash.setMessage( 'File not saved: ' + json.error ); } }); @@ -282,3 +285,7 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $fileUploader, }); } ); + +NGApp.controller('DriversOnboardingSetupCtrl', function($scope) { + console.log('setup'); +});