summaryrefslogtreecommitdiffstats
path: root/scripts/client.js
blob: 8cef12a917d3bbfb17ce5f687be70f8c7a8dacc0 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var ioc = angular.module('ioc', []);

ioc.controller('ioctrl', function($scope) {
    var soc = io();
    var pw = 0;

    $scope.uid = 0;
    $scope.que = [];
    $scope.row = "";
    $scope.name = "";
    $scope.qsize = 0;
    $scope.outdated = true;
    $scope.error_message = "";

    $scope.submit = function() {
        if ($scope.row == "")
            $scope.error_message = "Valitse rivi ennen lisäämistä!";
        else if ($scope.name == "")
            $scope.error_message = "Kirjoita nimesi ennen lisäämistä!";
        else {
            soc.emit("queadd", {
                "row":  $scope.row,
                "name": $scope.name,
                "uid":  $scope.uid
            });
            $scope.error_message = "";
            $scope.row = "";
            $scope.name = "";
        }
    };

    soc.on("quedata", function(data) {
        $scope.que = data;
        $scope.qsize = data.length;
        $scope.outdated = false;
        $scope.$apply();
    });

    soc.on("userinfo", function(data) {
        $scope.uid = data.uid;
        pw = data.pw;
    });

    soc.on("disconnect", function(data) {
        setTimeout(function() {
            console.log("blblbl");
            $scope.uid = data.uid;
            pw = data.pw;
            $scope.$apply();
        }, 1000);
    });

    soc.on("err", function(err) {
        console.log("error! msg: " + err.msg);
    });

    $scope.popfirst = function() {
        $scope.outdated = true;
        soc.emit("quepopfirst", "");
    };

    $scope.querm = function(qid) {
        data = {
            "qid": qid,
            "pw":  pw
        };
        soc.emit("quedelete", data);
    };
});