angular.module('odoo')

    /**
     *
     */
    .controller('ConfigurationController', function (
        $scope,
        $state,
        $ionicLoading,
        $ionicPopup,
        $localStorage,
        odooFactory,
        databaseFactory
    ) {
        $scope.loading = false;
        $scope.configuration = $localStorage.$default({
            host: '192.168.2.105',
            port: 8069,
            database: 'odoo',
            username: 'admin',
            password: 'admin',
            id: null
        });

        /**
         *
         */
        $scope.auth = function () {
            $scope.loading = true;

            odooFactory.auth(function (id) {
                $scope.configuration.id = id;

                databaseFactory.initTables(function (result) {
                    $scope.loading = false;
                    $state.go('app.main');
                }, function (err) {
                    $scope.loading = false;
                    console.log(err);
                });

            }, function (err) {
                $scope.loading = false;
                console.log(err);
            });
        }
    });
