浏览代码

navigation feature added to customer module

robert 8 年之前
父节点
当前提交
b422e42613

+ 2 - 1
package.json

@@ -25,7 +25,8 @@
     "cordova-plugin-contacts",
     "cordova-plugin-vibration",
     "cordova-plugin-geolocation",
-    "cordova-plugin-device-motion"
+    "cordova-plugin-device-motion",
+    "uk.co.workingedge.phonegap.plugin.launchnavigator"
   ],
   "cordovaPlatforms": [
     "android"

+ 47 - 11
www/js/controllers/customer.controller.js

@@ -13,8 +13,6 @@ angular.module('odoo')
         customersRemoteFactory,
         customersStorageFactory,
         sqlFactory,
-        cameraFactory,
-        contactFactory,
         deviceFactory
     ) {
         $scope.loading = false;
@@ -27,32 +25,50 @@ angular.module('odoo')
             $scope.customerModal = modal;
         });
 
+        /**
+         *
+         */
         $scope.$on('$ionicView.enter', function () {
-            $scope.fill();
+            $scope.fill(false);
         });
 
+        /**
+         *
+         */
         $scope.$on('$destroy', function () {
             $scope.customerModal.remove();
         });
 
+        /**
+         *
+         */
         $scope.$on('modal.hidden', function () {
             $scope.customer = {};
         });
 
-        $scope.$on('device.shaked', function () { 
+        /**
+         *
+         */
+        $scope.$on('device.shaked', function () {
             if ($scope.customerModal.isShown()) {
-                deviceFactory.getCurrentPosition(function (position) { 
-                    console.log(position);
+
+                deviceFactory.getCurrentPosition(function (position) {
+                    $scope.customer.partner_latitude = position.coords.latitude;
+                    $scope.customer.partner_longitude = position.coords.longitude;
+                    $scope.customer.date_localization = new Date(position.timestamp).toLocaleString();
                 }, function (err) {
                     console.log(err);
                 });
+
+            } else {
+                $scope.fill(false);
             }
         });
 
         /**
          *
          */
-        $scope.fill = function (refresh = false) {
+        $scope.fill = function (refresh) {
             $scope.loading = !refresh;
 
             customersRemoteFactory.sync(function (customers) {
@@ -111,7 +127,7 @@ angular.module('odoo')
                 $scope.customer = $scope.customers[index];
             }
 
-            console.log('Customer selected => ' + angular.toJson($scope.customer));
+            console.log('Customer selected => ' + angular.toJson($scope.customer, true));
 
             $ionicActionSheet.show({
                 titleText: 'Acciones',
@@ -121,6 +137,9 @@ angular.module('odoo')
                     },
                     {
                         text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
+                    },
+                    {
+                        text: '<i class="icon ion-navigate positive"></i> Ir a la ubicación'
                     }
                 ],
                 destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
@@ -136,6 +155,9 @@ angular.module('odoo')
                         case 1:
                             $scope.addContact();
                             break;
+                        case 2:
+                            $scope.navigate();
+                            break;
                         default:
                             $scope.show();
                     }
@@ -204,7 +226,7 @@ angular.module('odoo')
          *
          */
         $scope.takePicture = function () {
-            cameraFactory.takePicture(function (imageData) {
+            deviceFactory.takePicture(function (imageData) {
                 $scope.customer.image_small = imageData;
                 $scope.customer.image_medium = imageData;
             }, function (error) {
@@ -216,10 +238,24 @@ angular.module('odoo')
          *
          */
         $scope.addContact = function () {
-            contactFactory.save($scope.customer, function (result) {
-                $ionicPopup.alert({ title: 'Contacto guardado' });
+            deviceFactory.saveContact($scope.customer, function (result) {
+                console.log(result);
             }, function (error) {
                 console.log(error);
             })
         }
+
+        /**
+         *
+         */
+        $scope.navigate = function () {
+            deviceFactory.navigate([
+                $scope.customer.partner_latitude,
+                $scope.customer.partner_longitude
+            ], function (message) {
+                console.log(message);
+            }, function (err) {
+                console.log(err);
+            })
+        }
     });

+ 1 - 1
www/js/factories/database.factory.js

@@ -41,7 +41,7 @@ angular.module('odoo')
                         statement += key + ' BLOB DEFAULT NULL,\n';
                     }
 
-                    if (model[key].type == 'char' || model[key].type == 'text' || model[key].type == 'datetime') {
+                    if (model[key].type == 'char' || model[key].type == 'text' || model[key].type == 'date' || model[key].type == 'datetime') {
                         statement += key + ' TEXT DEFAULT NULL,\n';
                     }
 

+ 8 - 0
www/js/factories/sales/customer.storage.factory.js

@@ -15,6 +15,8 @@ angular.module('odoo')
         var save = function (data, success, error) {
             var query = null;
 
+            console.log(data);
+
             if (data.id) {
                 query = squel.update()
                     .table('partner')
@@ -34,6 +36,9 @@ angular.module('odoo')
                     .set('customer', 1)
                     .set('employee', 0)
                     .set('is_company', 0)
+                    .set('partner_latitude', data.partner_latitude ? data.partner_latitude : 0)
+                    .set('partner_longitude', data.partner_longitude ? data.partner_longitude : 0)
+                    .set('date_localization', data.date_localization ? data.date_localization : null)
                     .where('id = ?', data.id)
                     .toParam();
             } else {
@@ -65,6 +70,9 @@ angular.module('odoo')
                     .set('total_invoiced', data.total_invoiced)
                     .set('type', data.type ? data.type : 'contact')
                     .set('active', data.active ? data.active : 1)
+                    .set('partner_latitude', data.partner_latitude ? data.partner_latitude : 0)
+                    .set('partner_longitude', data.partner_longitude ? data.partner_longitude : 0)
+                    .set('date_localization', data.date_localization ? data.date_localization : null)
                     .set('company_id', angular.isArray(data.company_id) ? data.company_id[0] : configuration.company_id)
                     .set('create_uid', angular.isArray(data.create_uid) ? data.create_uid[0] : configuration.id)
                     .toParam();

+ 95 - 94
www/js/factories/utils.factory.js

@@ -127,13 +127,26 @@ angular.module('odoo')
     })
 
     /**
-     * -----------------------------------------------------------------------------
-     *  Description:    Native camera manager
-     * -----------------------------------------------------------------------------
-     */
-    .factory('cameraFactory', function ($cordovaCamera) {
+    * -----------------------------------------------------------------------------
+    *  Description:    Native device functions manager
+    * -----------------------------------------------------------------------------
+    */
+    .factory('deviceFactory', function (
+        $timeout,
+        $rootScope,
+        $cordovaCamera,
+        $cordovaContacts,
+        $cordovaGeolocation,
+        $cordovaDeviceMotion,
+        $cordovaLaunchNavigator,
+        $cordovaToast,
+        $cordovaVibration
+    ) {
+        var vibrateDuration = 100;
 
-        // Take a picture using native camera
+        /**
+         *
+         */
         var takePicture = function (success, error) {
             var options = {
                 quality: 75,
@@ -153,27 +166,67 @@ angular.module('odoo')
             }, function (err) {
                 error(err);
             });
-        };
-
-        return {
-            takePicture: takePicture
         }
-    })
 
-    /**
-    * -----------------------------------------------------------------------------
-    *  Description:    Native device functions manager
-    * -----------------------------------------------------------------------------
-    */
-    .factory('deviceFactory', function (
-        $timeout,
-        $rootScope,
-        $cordovaGeolocation,
-        $cordovaDeviceMotion,
-        $cordovaToast,
-        $cordovaVibration
-    ) {
-        var vibrateDuration = 100;
+        var saveContact = function (contact, success, error) {
+            if (!contact.mobile && !contact.phone && !contact.email) {
+                error();
+                return;
+            }
+
+            var info = {
+                name: {
+                    givenName: contact.name,
+                    familyName: '',
+                    formatted: ''
+                },
+                nickname: '',
+                phoneNumbers: [
+                    {
+                        value: contact.phone,
+                        type: 'phone'
+                    },
+                    {
+                        value: contact.mobile,
+                        type: 'mobile'
+                    }
+                ],
+                emails: [
+                    {
+                        value: contact.email,
+                        type: 'home'
+                    }
+                ],
+                addresses: [
+                    {
+                        type: 'home',
+                        formatted: '',
+                        streetAddress: contact.street,
+                        locality: contact.city,
+                        region: '',
+                        postalCode: '',
+                        country: 'Paraguay'
+                    }
+                ],
+                ims: null,
+                organizations: null,
+                birthday: null,
+                note: null,
+                photos: null,
+                categories: null,
+                urls: null
+            };
+
+            $cordovaContacts.save(info).then(function (result) {
+                $cordovaVibration.vibrate(vibrateDuration);
+
+                success(result);
+            }, function (err) {
+                $cordovaVibration.vibrate(vibrateDuration);
+
+                error(err);
+            });
+        }
 
         /**
          *
@@ -200,6 +253,21 @@ angular.module('odoo')
             });
         }
 
+        /**
+         *
+         */
+        var navigate = function (destination, success, error) {
+            // if (!destination.latitude || !destination.longitude) {
+            //     return error('Invalid destination');
+            // }
+
+            $cordovaLaunchNavigator.navigate(destination).then(function () { 
+                success('Navigator launched');
+            }, function (err) { 
+                error(err);
+            });
+        }
+
         /**
          *
          */
@@ -254,76 +322,9 @@ angular.module('odoo')
         }
 
         return {
+            takePicture: takePicture,
             getCurrentPosition: getCurrentPosition,
+            navigate: navigate,
             detectShake: detectShake
         }
-    })
-
-    /**
-     * -----------------------------------------------------------------------------
-     *  Description:    Native contacts manager
-     * -----------------------------------------------------------------------------
-     */
-    .factory('contactFactory', function ($cordovaContacts) {
-
-        // Save customer information to device contacts
-        var save = function (customer, success, error) {
-            if (!customer.mobile && !customer.phone && !customer.email) {
-                error();
-                return;
-            }
-
-            var contact = {
-                name: {
-                    givenName: customer.name,
-                    familyName: '',
-                    formatted: ''
-                },
-                nickname: '',
-                phoneNumbers: [
-                    {
-                        value: customer.phone,
-                        type: 'phone'
-                    },
-                    {
-                        value: customer.mobile,
-                        type: 'mobile'
-                    }
-                ],
-                emails: [
-                    {
-                        value: customer.email,
-                        type: 'home'
-                    }
-                ],
-                addresses: [
-                    {
-                        type: 'home',
-                        formatted: '',
-                        streetAddress: customer.street,
-                        locality: customer.city,
-                        region: '',
-                        postalCode: '',
-                        country: 'Paraguay'
-                    }
-                ],
-                ims: null,
-                organizations: null,
-                birthday: null,
-                note: null,
-                photos: null,
-                categories: null,
-                urls: null
-            };
-
-            $cordovaContacts.save(contact).then(function (result) {
-                success(result);
-            }, function (err) {
-                error(err);
-            });
-        };
-
-        return {
-            save: save
-        }
     });

文件差异内容过多而无法显示
+ 1 - 1
www/templates/sales/customers.html


部分文件因为文件数量过多而无法显示