123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- angular.module('odoo.controllers', ['odoo.factories'])
- .controller('AppController', function ($scope) {
- console.log("I'm AppController");
- })
- .controller('MainController', function ($scope) {
- console.log("I'm MainController");
- })
- .controller('VentasController', function ($scope) {
- })
- .controller('CustomersController', function ($scope, $ionicLoading, $ionicPopup, odoo, storage) {
- $scope.customers = {};
- $scope.$on('$ionicView.enter', function () {
- $scope.fill();
- });
- // Fill view list
- $scope.fill = function () {
- $ionicLoading.show();
- storage.get('user', function (users) {
- if (users.length == 1) {
- var userConfig = users.item(0);
- odoo.fetch('res.partner', [[['customer', '=', true]]], userConfig, function (customers) {
- $ionicLoading.hide();
- $scope.customers = customers;
- $scope.$broadcast('scroll.refreshComplete');
- }, function (error) {
- $ionicLoading.hide();
- console.error(error);
- var message = 'Configuración no válida';
- if (angular.isObject(error)) {
- message = 'Credenciales no válidas';
- }
- $ionicPopup.alert({ title: 'No se pudo establecer una conexión al servidor', template: message });
- });
- } else {
- $ionicLoading.hide();
- $ionicPopup.alert({ title: 'Nada que hacer' });
- }
- }, function (error) {
- $ionicLoading.hide();
- console.error(error);
- $ionicPopup.alert({ title: 'Atención', template: 'No se pudo ejecutar la instrucción SQL' });
- });
- }
- $scope.showDetails = function() {
- console.log('showDetails');
- }
- $scope.showOptions = function () {
- console.log('showOptions');
- }
- })
- .controller('ConfigurationController', function($scope, $state, $ionicLoading, $ionicPopup, odoo, storage) {
- $scope.config = { host: '192.168.88.116', port: 8069, database: 'odoo', username: 'admin', password: 'admin' }
- // Apply configuration for app
- $scope.configure = function () {
- $ionicLoading.show();
- storage.count('user', function (total) {
- if (total == 0) {
- odoo.auth($scope.config, function (user) {
- storage.saveUser([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);
- });
- }
- });
|