completly changed how all data is posted to server n stuff
- removed old form encoding formatting - added decoding into cana rest class - added inline partial for google maps info boxes - upgraded angular js - upgraded angular upload lib - updated driver documents page for new lib - did NOT upgrade driver onboarding page
This commit is contained in:
parent
89498080b0
commit
2e0c96b941
@ -79,7 +79,7 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun
|
||||
|
||||
Log::debug( [ 'action' => 'upload file success', 'file name' => $name, 'type' => 'drivers-onboarding'] );
|
||||
|
||||
echo json_encode( ['success' => $name ] );
|
||||
echo json_encode( ['success' => $name, 'id_driver_document' => $_POST['id_driver_document']] );
|
||||
exit;
|
||||
} else {
|
||||
$this->_error( 'invalid extension' );
|
||||
@ -101,6 +101,7 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun
|
||||
}
|
||||
|
||||
$id_driver_document = $this->request()[ 'id_driver_document' ];
|
||||
|
||||
if( $id_admin && $id_driver_document ){
|
||||
$docStatus = Cockpit_Driver_Document_Status::document( $id_admin, $id_driver_document );
|
||||
if( !$docStatus->id_driver_document_status ){
|
||||
|
||||
@ -11,13 +11,17 @@ class Cana_Controller_Rest extends Cana_Controller {
|
||||
}
|
||||
|
||||
if (isset($_SERVER['REQUEST_METHOD'])) {
|
||||
|
||||
$contentType = explode(';',trim($_SERVER['CONTENT_TYPE']));
|
||||
$contentType = trim($contentType[0]);
|
||||
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case 'PUT':
|
||||
case 'DELETE':
|
||||
if ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
|
||||
if ($contentType === 'application/x-www-form-urlencoded') {
|
||||
parse_str($this->getContent(), $this->request);
|
||||
|
||||
} elseif ($_SERVER['CONTENT_TYPE'] === 'application/json') {
|
||||
} elseif ($contentType === 'application/json') {
|
||||
$content = $this->getContent();
|
||||
|
||||
$request = json_decode($content,'array');
|
||||
@ -33,24 +37,26 @@ class Cana_Controller_Rest extends Cana_Controller {
|
||||
break;
|
||||
|
||||
case 'GET':
|
||||
if ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded' || !$_SERVER['CONTENT_TYPE']) {
|
||||
if ($contentType === 'application/x-www-form-urlencoded' || !$contentType) {
|
||||
$this->request = $_GET;
|
||||
} elseif ($_SERVER['CONTENT_TYPE'] === 'application/json') {
|
||||
} elseif ($contentType === 'application/json') {
|
||||
$this->request = $this->getRawRequest();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
if ($_SERVER['CONTENT_TYPE'] === 'application/json') {
|
||||
if ($contentType === 'application/json') {
|
||||
$this->request = json_decode($this->getContent(), 'array');
|
||||
/* Found a case where the CONTENT_TYPE was 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
*
|
||||
* @todo Is there any case where we do not set the $request to $_POST nor the json?
|
||||
* If not, there there should be OK to use the fallback scenario
|
||||
*/
|
||||
// } elseif ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
|
||||
} else {
|
||||
} elseif ($contentType === 'application/x-www-form-urlencoded') {
|
||||
$this->request = $_POST;
|
||||
} else {
|
||||
$content = $this->getContent();
|
||||
parse_str($content, $this->request);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
|
||||
<!-- <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-route.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-resource.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-animate.min.js"></script>
|
||||
-->
|
||||
|
||||
<? /*
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular-route.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular-resource.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular-animate.min.js"></script>
|
||||
*/ ?>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular-route.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular-resource.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular-animate.min.js"></script>
|
||||
|
||||
<script src="//cdn.socket.io/socket.io-1.2.0.js"></script>
|
||||
|
||||
<!-- Payment stuff -->
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
</td>
|
||||
<td class="td-download">
|
||||
<!-- upload directive -->
|
||||
<div class="upbutton"><div driver-docs-upload="{{doc.id_driver_document}}"></div></div>
|
||||
<div class="upbutton" driver-docs-upload>
|
||||
<button class="ladda-button upload" data-color="mint" data-style="zoom-in"><span class="ladda-label"><b>UPLOAD</b></span></button>
|
||||
<input ng-if="init" type="file" nv-file-select="" uploader="uploader" name="file" class="file file-hidden" options="{ formData: [{id_driver_document: doc.id_driver_document}]}">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<div class="dont-remove-me i-am-needed-for-comlile ">
|
||||
<div class="box-content2 box-content-table map-info-box">
|
||||
<table class="tb-zebra">
|
||||
<tr>
|
||||
<th>Info</th>
|
||||
<th>Date</th>
|
||||
<th>Restaurant</th>
|
||||
<th>Customer</th>
|
||||
<th>Driver</th>
|
||||
<th>Order</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td><a href="/order/{{order.id_order}}">{{order.id_order}}</td>
|
||||
<td>{{order.date | localtime | timestamp | date:'MM/dd @ HH:mm'}}</td>
|
||||
<td>
|
||||
<a href="/restaurant/{{order._restaurant_permalink}}">{{order._restaurant_name}}</a><br>
|
||||
<a href="/community/{{order._community_permalink}}" ng-if="!community">{{order._community_name}}</a>
|
||||
</td>
|
||||
<td><a href="/customer/{{order.id_user}}">{{order.name}}</a></td>
|
||||
<td><a href="/staff/{{order.status.driver.id_admin}}">{{order.status.driver.name}}</a></td>
|
||||
<td>${{order.final_price_plus_delivery_markup}}</td>
|
||||
<td>
|
||||
<b>{{order.status.status}}</b><br>
|
||||
<span ng-if="order.status"><span am-time-ago="order.status.date | localtime | timestamp"></span></span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
1923
www/assets/cockpit/js/angular-file-upload.js
vendored
1923
www/assets/cockpit/js/angular-file-upload.js
vendored
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,7 @@ App.NGinit = function() {
|
||||
};
|
||||
|
||||
var NGApp = angular.module('NGApp', ['ngRoute', 'ngResource', 'ngAnimate', 'angularFileUpload', 'angularMoment', 'btford.socket-io', 'cfp.hotkeys', 'ngMap'], function( $httpProvider ) {
|
||||
/*
|
||||
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
|
||||
var param = function(obj) {
|
||||
var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
|
||||
@ -75,6 +76,7 @@ var NGApp = angular.module('NGApp', ['ngRoute', 'ngResource', 'ngAnimate', 'angu
|
||||
$httpProvider.defaults.transformRequest = [function(data) {
|
||||
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
|
||||
}];
|
||||
*/
|
||||
});
|
||||
|
||||
NGApp.constant('angularMomentConfig', {
|
||||
|
||||
@ -558,7 +558,7 @@ NGApp.controller('DriversOnboardingCtrl', function ($scope, $timeout, $location,
|
||||
$scope.focus('#search');
|
||||
});
|
||||
|
||||
NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $routeParams, $filter, $fileUploader, DriverOnboardingService, CommunityService ) {
|
||||
NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $routeParams, $filter, FileUploader, DriverOnboardingService, CommunityService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.submitted = false;
|
||||
@ -697,15 +697,14 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $routeParams,
|
||||
|
||||
// Upload control stuff
|
||||
$scope.doc_uploaded = 0;
|
||||
var uploader = $scope.uploader = new FileUploader({
|
||||
url: '/api/driver/documents/upload/'
|
||||
});
|
||||
|
||||
var uploader = $scope.uploader = $fileUploader.create({
|
||||
scope: $scope,
|
||||
url: '/api/driver/documents/upload/',
|
||||
filters: [ function( item ) { return true; } ]
|
||||
} );
|
||||
|
||||
uploader.bind( 'success', function( event, xhr, item, response ) {
|
||||
uploader.onSuccessItem = function(fileItem, response, status, headers) {
|
||||
$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( json ){
|
||||
@ -721,11 +720,11 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $routeParams,
|
||||
} else {
|
||||
$scope.flash.setMessage( 'File not saved: ' + json.error );
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
uploader.bind('error', function (event, xhr, item, response) {
|
||||
uploader.onErrorItem = function (fileItem, response, status, headers) {
|
||||
App.alert( 'Upload error, please try again or send us a message.' );
|
||||
});
|
||||
};
|
||||
|
||||
$scope.download = function( id_driver_document_status ){
|
||||
DriverOnboardingService.docs.download( id_driver_document_status );
|
||||
@ -779,7 +778,7 @@ NGApp.controller( 'DriversOnboardingSetupCtrl', function( $scope, DriverOnboardi
|
||||
|
||||
} );
|
||||
|
||||
NGApp.controller( 'DriversDocsFormCtrl', function( $scope, $fileUploader, DriverOnboardingService, StaffService ) {
|
||||
NGApp.controller( 'DriversDocsFormCtrl', function( $scope, $rootScope, DriverOnboardingService, StaffService) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.status = {};
|
||||
@ -853,6 +852,9 @@ NGApp.controller( 'DriversDocsFormCtrl', function( $scope, $fileUploader, Driver
|
||||
$scope.download = function( id_driver_document_status ){
|
||||
DriverOnboardingService.docs.download( id_driver_document_status );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} );
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ NGApp.controller('OrdersCtrl', function ($scope, $location, OrderService, ViewLi
|
||||
});
|
||||
});
|
||||
|
||||
NGApp.controller('OrderCtrl', function ($scope, $rootScope, $routeParams, $interval, OrderService, MapService) {
|
||||
NGApp.controller('OrderCtrl', function ($scope, $rootScope, $routeParams, $interval, OrderService, MapService, SocketService) {
|
||||
|
||||
SocketService.listen('order.' + $routeParams.id, $scope)
|
||||
.on('update', function(d) {
|
||||
|
||||
@ -240,4 +240,61 @@ NGApp.filter('formatTimezone', function() {
|
||||
var tz = timezone.split('/');
|
||||
return tz[1].replace('_',' ');
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
NGApp.directive( 'driverDocsUpload', function ($rootScope, FileUploader) {
|
||||
return {
|
||||
restrict: 'AE',
|
||||
replace: false,
|
||||
scope: true,
|
||||
link: function ( scope, elem, attrs, ctrl ) {
|
||||
var button = elem.find('button')[0];
|
||||
|
||||
scope.init = true;
|
||||
|
||||
var l = Ladda.create(button);
|
||||
|
||||
angular.element(button).on('click', function() {
|
||||
angular.element(elem.find('input')[0]).click();
|
||||
});
|
||||
|
||||
scope.uploader = new FileUploader({
|
||||
url: '/api/driver/documents/upload/',
|
||||
autoUpload: true
|
||||
});
|
||||
|
||||
scope.uploader.onBeforeUploadItem = function() {
|
||||
l.start();
|
||||
};
|
||||
|
||||
scope.uploader.onSuccessItem = function(fileItem, response, status, headers) {
|
||||
$rootScope.$broadcast( 'driverDocsUploaded', { id_driver_document: response.id_driver_document, response: response } );
|
||||
scope.uploader.clearQueue();
|
||||
l.stop();
|
||||
};
|
||||
|
||||
scope.uploader.onErrorItem = function (fileItem, response, status, headers) {
|
||||
$rootScope.$broadcast( 'driverDocsUploadedError', {} );
|
||||
scope.uploader.clearQueue();
|
||||
l.stop();
|
||||
};
|
||||
|
||||
return;
|
||||
|
||||
|
||||
scope.$watch( 'uploader.progress', function( newValue, oldValue, scope ) {
|
||||
return;
|
||||
console.log(newValue);
|
||||
if( !isNaN( uploader.progress ) ){
|
||||
var progress = ( uploader.progress / 100 );
|
||||
l.setProgress( progress );
|
||||
}
|
||||
});
|
||||
|
||||
$timeout(l.stop, 100);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
NGApp.factory('MapService', function($rootScope, $resource, $routeParams, OrderService) {
|
||||
NGApp.factory('MapService', function($rootScope, $resource, $routeParams, $templateRequest, $timeout, $compile, OrderService) {
|
||||
var service = {
|
||||
icon: {
|
||||
car: {
|
||||
@ -63,22 +63,36 @@ NGApp.factory('MapService', function($rootScope, $resource, $routeParams, OrderS
|
||||
|
||||
service.trackOrders = function(params) {
|
||||
var map = params.map;
|
||||
|
||||
var closeInfoWindows = function() {
|
||||
for (var x in maps[params.id].infoWindows) {
|
||||
maps[params.id].infoWindows[x].close();
|
||||
}
|
||||
}
|
||||
|
||||
if (!maps[params.id]) {
|
||||
maps[params.id] = {
|
||||
markers: []
|
||||
markers: [],
|
||||
infoWindows: []
|
||||
};
|
||||
params.scope.$on('$destroy', function() {
|
||||
service.reset(params.id);
|
||||
});
|
||||
|
||||
google.maps.event.addListener(map, 'click', closeInfoWindows);
|
||||
}
|
||||
console.log(maps[params.id].markers);
|
||||
|
||||
for (var x in maps[params.id].markers) {
|
||||
maps[params.id].markers[x].setMap(null);
|
||||
}
|
||||
maps[params.id].markers = [];
|
||||
console.log(maps[params.id].markers);
|
||||
|
||||
for (var x in maps[params.id].infoWindows) {
|
||||
maps[params.id].infoWindows[x].close();
|
||||
maps[params.id].infoWindows[x] = null;
|
||||
}
|
||||
maps[params.id].infoWindows = [];
|
||||
|
||||
var latlngbounds = new google.maps.LatLngBounds();
|
||||
var updateBounds = function(loc) {
|
||||
latlngbounds.extend(loc);
|
||||
@ -95,7 +109,7 @@ NGApp.factory('MapService', function($rootScope, $resource, $routeParams, OrderS
|
||||
geocoder.geocode({address: address}, function (results, status) {
|
||||
if (status == google.maps.GeocoderStatus.OK) {
|
||||
console.debug('Got geocoded result: ', results[0]);
|
||||
markOrder(results[0].geometry.location);
|
||||
markOrder(order, results[0].geometry.location);
|
||||
|
||||
// update the order with the lat and lon so we never have to geocode the address again
|
||||
OrderService.put({
|
||||
@ -113,16 +127,44 @@ NGApp.factory('MapService', function($rootScope, $resource, $routeParams, OrderS
|
||||
});
|
||||
};
|
||||
|
||||
var markOrder = function(loc) {
|
||||
var markOrder = function(order, loc) {
|
||||
updateBounds(loc);
|
||||
|
||||
maps[params.id].markers.push(new google.maps.Marker({
|
||||
map: map,
|
||||
position: loc,
|
||||
zIndex: 99,
|
||||
animation: google.maps.Animation.DROP,
|
||||
icon: service.icon.customer
|
||||
}));
|
||||
|
||||
$templateRequest('assets/view/mapview-order-info.html').then(function(d) {
|
||||
var orderScope = params.scope.$new(true);
|
||||
orderScope.order = order;
|
||||
|
||||
var template = angular.element(d);
|
||||
var linkFn = $compile(d);
|
||||
var element = linkFn(orderScope);
|
||||
|
||||
$timeout(function() {
|
||||
orderScope.$apply();
|
||||
var infowindow = new google.maps.InfoWindow({
|
||||
content: element[0].innerHTML
|
||||
});
|
||||
|
||||
var marker = new google.maps.Marker({
|
||||
map: map,
|
||||
position: loc,
|
||||
zIndex: 99,
|
||||
animation: google.maps.Animation.DROP,
|
||||
icon: service.icon.customer
|
||||
});
|
||||
|
||||
maps[params.id].markers.push(marker);
|
||||
maps[params.id].infoWindows.push(infowindow);
|
||||
|
||||
google.maps.event.addListener(marker, 'click', function() {
|
||||
closeInfoWindows();
|
||||
infowindow.open(map, marker);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var trackOrder = function(order) {
|
||||
@ -130,7 +172,7 @@ NGApp.factory('MapService', function($rootScope, $resource, $routeParams, OrderS
|
||||
return;
|
||||
}
|
||||
if (order.lat && order.lon) {
|
||||
markOrder(new google.maps.LatLng(parseFloat(order.lat), parseFloat(order.lon)));
|
||||
markOrder(order, new google.maps.LatLng(parseFloat(order.lat), parseFloat(order.lon)));
|
||||
} else {
|
||||
getGeo(order.id_order, order.address, 0);
|
||||
}
|
||||
|
||||
@ -3446,4 +3446,8 @@ input[type="checkbox"].switch + div:before {
|
||||
@-webkit-keyframes masked-animation {
|
||||
0% {background-position: -10000px bottom;}
|
||||
100% {background-position: left bottom;}
|
||||
}
|
||||
|
||||
.map-info-box {
|
||||
font-size: .8em;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user