/**
 * Created by DennysO on 6/27/2015.
 */
var Projects = {};

var notifyProjectComponents = function(id) {
    ////console.log(id);
    $(ProjectsEntity).trigger(id);
};

var ProjectsEntity = {
    doneLoading: false,
    getProjects: function() {
        return Projects;
    },
    getStudents: function() {
        return Projects;
    },
    get: function() {
        return Projects;
    },
    loadProjects: function() {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/getProjectsInfo",
            dataType: "json"
        });
        loadRequest.done(function(dataFromServer) {
            Projects = dataFromServer;
            notifyProjectComponents('ProjectsHasChanged');
        });
    },
    loadAllProjects: function() {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/getAll/projects",
            dataType: "json"
        });
        loadRequest.done(function(dataFromServer) {
            Projects = dataFromServer;
            notifyProjectComponents('GetAllProjects');
        });
    },
    loadStudents: function() {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/getProjectsSInfo",
            dataType: "json"
        });
        loadRequest.done(function(dataFromServer) {
            Projects = dataFromServer;
            notifyProjectComponents('StudentsHasChanged');
        });
    },
    loadProjectFilter: function(id) {
        var loadRequest = $.ajax({
            type: 'GET',
            url: "/api/getProjectFilter/"+id,
            dataType: "text"
        });
        loadRequest.done(function(dataFromServer) {
            Projects = dataFromServer;
            notifyProjectComponents('FilterHasChanged');
        });
    },
};