controllers.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. angular.module('odoo.controllers', ['odoo.factories'])
  2. .controller('AppController', function ($scope) {
  3. console.log("I'm AppController");
  4. })
  5. .controller('MainController', function ($scope) {
  6. console.log("I'm MainController");
  7. })
  8. .controller('VentasController', function ($scope) {
  9. })
  10. .controller('CustomersController', function ($scope, $ionicLoading, $ionicPopup, odoo, storage) {
  11. $scope.customers = {};
  12. $scope.$on('$ionicView.enter', function () {
  13. $scope.fill();
  14. });
  15. // Fill view list
  16. $scope.fill = function () {
  17. $ionicLoading.show();
  18. storage.get('user', function (users) {
  19. if (users.length == 1) {
  20. var userConfig = users.item(0);
  21. odoo.fetch('res.partner', [[['customer', '=', true]]], userConfig, function (customers) {
  22. $ionicLoading.hide();
  23. $scope.customers = customers;
  24. $scope.$broadcast('scroll.refreshComplete');
  25. }, function (error) {
  26. $ionicLoading.hide();
  27. console.error(error);
  28. var message = 'Configuración no válida';
  29. if (angular.isObject(error)) {
  30. message = 'Credenciales no válidas';
  31. }
  32. $ionicPopup.alert({ title: 'No se pudo establecer una conexión al servidor', template: message });
  33. });
  34. } else {
  35. $ionicLoading.hide();
  36. $ionicPopup.alert({ title: 'Nada que hacer' });
  37. }
  38. }, function (error) {
  39. $ionicLoading.hide();
  40. console.error(error);
  41. $ionicPopup.alert({ title: 'Atención', template: 'No se pudo ejecutar la instrucción SQL' });
  42. });
  43. }
  44. $scope.showDetails = function() {
  45. console.log('showDetails');
  46. }
  47. $scope.showOptions = function () {
  48. console.log('showOptions');
  49. }
  50. })
  51. .controller('ConfigurationController', function($scope, $state, $ionicLoading, $ionicPopup, odoo, storage) {
  52. $scope.config = { host: '192.168.88.116', port: 8069, database: 'odoo', username: 'admin', password: 'admin' }
  53. // Apply configuration for app
  54. $scope.configure = function () {
  55. $ionicLoading.show();
  56. storage.count('user', function (total) {
  57. if (total == 0) {
  58. odoo.auth($scope.config, function (user) {
  59. storage.saveUser([user.id, $scope.config.host, $scope.config.port, $scope.config.database, user.username, user.password], function (newId) {
  60. $ionicLoading.hide();
  61. $state.go('app.main');
  62. console.log(newId);
  63. }, function (error) {
  64. $ionicLoading.hide();
  65. console.log(error);
  66. });
  67. }, function (error) {
  68. $ionicLoading.hide();
  69. var message = 'Configuración no válida';
  70. if (angular.isObject(error)) {
  71. message = 'No se pudo establecer una llamada al servidor';
  72. }
  73. $ionicPopup.alert({ title: 'Ha fallado el inicio de sesión', template: message });
  74. });
  75. } else {
  76. $ionicLoading.hide();
  77. $state.go('app.main');
  78. }
  79. }, function (error) {
  80. $ionicLoading.hide();
  81. console.log(error);
  82. });
  83. }
  84. });