configuration.controller.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. angular.module('odoo')
  2. .controller('ConfigurationController', function (
  3. $scope,
  4. $state,
  5. $ionicLoading,
  6. $ionicPopup,
  7. userStorageFactory,
  8. odooInteroperabilityFactory,
  9. sqlFactory
  10. ) {
  11. $scope.config = { host: '192.168.43.170', 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. odooInteroperabilityFactory.auth($scope.config, function (user) {
  18. userStorageFactory.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. }, function (error) {
  30. $ionicLoading.hide();
  31. });
  32. }, function (error) {
  33. $ionicLoading.hide();
  34. var message = 'Configuración no válida';
  35. if (angular.isObject(error)) {
  36. message = 'No se pudo establecer una llamada al servidor';
  37. }
  38. $ionicPopup.alert({ title: 'Ha fallado el inicio de sesión', template: message });
  39. });
  40. } else {
  41. $ionicLoading.hide();
  42. $state.go('app.main');
  43. }
  44. }, function (error) {
  45. $ionicLoading.hide();
  46. });
  47. }
  48. });