|
@@ -1,192 +1,197 @@
|
|
|
angular.module('odoo')
|
|
|
|
|
|
-.controller('CustomersController', function (
|
|
|
- $scope,
|
|
|
- $ionicModal,
|
|
|
- $ionicActionSheet,
|
|
|
- $ionicPopup,
|
|
|
- customersRemoteFactory,
|
|
|
- customersStorageFactory,
|
|
|
- sqlFactory,
|
|
|
- cameraFactory,
|
|
|
- contactFactory
|
|
|
-) {
|
|
|
- $scope.loading = false;
|
|
|
- $scope.customers = [];
|
|
|
- $scope.customer = {};
|
|
|
-
|
|
|
- $ionicModal.fromTemplateUrl('templates/sales/customer.html', {
|
|
|
- scope: $scope,
|
|
|
- animation: 'slide-in-up'
|
|
|
- }).then(function(modal) {
|
|
|
- $scope.customerModal = modal;
|
|
|
- });
|
|
|
+ .controller('CustomersController', function (
|
|
|
+ $scope,
|
|
|
+ $ionicModal,
|
|
|
+ $ionicActionSheet,
|
|
|
+ $ionicPopup,
|
|
|
+ customersRemoteFactory,
|
|
|
+ customersStorageFactory,
|
|
|
+ sqlFactory,
|
|
|
+ cameraFactory,
|
|
|
+ contactFactory
|
|
|
+ ) {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.customers = [];
|
|
|
+ $scope.customer = {};
|
|
|
|
|
|
- $scope.$on('$ionicView.enter', function () {
|
|
|
- $scope.fill();
|
|
|
- });
|
|
|
+ $ionicModal.fromTemplateUrl('templates/sales/customer.html', {
|
|
|
+ scope: $scope,
|
|
|
+ animation: 'slide-in-up'
|
|
|
+ }).then(function (modal) {
|
|
|
+ $scope.customerModal = modal;
|
|
|
+ });
|
|
|
|
|
|
- $scope.$on('$destroy', function() {
|
|
|
- $scope.customerModal.remove();
|
|
|
- });
|
|
|
+ $scope.$on('$ionicView.enter', function () {
|
|
|
+ $scope.fill();
|
|
|
+ });
|
|
|
|
|
|
- $scope.$on('modal.hidden', function() {
|
|
|
- $scope.customer = {};
|
|
|
- });
|
|
|
+ $scope.$on('$destroy', function () {
|
|
|
+ $scope.customerModal.remove();
|
|
|
+ });
|
|
|
|
|
|
- // Fill view list from data readed from local database
|
|
|
- $scope.fill = function (refresh = false) {
|
|
|
- $scope.loading = !refresh;
|
|
|
+ $scope.$on('modal.hidden', function () {
|
|
|
+ $scope.customer = {};
|
|
|
+ });
|
|
|
|
|
|
- customersRemoteFactory.sync(function (customers) {
|
|
|
- console.log('Customers sync correctly and receive ' + customers.length + ' items');
|
|
|
+ // Fill view list from data readed from local database
|
|
|
+ $scope.fill = function (refresh = false) {
|
|
|
+ $scope.loading = !refresh;
|
|
|
|
|
|
- $scope.getCustomers(function () {
|
|
|
- $scope.$broadcast('scroll.refreshComplete');
|
|
|
- $scope.loading = false;
|
|
|
- }, function (getCustomersError) {
|
|
|
- $scope.$broadcast('scroll.refreshComplete');
|
|
|
- $scope.loading = false;
|
|
|
+ customersRemoteFactory.sync(function (customers) {
|
|
|
+ console.log('Customers sync correctly and receive ' + customers.length + ' items');
|
|
|
|
|
|
- $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
|
|
|
- });
|
|
|
- }, function (syncErr) {
|
|
|
+ $scope.getCustomers(function () {
|
|
|
+ $scope.$broadcast('scroll.refreshComplete');
|
|
|
+ $scope.loading = false;
|
|
|
+ }, function (getCustomersError) {
|
|
|
+ console.log(getCustomersError);
|
|
|
|
|
|
- $scope.getCustomers(function () {
|
|
|
- $scope.$broadcast('scroll.refreshComplete');
|
|
|
- $scope.loading = false;
|
|
|
- }, function (getCustomersError) {
|
|
|
- $scope.$broadcast('scroll.refreshComplete');
|
|
|
- $scope.loading = false;
|
|
|
+ $scope.$broadcast('scroll.refreshComplete');
|
|
|
+ $scope.loading = false;
|
|
|
|
|
|
- $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
|
|
|
+ $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
|
|
|
+ });
|
|
|
+ }, function (syncErr) {
|
|
|
+ console.log(syncErr);
|
|
|
+
|
|
|
+ $scope.getCustomers(function () {
|
|
|
+ $scope.$broadcast('scroll.refreshComplete');
|
|
|
+ $scope.loading = false;
|
|
|
+ }, function (getCustomersError) {
|
|
|
+ console.log(getCustomersError);
|
|
|
+
|
|
|
+ $scope.$broadcast('scroll.refreshComplete');
|
|
|
+ $scope.loading = false;
|
|
|
+
|
|
|
+ $ionicPopup.alert({ title: 'No se pudo obtener los clientes' });
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Get filtered customers for correct data visualization
|
|
|
- $scope.getCustomers = function (success, error) {
|
|
|
- sqlFactory.selectByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
|
|
|
- $scope.customers = [];
|
|
|
+ }
|
|
|
|
|
|
- for (var i = 0; i < customers.length; i++) {
|
|
|
- $scope.customers.push(customers.item(i));
|
|
|
- }
|
|
|
+ // Get filtered customers for correct data visualization
|
|
|
+ $scope.getCustomers = function (success, error) {
|
|
|
+ sqlFactory.selectByConstraint('partner', 'customer = 1 AND modified != 2', function (customers) {
|
|
|
+ $scope.customers = [];
|
|
|
|
|
|
- $scope.$apply();
|
|
|
- success();
|
|
|
- }, function (customerGetByConstraintError) {
|
|
|
- error(customerGetByConstraintError);
|
|
|
- });
|
|
|
- }
|
|
|
+ for (var i = 0; i < customers.length; i++) {
|
|
|
+ $scope.customers.push(customers.item(i));
|
|
|
+ }
|
|
|
|
|
|
- // Show action sheet for customer options
|
|
|
- $scope.openOptions = function(index) {
|
|
|
- if (index == -1) {
|
|
|
- $scope.customer = {};
|
|
|
- } else {
|
|
|
- $scope.customer = $scope.customers[index];
|
|
|
+ $scope.$apply();
|
|
|
+ success();
|
|
|
+ }, function (customerGetByConstraintError) {
|
|
|
+ error(customerGetByConstraintError);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- console.log('Customer selected => ' + JSON.stringify($scope.customer));
|
|
|
+ // Show action sheet for customer options
|
|
|
+ $scope.openOptions = function (index) {
|
|
|
+ if (index == -1) {
|
|
|
+ $scope.customer = {};
|
|
|
+ } else {
|
|
|
+ $scope.customer = $scope.customers[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('Customer selected => ' + JSON.stringify($scope.customer));
|
|
|
|
|
|
- $ionicActionSheet.show({
|
|
|
- titleText: 'Acciones',
|
|
|
- buttons: [
|
|
|
- {
|
|
|
- text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
|
|
|
+ $ionicActionSheet.show({
|
|
|
+ titleText: 'Acciones',
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
|
|
|
+ cancel: function () {
|
|
|
+ $scope.customer = {};
|
|
|
+ console.log('ActionSheet canceled');
|
|
|
+ },
|
|
|
+ buttonClicked: function (index) {
|
|
|
+ switch (index) {
|
|
|
+ case 0:
|
|
|
+ $scope.show();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ $scope.addContact();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $scope.show();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
},
|
|
|
- {
|
|
|
- text: '<i class="icon ion-archive positive"></i> Agregar a contactos'
|
|
|
+ destructiveButtonClicked: function () {
|
|
|
+ $scope.delete();
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
- ],
|
|
|
- destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
|
|
|
- cancel: function() {
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save a customer data on local database
|
|
|
+ $scope.save = function () {
|
|
|
+ customersStorageFactory.save($scope.customer, function (customerId) {
|
|
|
+ if (!$scope.customer.id) {
|
|
|
+ $scope.customer.id = customerId;
|
|
|
+ $scope.customers.push($scope.customer);
|
|
|
+ }
|
|
|
+
|
|
|
$scope.customer = {};
|
|
|
- console.log('ActionSheet canceled');
|
|
|
- },
|
|
|
- buttonClicked: function(index) {
|
|
|
- switch (index) {
|
|
|
- case 0:
|
|
|
- $scope.show();
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- $scope.addContact();
|
|
|
- break;
|
|
|
- default:
|
|
|
- $scope.show();
|
|
|
+ $scope.customerModal.hide();
|
|
|
+ console.log('Customer saved');
|
|
|
+ }, function (error) {
|
|
|
+ $ionicPopup.alert({ title: 'No se ha podido guardar el cliente', template: JSON.stringify(error) });
|
|
|
+ console.log(JSON.stringify(error));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Delete a customer from local database
|
|
|
+ $scope.delete = function () {
|
|
|
+ $ionicPopup.confirm({
|
|
|
+ title: 'Confirmar',
|
|
|
+ template: 'Estás seguro que quieres eliminar este cliente?'
|
|
|
+ }).then(function (confirmation) {
|
|
|
+ if (confirmation) {
|
|
|
+ customersStorageFactory.remove($scope.customer, function (affected) {
|
|
|
+ if (affected != 0) {
|
|
|
+ var index = $scope.customers.indexOf($scope.customer);
|
|
|
+ $scope.customers.splice(index, 1);
|
|
|
+ $scope.customer = {};
|
|
|
+
|
|
|
+ $scope.$apply();
|
|
|
+ }
|
|
|
+ }, function (error) {
|
|
|
+ $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
|
|
|
+ console.log(JSON.stringify(error));
|
|
|
+ });
|
|
|
}
|
|
|
- return true;
|
|
|
- },
|
|
|
- destructiveButtonClicked: function() {
|
|
|
- $scope.delete();
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Save a customer data on local database
|
|
|
- $scope.save = function() {
|
|
|
- customersStorageFactory.save($scope.customer, function (customerId) {
|
|
|
- if (!$scope.customer.id) {
|
|
|
- $scope.customer.id = customerId;
|
|
|
- $scope.customers.push($scope.customer);
|
|
|
- }
|
|
|
+ // Show customer data in modal
|
|
|
+ $scope.show = function () {
|
|
|
+ $scope.customerModal.show();
|
|
|
+ }
|
|
|
|
|
|
- $scope.customer = {};
|
|
|
- $scope.customerModal.hide();
|
|
|
- console.log('Customer saved');
|
|
|
- }, function (error) {
|
|
|
- $ionicPopup.alert({ title: 'No se ha podido guardar el cliente', template: JSON.stringify(error) });
|
|
|
- console.log(JSON.stringify(error));
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Delete a customer from local database
|
|
|
- $scope.delete = function () {
|
|
|
- $ionicPopup.confirm({
|
|
|
- title: 'Confirmar',
|
|
|
- template: 'Estás seguro que quieres eliminar este cliente?'
|
|
|
- }).then(function (confirmation) {
|
|
|
- if(confirmation) {
|
|
|
- customersStorageFactory.remove($scope.customer, function (affected) {
|
|
|
- if (affected != 0) {
|
|
|
- var index = $scope.customers.indexOf($scope.customer);
|
|
|
- $scope.customers.splice(index, 1);
|
|
|
- $scope.customer = {};
|
|
|
-
|
|
|
- $scope.$apply();
|
|
|
- }
|
|
|
- }, function (error) {
|
|
|
- $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
|
|
|
- console.log(JSON.stringify(error));
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Show customer data in modal
|
|
|
- $scope.show = function () {
|
|
|
- $scope.customerModal.show();
|
|
|
- }
|
|
|
-
|
|
|
- // Take a picture from camera for customer profile
|
|
|
- $scope.takePicture = function () {
|
|
|
- cameraFactory.takePicture(function (imageData) {
|
|
|
- $scope.customer.image_small = imageData;
|
|
|
- $scope.customer.image_medium = imageData;
|
|
|
- }, function (error) {
|
|
|
- console.log(error);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Add customer data contact to device mobile contacts
|
|
|
- $scope.addContact = function () {
|
|
|
- contactFactory.save($scope.customer, function (result) {
|
|
|
- $ionicPopup.alert({ title: 'Contacto guardado' });
|
|
|
- }, function (error) {
|
|
|
- console.log(error);
|
|
|
- })
|
|
|
- }
|
|
|
-});
|
|
|
+ // Take a picture from camera for customer profile
|
|
|
+ $scope.takePicture = function () {
|
|
|
+ cameraFactory.takePicture(function (imageData) {
|
|
|
+ $scope.customer.image_small = imageData;
|
|
|
+ $scope.customer.image_medium = imageData;
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add customer data contact to device mobile contacts
|
|
|
+ $scope.addContact = function () {
|
|
|
+ contactFactory.save($scope.customer, function (result) {
|
|
|
+ $ionicPopup.alert({ title: 'Contacto guardado' });
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|