فهرست منبع

remodeled code for best performance and modularity

robert2206 8 سال پیش
والد
کامیت
a18de9fec7

+ 4 - 3
www/index.html

@@ -24,10 +24,11 @@
 
     <!-- Factories -->
     <script src="js/factories/utils.factory.js"></script>
-    <script src="js/factories/storage.factory.js"></script>
     <script src="js/factories/odoo.factory.js"></script>
-    <script src="js/factories/sale/sync.customer.factory.js"></script>
-    <script src="js/factories/sale/sync.lead.factory.js"></script>
+    <script src="js/factories/storage.user.factory.js"></script>
+    <script src="js/factories/sales/storage.customer.factory.js"></script>
+    <script src="js/factories/sales/sync.customer.factory.js"></script>
+    <script src="js/factories/sales/sync.lead.factory.js"></script>
     <!-- 3rd Party -->
     <script src="lib/angular-xmlrpc/xmlrpc.js"></script>
   </head>

+ 25 - 3
www/js/app.js

@@ -61,6 +61,28 @@ angular.module('odoo',['ionic', 'ngCordova', 'xml-rpc'])
                        'phonecall_count' INTEGER DEFAULT 0,\n\
                        'sale_order_count' INTEGER DEFAULT NULL,\n\
                        'total_invoiced' INTEGER DEFAULT NULL);");
+
+        db.executeSql("CREATE TABLE IF NOT EXISTS 'lead' (\n\
+                      'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n\
+                      'remote_id' INTEGER DEFAULT 0,\n\
+                      'modified' INTEGER DEFAULT 0,\n\
+                      'modifiedDate' TEXT DEFAULT CURRENT_TIMESTAMP,\n\
+                      'name' VARCHAR(35) DEFAULT NULL,\n\
+                      'description' VARCHAR(100) DEFAULT NULL,\n\
+                      'contact_name' VARCHAR(100) DEFAULT NULL,\n\
+                      'phone' VARCHAR(20) DEFAULT NULL,\n\
+                      'mobile' VARCHAR(20) DEFAULT NULL,\n\
+                      'fax' VARCHAR(20) DEFAULT NULL,\n\
+                      'street' VARCHAR(35) DEFAULT NULL,\n\
+                      'street2' VARCHAR(35) DEFAULT NULL,\n\
+                      'meeting_count' INTEGER DEFAULT 0,\n\
+                      'message_bounce' INTEGER DEFAULT 0,\n\
+                      'planned_cost' INTEGER DEFAULT 0,\n\
+                      'planned_revenue' INTEGER DEFAULT 0,\n\
+                      'priority' INTEGER DEFAULT 0,\n\
+                      'probability' INTEGER DEFAULT 0,\n\
+                      'type' VARCHAR(20) DEFAULT NULL,\n\
+                      'partner_id' INTEGER DEFAULT 0);");
     });
 })
 
@@ -85,7 +107,7 @@ angular.module('odoo',['ionic', 'ngCordova', 'xml-rpc'])
             url: 'app/sales',
             views: {
                 'content': {
-                    templateUrl: 'templates/sale/sales.html',
+                    templateUrl: 'templates/sales/sales.html',
                     controller: 'SaleController'
                 }
             }
@@ -95,7 +117,7 @@ angular.module('odoo',['ionic', 'ngCordova', 'xml-rpc'])
             url: 'app/customers',
             views: {
                 'content': {
-                    templateUrl: 'templates/sale/customers.html',
+                    templateUrl: 'templates/sales/customers.html',
                     controller: 'CustomersController'
                 }
             }
@@ -105,7 +127,7 @@ angular.module('odoo',['ionic', 'ngCordova', 'xml-rpc'])
             url: 'app/leads',
             views: {
                 'content': {
-                    templateUrl: 'templates/sale/leads.html',
+                    templateUrl: 'templates/sales/leads.html',
                     controller: 'LeadsController'
                 }
             }

+ 12 - 4
www/js/controllers/configuration.controller.js

@@ -1,16 +1,24 @@
 angular.module('odoo')
 
-.controller('ConfigurationController', function($scope, $state, $ionicLoading, $ionicPopup, odoo, storage) {
-    $scope.config = { host: '192.168.88.116', port: 8069, database: 'odoo', username: 'admin', password: 'admin' }
+.controller('ConfigurationController', function (
+    $scope,
+    $state,
+    $ionicLoading,
+    $ionicPopup,
+    odoo,
+    sql,
+    userStorage
+) {
+    $scope.config = { host: '192.168.2.103', port: 8069, database: 'odoo', username: 'admin', password: 'admin' }
 
     // Apply configuration for app
     $scope.configure = function () {
         $ionicLoading.show();
 
-        storage.count('user', function (total) {
+        sql.count('user', function (total) {
             if (total == 0) {
                 odoo.auth($scope.config, function (user) {
-                    storage.saveUser(
+                    userStorage.save(
                         [
                             user.id,
                             $scope.config.host,

+ 14 - 16
www/js/controllers/customer.controller.js

@@ -2,23 +2,21 @@ angular.module('odoo')
 
 .controller('CustomersController', function (
     $scope,
-    $log,
     $ionicLoading,
     $ionicModal,
     $ionicActionSheet,
     $ionicPopup,
     customers,
     odoo,
-    storage,
+    sql,
+    customerStorage,
     camera,
     contact
 ) {
-
-    // Objects
-    $scope.customer = {};
     $scope.customers = [];
+    $scope.customer = {};
 
-    $ionicModal.fromTemplateUrl('templates/sale/customer.html', {
+    $ionicModal.fromTemplateUrl('templates/sales/customer.html', {
         scope: $scope,
         animation: 'slide-in-up'
     }).then(function(modal) {
@@ -64,7 +62,7 @@ angular.module('odoo')
 
     // Get filtered customers for correct data visualization
     $scope.getCustomers = function (success, error) {
-        storage.getByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
+        sql.selectByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
             console.log(customers);
             $scope.customers = [];
 
@@ -87,22 +85,22 @@ angular.module('odoo')
             $scope.customer = $scope.customers[index];
         }
 
-        $log.info('Customer selected => ' + JSON.stringify($scope.customer));
+        console.log('Customer selected => ' + JSON.stringify($scope.customer));
 
         $ionicActionSheet.show({
             titleText: 'Acciones',
             buttons: [
                 {
-                    text: '<i class="icon ion-eye positive"></i> Detallar'
+                    text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
                 },
                 {
                     text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
                 }
             ],
-            destructiveText: 'Eliminar',
+            destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
             cancel: function() {
                 $scope.customer = {};
-                $log.info('ActionSheet canceled');
+                console.log('ActionSheet canceled');
             },
             buttonClicked: function(index) {
                 switch (index) {
@@ -127,7 +125,7 @@ angular.module('odoo')
 
     // Save a customer data on local database
     $scope.save = function() {
-        storage.saveCustomer($scope.customer, function (customerId) {
+        customerStorage.save($scope.customer, function (customerId) {
             if (!$scope.customer.id) {
                 $scope.customer.id = customerId;
                 $scope.customers.push($scope.customer);
@@ -135,10 +133,10 @@ angular.module('odoo')
 
             $scope.customer = {};
             $scope.customerModal.hide();
-            $log.info('Customer saved');
+            console.log('Customer saved');
         }, function (error) {
             $ionicPopup.alert({ title: 'No se ha podido guardar el cliente', template: JSON.stringify(error) });
-            $log.error(JSON.stringify(error));
+            console.log(JSON.stringify(error));
         });
     }
 
@@ -149,7 +147,7 @@ angular.module('odoo')
             template: 'Estás seguro que quieres eliminar este cliente?'
         }).then(function (confirmation) {
             if(confirmation) {
-                storage.deleteCustomer($scope.customer, function (affected) {
+                customerStorage.remove($scope.customer, function (affected) {
                     if (affected != 0) {
                         var index = $scope.customers.indexOf($scope.customer);
                         $scope.customers.splice(index, 1);
@@ -159,7 +157,7 @@ angular.module('odoo')
                     }
                 }, function (error) {
                     $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
-                    $log.error(JSON.stringify(error));
+                    console.log(JSON.stringify(error));
                 });
             }
         });

+ 94 - 6
www/js/controllers/lead.controller.js

@@ -1,14 +1,102 @@
 angular.module('odoo')
 
-.controller('LeadsController', function ($scope, leads) {
-    
-    leads.read(function (leads) {
-        console.log(leads);
-    }, function (error) {
-        console.log(error);
+.controller('LeadsController', function (
+    $scope,
+    $ionicModal,
+    $ionicActionSheet,
+    $ionicPopup,
+    leads
+) {
+    $scope.leads = [];
+    $scope.lead = {};
+
+    $ionicModal.fromTemplateUrl('templates/sales/lead.html', {
+        scope: $scope,
+        animation: 'slide-in-up'
+    }).then(function(modal) {
+        $scope.leadModal = modal;
+    });
+
+    $scope.$on('$ionicView.enter', function () {
+        $scope.fill();
+    });
+
+    $scope.$on('$destroy', function() {
+        $scope.leadModal.remove();
     });
 
+    $scope.$on('modal.hidden', function() {
+        $scope.lead = {};
+    });
+
+    $scope.fill = function () {
+        leads.read(function (leads) {
+            console.log(leads);
+            $scope.leads = leads;
+        }, function (error) {
+            console.log(error);
+        });
+    }
+
     $scope.show = function () {
+        $scope.leadModal.show();
+    }
+
+    $scope.save = function () {
+
+    }
+
+    $scope.delete = function () {
+        $ionicPopup.confirm({
+            title: 'Confirmar',
+            template: 'Estás seguro que quieres eliminar esta iniciativa?'
+        }).then(function (confirmation) {
+            if(confirmation) {
+                console.log(confirmation);
+            }
+        });
+    }
+
+    $scope.openOptions = function (index) {
+        if (index == -1) {
+            $scope.lead = {};
+        } else {
+            $scope.lead = $scope.leads[index];
+        }
+
+        $ionicActionSheet.show({
+            titleText: 'Acciones',
+            buttons: [
+                {
+                    text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
+                },
+                {
+                    text: '<i class="icon ion-wand positive"></i> Convertir a oportunidad'
+                }
+            ],
+            destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
+            cancel: function() {
+                $scope.lead = {};
+                $log.info('ActionSheet canceled');
+            },
+            buttonClicked: function(index) {
+                switch (index) {
+                    case 0:
+                        $scope.show();
+                        break;
+                    case 1:
+                        console.log('1');
+                        break;
+                    default:
+                        $scope.show();
+                }
+                return true;
+            },
+            destructiveButtonClicked: function() {
+                $scope.delete();
 
+                return true;
+            }
+        });
     }
 });

+ 0 - 127
www/js/factories/sale/sync.customer.factory.js

@@ -1,127 +0,0 @@
-angular.module('odoo')
-
-.factory('customers', function (storage, odoo, async) {
-    return {
-        sync: function (success, error) {
-            // Get current user saved on mobile
-            storage.get('user', function (users) {
-                if (users.length == 1) {
-                    var userConfig = users.item(0);
-
-                    // 1. Transfer all new data from mobile to server
-                    storage.getByConstraint('partner', 'remote_id = 0 AND customer = 1', function(newPartners) {
-                        async.loop(newPartners.length, function (loop) {
-                            var data = newPartners.item(loop.iteration());
-
-                            // Avoid odoo server warning message
-                            delete data.id;
-                            delete data.remote_id;
-                            delete data.modified;
-                            delete data.modifiedDate;
-
-                            odoo.create('res.partner', data, userConfig, function (response) {
-                                loop.next();
-                            }, function (odooCreateError) {
-                                loop.break();
-                            });
-
-                        // End loop
-                        }, function() {
-                            // 2. Transfer all modified data from mobile to server
-                            storage.getByConstraint('partner', 'remote_id != 0 AND customer = 1 AND modified = 1', function (modifiedPartners) {
-                                async.loop(modifiedPartners.length, function (loop) {
-                                    var localData = modifiedPartners.item(loop.iteration());
-
-                                    odoo.read('res.partner', [['id', '=', localData.remote_id]], userConfig, function (response) {
-                                        if (response.length == 1) {
-                                            var remoteData = response[0];
-
-                                            var remoteModifiedDate = new Date(remoteData.__last_update);
-                                            var localModifiedDate = new Date(localData.modifiedDate);
-
-                                            if (localModifiedDate > remoteModifiedDate) {
-                                                var id = localData.remote_id;
-
-                                                // Avoid odoo server warning message
-                                                delete localData.id;
-                                                delete localData.remote_id;
-                                                delete localData.modified;
-                                                delete localData.modifiedDate;
-
-                                                odoo.write('res.partner', id, localData, userConfig, function (response) {
-                                                    loop.next();
-                                                }, function (odooWriteError) {
-                                                    console.error(odooWriteError);
-                                                    loop.next();
-                                                });
-                                            } else {
-                                                loop.next();
-                                            }
-                                        } else {
-                                            loop.next();
-                                        }
-                                    }, function(odooReadError) {
-                                        console.error(odooReadError);
-                                        loop.next();
-                                    });
-
-                                // End loop
-                                }, function () {
-                                    // 3. Delete server data from mobile
-                                    storage.getByConstraint('partner', 'remote_id != 0 AND customer = 1 AND modified = 2', function (deletedPartners) {
-                                        async.loop(deletedPartners.length, function (loop) {
-                                            var id = deletedPartners.item(loop.iteration()).remote_id;
-
-                                            odoo.unlink('res.partner', id, userConfig, function (response) {
-                                                loop.next();
-                                            }, function (odooUnlinkError) {
-                                                console.error(odooUnlinkError);
-                                                loop.next();
-                                            });
-
-                                        // End loop
-                                        }, function () {
-                                            // 4. Download updated data from server to mobile
-                                            odoo.read('res.partner', [['customer', '=', true]], userConfig, function (updatedPartners) {
-                                                storage.deleteAllCustomers(function () {
-                                                    async.loop(updatedPartners.length, function (loop) {
-                                                        var data = updatedPartners[loop.iteration()];
-
-                                                        // Set id for save on local database
-                                                        data.remote_id = data.id;
-                                                        delete data.id;
-
-                                                        storage.saveCustomer(data, function (customerId) {
-                                                            loop.next();
-                                                        } ,function (saveCustomerError) {
-                                                            console.error(saveCustomerError);
-                                                            loop.next();
-                                                        });
-                                                    }, function () {
-                                                        success(updatedPartners);
-                                                    });
-                                                }, function (deleteAllCustomersError) {
-                                                    error(deleteAllCustomersError);
-                                                });
-                                            }, function (odooReadError) {
-                                                error(odooReadError);
-                                            });
-                                        });
-                                    }, function (getDeletedPartnersError) {
-                                        error(getDeletedPartnersError);
-                                    });
-                                });
-                            }, function (getModifiedPartnersError) {
-                                error(getModifiedPartnersError);
-                            });
-                        });
-                    }, function (partnerGetByConstraintError) {
-                        error(partnerGetByConstraintError);
-                    });
-                }
-            }, function(userGetError) {
-                error(userGetError);
-            });
-        }
-    }
-});

+ 0 - 21
www/js/factories/sale/sync.lead.factory.js

@@ -1,21 +0,0 @@
-angular.module('odoo')
-
-.factory('leads', function (config, odoo) {
-    // Read leads from server
-    var readLeads = function (success, error) {
-        config(function (users) {
-            if (users.length)
-            odoo.read('crm.lead', [['active', '=', true]], function (leads) {
-                success(leads);
-            }, function (err) {
-                error(err);
-            });
-        }, function (err) {
-            error(err);
-        });
-    }
-
-    return {
-        read: readLeads
-    }
-});

+ 0 - 90
www/js/factories/storage.factory.js

@@ -1,90 +0,0 @@
-angular.module('odoo')
-
-.factory('storage', function () {
-    return {
-        // Customer
-        saveCustomer(customer, success, error) {
-            var sql = '';
-
-            if (customer.id) {
-                sql = `UPDATE partner SET remote_id = ${ customer.remote_id ? customer.remote_id : 0  }, modified = 1, modifiedDate = CURRENT_TIMESTAMP, name = ${ customer.name ? '"' + customer.name + '"' : null }, city = ${ customer.city ? '"' + customer.city + '"' : null }, mobile = ${ customer.mobile ? '"' + customer.mobile + '"' : null }, phone = ${ customer.phone ? '"' + customer.phone + '"' : null }, fax = ${ customer.fax ? '"' + customer.fax + '"' : null }, email = ${ customer.email ? '"' + customer.email + '"' : null }, street = ${ customer.street ? '"' + customer.street + '"' : null }, street2 = ${ customer.street2 ? '"' + customer.street2 + '"' : null }, image_medium = ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, image_small = ${ customer.image_small ? '"' + customer.image_small + '"' : null }, comment = ${ customer.comment ? '"' + customer.comment + '"' : null }, customer = ${ customer.customer ? customer.customer : 1 }, employee = ${ customer.employee ? customer.employee : 0 }, is_company = ${ customer.is_company ? customer.is_company : 0 }, debit = ${ customer.debit ? customer.debit : 0 }, debit_limit = ${ customer.debit_limit ? customer.debit_limit : 0 }, opportunity_count = ${ customer.opportunity_count ? customer.opportunity_count : 0 }, contracts_count = ${ customer.contracts_count ? customer.contracts_count : 0 }, journal_item_count = ${ customer.journal_item_count ? customer.journal_item_count : 0 }, meeting_count = ${ customer.meeting_count ? customer.meeting_count : 0 }, phonecall_count = ${ customer.phonecall_count ? customer.phonecall_count : 0 }, sale_order_count = ${ customer.sale_order_count ? customer.sale_order_count : 0 }, total_invoiced = ${ customer.total_invoiced ? customer.total_invoiced : 0 } WHERE id = ${ customer.id }`;
-            } else {
-                sql = `INSERT INTO partner(remote_id, name, city, mobile, phone, fax, email, street, street2, image_medium, image_small, comment, customer, employee, is_company, debit, debit_limit, opportunity_count, contracts_count, journal_item_count, meeting_count, phonecall_count, sale_order_count, total_invoiced) VALUES (${ customer.remote_id ? customer.remote_id : 0 }, ${ customer.name ? '"' + customer.name + '"' : null }, ${ customer.city ? '"' + customer.city + '"' : null }, ${ customer.mobile ? '"' + customer.mobile + '"' : null }, ${ customer.phone ? '"' + customer.phone + '"' : null }, ${ customer.fax ? '"' + customer.fax + '"' : null }, ${ customer.email ? '"' + customer.email + '"' : null }, ${ customer.street ? '"' + customer.street + '"' : null }, ${ customer.street2 ? '"' + customer.street2 + '"' : null }, ${ customer.image_medium ? '"' + customer.image_medium + '"' : null }, ${ customer.image_small ? '"' + customer.image_small + '"' : null }, ${ customer.comment ? '"' + customer.comment + '"' : null }, 1, 0, 0, ${ customer.debit ? customer.debit : 0 }, ${ customer.debit_limit ? customer.debit_limit : 0 }, ${ customer.opportunity_count ? customer.opportunity_count : 0 }, ${ customer.contracts_count ? customer.contracts_count : 0 }, ${ customer.journal_item_count ? customer.journal_item_count : 0 }, ${ customer.meeting_count ? customer.meeting_count : 0 }, ${ customer.phonecall_count ? customer.phonecall_count : 0 }, ${ customer.sale_order_count ? customer.sale_order_count : 0 }, ${ customer.total_invoiced ? customer.total_invoiced : 0 })`;
-            }
-
-            db.executeSql(sql, [], function(result) {
-                success(sql.startsWith('INSERT') ? result.insertId : customer.id);
-            }, function(err) {
-                error(err);
-            });
-        },
-        deleteCustomer(customer, success, error) {
-            if (!customer.id) {
-                error('Customer cannot delete without provide an id');
-            }
-
-            var sql = '';
-
-            if (customer.remote_id) {
-                sql = `UPDATE partner SET modified = 2 WHERE id = ${ customer.id }`;
-            } else {
-                sql = `DELETE FROM partner WHERE id = ${ customer.id }`;
-            }
-
-            console.log(sql);
-
-            db.executeSql(sql, [], function(result) {
-                success(result.rowsAffected);
-            }, function(err) {
-                error(err);
-            });
-        },
-        deleteAllCustomers(success, error) {
-            var sql = 'DELETE FROM partner WHERE customer = 1';
-
-            db.executeSql(sql, [], function(result) {
-                success(result.rowsAffected);
-            }, function(err) {
-                error(err);
-            });
-        },
-        // Users
-        saveUser: function(data, success, error) {
-            var sql = 'INSERT INTO user(remote_id, host, port, database, username, password) VALUES(?, ?, ?, ?, ?, ?)';
-
-            db.executeSql(sql, data, function (result) {
-                success(result.insertId);
-            }, function (err) {
-                error(err);
-            });
-        },
-        // Utils
-        get: function(tableName, success, error) {
-            var sql = 'SELECT * FROM ' + tableName;
-
-            db.executeSql(sql, [], function(result) {
-                success(result.rows);
-            }, function(err) {
-                error(err);
-            });
-        },
-        getByConstraint: function(tableName, constraint, success, error) {
-            var sql = 'SELECT * FROM ' + tableName + ' WHERE ' + constraint;
-
-            db.executeSql(sql, [], function(result) {
-                success(result.rows);
-            }, function(err) {
-                error(err);
-            });
-        },
-        count: function(tableName, success, error) {
-            var sql = 'SELECT COUNT(*) AS total FROM ' + tableName;
-
-            db.executeSql(sql, [], function(result) {
-                success(result.rows.item(0).total);
-            }, function(err) {
-                error(err);
-            });
-        }
-    }
-});

+ 189 - 75
www/js/factories/utils.factory.js

@@ -1,8 +1,60 @@
 angular.module('odoo')
 
-.factory('config', function (storage) {
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Native SQL util instructions
+ * -----------------------------------------------------------------------------
+ */
+.factory('sql', function () {
+
+    // Execute native SQL SELECT instruction
+    var select = function(tableName, success, error) {
+        var sql = 'SELECT * FROM ' + tableName;
+
+        db.executeSql(sql, [], function(result) {
+            success(result.rows);
+        }, function(err) {
+            error(err);
+        });
+    };
+
+    // Execute native SQL SELECT instruction with a constraint
+    var selectByConstraint = function(tableName, constraint, success, error) {
+        var sql = 'SELECT * FROM ' + tableName + ' WHERE ' + constraint;
+
+        db.executeSql(sql, [], function(result) {
+            success(result.rows);
+        }, function(err) {
+            error(err);
+        });
+    };
+
+    // Execute native SQL SELECT instruction with count instruction
+    var count = function(tableName, success, error) {
+        var sql = 'SELECT COUNT(*) AS total FROM ' + tableName;
+
+        db.executeSql(sql, [], function(result) {
+            success(result.rows.item(0).total);
+        }, function(err) {
+            error(err);
+        });
+    };
+
+    return {
+        select: select,
+        selectByConstraint: selectByConstraint,
+        count: count
+    }
+})
+
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Get user configuration from local database
+ * -----------------------------------------------------------------------------
+ */
+.factory('config', function (sql) {
     return function (success, error) {
-        storage.get('user', function (users) {
+        sql.get('user', function (users) {
             success(users);
         }, function (err) {
             error(err);
@@ -10,6 +62,51 @@ angular.module('odoo')
     };
 })
 
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Async loop util v2
+ * -----------------------------------------------------------------------------
+ */
+.factory('asyncLoop', function () {
+    return function (iterations, func, callback) {
+                var index = 0;
+                var done = false;
+                var loop = {
+                    next: function  () {
+                        if (done) {
+                            return;
+                        }
+
+                        if (index < iterations) {
+                            index++;
+                            func(loop);
+
+                        } else {
+                            done = true;
+                            callback();
+                        }
+                    },
+
+                    iteration: function() {
+                        return index - 1;
+                    },
+
+                    break: function() {
+                        done = true;
+                        callback();
+                    }
+                };
+
+                loop.next();
+                return loop;
+            }
+})
+
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Async loop util
+ * -----------------------------------------------------------------------------
+ */
 .factory('async', function () {
     return {
         loop: function (iterations, func, callback) {
@@ -47,88 +144,105 @@ angular.module('odoo')
     }
 })
 
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Native camera manager
+ * -----------------------------------------------------------------------------
+ */
 .factory('camera', function ($cordovaCamera) {
-    return {
-        takePicture: function (success, error) {
-            var options = {
-                quality: 75,
-                destinationType: Camera.DestinationType.DATA_URL,
-                sourceType: Camera.PictureSourceType.CAMERA,
-                allowEdit: true,
-                encodingType: Camera.EncodingType.JPEG,
-                targetWidth: 300,
-                targetHeight: 300,
-                popoverOptions: CameraPopoverOptions,
-                saveToPhotoAlbum: false,
-                correctOrientation:true
-            };
 
-            $cordovaCamera.getPicture(options).then(function(imageData) {
-                success(imageData);
-            }, function(err) {
-                error(err);
-            });
-        }
+    // Take a picture using native camera
+    var takePicture = function (success, error) {
+        var options = {
+            quality: 75,
+            destinationType: Camera.DestinationType.DATA_URL,
+            sourceType: Camera.PictureSourceType.CAMERA,
+            allowEdit: true,
+            encodingType: Camera.EncodingType.JPEG,
+            targetWidth: 300,
+            targetHeight: 300,
+            popoverOptions: CameraPopoverOptions,
+            saveToPhotoAlbum: false,
+            correctOrientation:true
+        };
+
+        $cordovaCamera.getPicture(options).then(function(imageData) {
+            success(imageData);
+        }, function(err) {
+            error(err);
+        });
+    };
+
+    return {
+        takePicture: takePicture
     }
 })
 
+/**
+ * -----------------------------------------------------------------------------
+ *  Description:    Native contacts manager
+ * -----------------------------------------------------------------------------
+ */
 .factory('contact', function ($cordovaContacts) {
 
-    return {
-        save: function (customer, success, error) {
-            if(!customer.mobile && !customer.phone && !customer.email) {
-                error();
-                return;
-            }
+    // 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: ''
+        var contact = {
+            name: {
+                givenName: customer.name,
+                familyName: '',
+                formatted: ''
+            },
+            nickname: '',
+            phoneNumbers: [
+                {
+                    value: customer.phone,
+                    type: 'phone'
                 },
-                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
-            };
+                {
+                    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);
-            });
-        }
+        $cordovaContacts.save(contact).then(function (result) {
+            success(result);
+        }, function (err) {
+            error(err);
+        });
+    };
+
+    return {
+        save: save
     }
 });

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 11
www/templates/sale/customer.html


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 11
www/templates/sale/customers.html


+ 0 - 10
www/templates/sale/leads.html

@@ -1,10 +0,0 @@
-<ion-view title="Iniciativas">
-
-    <ion-nav-buttons side="right">
-        <button class="button button-clear ion-plus-round" style="font-size:22px !important;" ng-click="show()"></i></button>
-    </ion-nav-buttons>
-
-    <ion-content>
-        
-    </ion-content>
-</ion-view>

+ 0 - 9
www/templates/sale/sales.html

@@ -1,9 +0,0 @@
-<ion-view title="Ventas">
-    <ion-content>
-        <ion-list>
-            <ion-item class="item-icon-left" ui-sref="app.customers"><i class="ion-person-stalker" style="font-size:22px"></i> Clientes</ion-item>
-            <ion-item class="item-icon-left" ui-sref="app.leads"><i class="ion-happy" style="font-size:22px"></i> Iniciativas</ion-item>
-            <ion-item class="item-icon-left"><i class="ion-star" style="font-size:22px"></i> Oportunidades</ion-item>
-        </ion-list>
-    </ion-content>
-</ion-view>

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است