configuration.controller.js 1.8 KB

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