﻿require(["auth", "utils"],
function(auth, utils) {

    var valid = false;

    $(document).ready(function() {

        //by default
        $("#tab2").stop(false, false).show();

        $("#navigation li a").each(function(i) {
            $("#navigation li a:eq(" + i + ")").click(function() {
                var tab_id = i + 1;
                $("#content div").stop(false, false).hide();
                $("#tab" + tab_id).stop(false, false).show();
                return false;
            })
        })

        utils.postRequest(
            {
                "table": "events",
                "fields": ["id", "name"]
            },
            listEvents,
            "/handler/geteventlist"
        );

    });

    $("#register-btn").click(function() {
        if (valid == true) {
            auth.jsonHandle("register", auth.registerCallback);
        } else {
            $("#server-answer").text("Не все поля заполнены.").css("color", "red");
        }
    });

    $("#login-btn").click(function() {
        auth.jsonHandle("login", auth.loginCallback);
    });

    $("#logout-btn").click(function() {
        auth.jsonHandle("logout", auth.logoutCallback);
    });

    $("#cabinet-btn").click(function() {
        location.href = "/handler/showcabinet/users/";
    });

    $("#home-btn").click(function() {
        location.href = "/";
    });

    $("#fname, #lname, #pname").blur(function() {
        if ($(this).val() != "") {
            valid = true;
            $(this).css({"border": "2px solid green"});
        } else {
            valid = false;
            $(this).css({"border": "2px solid red"});
        }
    });

    function listEvents(data) {
        for (i in data["data"]) {
            var p = $("</p>", {});
            $(p).append($("<a/>", {
                text: data["data"][i]["name"],
                href: "/handler/getrequest/event/" + data["data"][i]["id"],
                class: "form-row",
            }));
            $(p).appendTo("div#list-events");
        }
    }

});

@@ -78,38 +78,617 @@
     
-$(document).ready(function() %7B
+function listEvents(data) %7B%0A        for (i in data%5B%22data%22%5D) %7B%0A            var p = $(%22%3C/p%3E%22, %7B%7D);%0A            $(p).append($(%22%3Ca/%3E%22, %7B%0A                text: data%5B%22data%22%5D%5Bi%5D%5B%22name%22%5D,%0A                href: %22/handler/getrequest/event/%22 + data%5B%22data%22%5D%5Bi%5D%5B%22id%22%5D,%0A                class: %22form-row%22,%0A            %7D));%0A            $(p).appendTo(%22div#list-events%22);%0A        %7D%0A    %7D%0A%0A    $(document).ready(function() %7B%0A%0A        utils.postRequest(%0A            %7B%0A                %22table%22: %22events%22,%0A                %22fields%22: %5B%22id%22, %22name%22%5D%0A            %7D,%0A            listEvents,%0A            %22/handler/geteventlist%22%0A        );
 %0A%0A  
@@ -1089,212 +1089,8 @@
 %7D)%0A%0A
-        utils.postRequest(%0A            %7B%0A                %22table%22: %22events%22,%0A                %22fields%22: %5B%22id%22, %22name%22%5D%0A            %7D,%0A            listEvents,%0A            %22/handler/geteventlist%22%0A        );%0A%0A
     
@@ -2004,32 +2004,32 @@
 d%22%7D);%0A        %7D%0A
+
     %7D);%0A%0A    fun
@@ -2025,383 +2025,8 @@
 );%0A%0A
-    function listEvents(data) %7B%0A        for (i in data%5B%22data%22%5D) %7B%0A            var p = $(%22%3C/p%3E%22, %7B%7D);%0A            $(p).append($(%22%3Ca/%3E%22, %7B%0A                text: data%5B%22data%22%5D%5Bi%5D%5B%22name%22%5D,%0A                href: %22/handler/getrequest/event/%22 + data%5B%22data%22%5D%5Bi%5D%5B%22id%22%5D,%0A                class: %22form-row%22,%0A            %7D));%0A            $(p).appendTo(%22div#list-events%22);%0A        %7D%0A    %7D%0A%0A
 %7D);%0A

Fix main.js