'use strict';

angular.module('fehlerberichtApp')
    .controller('CustomersCtrl', function ($scope, $http) {
        var webservice = 'db.php?';

        $scope.info = [];
        $scope.error = -1;

        $scope.domain = {
            'aktiv': {
                '1': 'Aktiv',
                '0': 'Inaktiv'
            },
            'system': [
                '?',
				'ARI',
                'AUDEV',
				'AUTOLINE',
				'CARLO',
				'HS',
				'LOCOSOFT',
				'NAVISION',
				'OPTIMA',
				'WERWISO',
				'Autosys',
				'Filaks',
				'O21-Light'
            ],
			'sys': {
                '?': '?',
				'ARI': 'AI',
                'AUDEV_CARIT': 'AC',
				'AUTOLINE': 'AL',
				'CARLO': 'C',
				'HS': 'HS',
				'LOCOSOFT': 'LO',
				'NAVISION': 'NV',
				'OPTIMA': 'O',
				'WERWISO': 'W',
				'Autosys': 'AS',
				'Filaks': 'F',
				'Optima-Light': 'OL'
            },
            'woche': [
                'Mo-Fr',
                'Mo-Sa',
                'Mo-So',
                'Di-So'
            ],
            'bundesland': {
                'AT': 'Österreich',
                'BW': 'Baden-Württemberg',
                'BY': 'Bayern',
                'BE': 'Berlin',
                'BB': 'Brandenburg',
                'HB': 'Bremen',
                'HH': 'Hamburg',
                'HE': 'Hessen',
                'MV': 'Mecklenburg-Vorpommern',
                'NI': 'Niedersachsen',
                'NW': 'Nordrhein-Westfalen',
                'RP': 'Rheinland-Pfalz',
                'SL': 'Saarland',
                'SN': 'Sachsen',
                'ST': 'Sachsen-Anhalt',
                'SH': 'Schleswig-Holstein',
                'TH': 'Thüringen'
            }
        };

        $scope.kunden = [];
        $scope.aworkKunden = [];

        $scope.current = {
            'zeile' : {},
            'fehler': {}
        };

        $scope.Filter = {
            'aktiv': '1',
            'kunde': '',
            'system': ''
        };

        $scope.removeItem = function (index) {
            // Beispiel
            $scope.Bestellungen = $scope.Bestellungen.splice(index, 1);
        };

        $scope.refresh = function () {
            $http.get(webservice + 'a=kunden').success(function (data) {
                $scope.kunden = data;
            });

            $http.get(webservice + 'a=awork_projekte').success(function (data) {
                $scope.aworkKunden = data.kunden;
            });
        };

        $scope.refresh();

        $scope.firstChar = function (t) {
            if (t === '') {
                return '?';
            }
            return t.substring(0, 1);
        };

        $scope.save = function () {
            $http.put(webservice + 'a=kunden', $scope.kunden).success(function (data) {
                $scope.kunden = data;
            });
        };
    });