configuration.controller.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. angular.module('odoo')
  2. .controller('ConfigurationController', function (
  3. $scope,
  4. $state,
  5. $ionicLoading,
  6. $ionicPopup,
  7. userStorageFactory,
  8. odooFactory,
  9. sqlFactory
  10. ) {
  11. // $scope.config = { host: 'localhost', port: 8069, database: 'odoo', username: 'admin', password: 'admin' };
  12. $scope.config = { host: '192.168.2.106', port: 8069, database: 'odoo', username: 'admin', password: 'admin' };
  13. $scope.$on('ionicView.enter', function () {
  14. console.log('Evaluar usuario');
  15. });
  16. // Apply configuration for app
  17. $scope.configure = function () {
  18. $ionicLoading.show();
  19. sqlFactory.count('user', function (total) {
  20. if (total == 0) {
  21. odooFactory.auth($scope.config, function (user) {
  22. userStorageFactory.save(
  23. [
  24. user.id,
  25. $scope.config.host,
  26. $scope.config.port,
  27. $scope.config.database,
  28. user.username,
  29. user.password
  30. ], function (newId) {
  31. $ionicLoading.hide();
  32. $state.go('app.main');
  33. }, function (error) {
  34. $ionicLoading.hide();
  35. });
  36. }, function (error) {
  37. $ionicLoading.hide();
  38. var message = 'Configuración no válida';
  39. if (angular.isObject(error)) {
  40. message = 'No se pudo establecer una llamada al servidor';
  41. }
  42. $ionicPopup.alert({ title: 'Ha fallado el inicio de sesión', template: message });
  43. });
  44. } else {
  45. $ionicLoading.hide();
  46. $state.go('app.main');
  47. }
  48. }, function (error) {
  49. $ionicLoading.hide();
  50. });
  51. }
  52. });