configuration.controller.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. angular.module(
  2. 'odoo.configuration.controller',
  3. [
  4. 'odoo.interoperability.factory',
  5. 'odoo.storage.factory'
  6. ]
  7. )
  8. .controller('ConfigurationController', function($scope, $state, $ionicLoading, $ionicPopup, odoo, storage) {
  9. $scope.config = { host: '192.168.88.116', port: 8069, database: 'odoo', username: 'admin', password: 'admin' }
  10. // Apply configuration for app
  11. $scope.configure = function () {
  12. $ionicLoading.show();
  13. storage.count('user', function (total) {
  14. if (total == 0) {
  15. odoo.auth($scope.config, function (user) {
  16. storage.saveUser(
  17. [
  18. user.id,
  19. $scope.config.host,
  20. $scope.config.port,
  21. $scope.config.database,
  22. user.username,
  23. user.password
  24. ], function (newId) {
  25. $ionicLoading.hide();
  26. $state.go('app.main');
  27. console.log(newId);
  28. }, function (error) {
  29. $ionicLoading.hide();
  30. console.log(error);
  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. console.log(error);
  47. });
  48. }
  49. });