configuration.controller.js 1.8 KB

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