summaryrefslogtreecommitdiffstats
path: root/src/main/resources/controllers/groupFieldController.js
blob: ce8085475fa5f18b4acdd75f623fb7819d560d2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
angular.module('group').controller('groupFieldController', ['$scope', function groupFieldController($scope) {

    $scope.data = { id: 0, password: '', resolution: window.innerWidth + 'x' + window.innerHeight };

    $scope.$watch('data', function(newValue) {
        if (window.location.hash !== '#/') {
            window.location.hash = '#/';
            window.location.reload();
        }
        $scope.model = JSON.stringify(newValue);
    }, true);

    $scope.selectGroup = function selectGroup($event, id) {
        if (angular.element($event.target).hasClass('bwlp-password-input')) return;
        $scope.data.password = '';
        if ($scope.data.id === id) {
            $scope.data.id = 0;
            angular.element('.selected-group').removeClass('selected-group');
            return;
        }
        $scope.data.id = id;
        angular.element('.selected-group').removeClass('selected-group');
        angular.element($event.currentTarget).addClass('selected-group');
    };

    $scope.logout = function logout() {
        window.localStorage.removeItem('GUAC_AUTH');
        window.location.hash = '#/';
        window.location.reload();
    }

}]);