angular.module('odoo') .controller('ConfigurationController', function ( $scope, $state, $ionicLoading, $ionicPopup, odoo, sqlFactory, userStorage ) { $scope.config = { host: '192.168.2.102', port: 8069, database: 'odoo', username: 'admin', password: 'admin' } // Apply configuration for app $scope.configure = function () { $ionicLoading.show(); sqlFactory.count('user', function (total) { if (total == 0) { odoo.auth($scope.config, function (user) { userStorage.save( [ user.id, $scope.config.host, $scope.config.port, $scope.config.database, user.username, user.password ], function (newId) { $ionicLoading.hide(); $state.go('app.main'); console.log(newId); }, function (error) { $ionicLoading.hide(); console.log(error); }); }, function (error) { $ionicLoading.hide(); var message = 'Configuración no válida'; if (angular.isObject(error)) { message = 'No se pudo establecer una llamada al servidor'; } $ionicPopup.alert({ title: 'Ha fallado el inicio de sesión', template: message }); }); } else { $ionicLoading.hide(); $state.go('app.main'); } }, function (error) { $ionicLoading.hide(); console.log(error); }); } });