var Students = {};
var NumLoaded = {};

var notifySComponents = function () {
    $(StudentForm).trigger('StudentHasChanged');
};

var notifyNumComponents = function () {
    $(StudentForm).trigger('StudentNumHasChanged');
};

var StudentForm = {

    doneLoading: false,
    getStudent: function () {
        return Student;
    },

    getNumStudent: function () {
        return NumLoaded;
    },

    loadStudents: function () {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/getStudentsInfo",
            dataType: "json"
        });
        loadRequest.done(function (dataFromServer) {
            Student = dataFromServer;
            notifySComponents();
        });
    },

    loadStudentsFromSPWS: function () {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/loadStudents",
            dataType: "json"
        });
        loadRequest.done(function (dataFromServer) {
            NumLoaded = dataFromServer;
            notifyNumComponents();
        });
    }
};