var Profil = function() {};

    /*
    * Chargement de l'application
    */
    Profil.Load = function(parameter)
    {
        this.LoadEvent();
        Profil.InitTabUser();

        Event.AddById("btnAddPlugin", "click",     Profil.AddPlugin);
        Event.AddByClass("removePlugin", "click" , Profil.RemovePlugin);

        let SkillPluginContainer = document.getElementById("SkillPlugin");

        if(SkillPluginContainer != ""){
               eval(SkillPluginContainer.innerHTML); 
        }

        let CaracteristicPluginContainer = document.getElementById("CaracteristicPlugin");

        if(CaracteristicPluginContainer != ""){
               eval(CaracteristicPluginContainer.innerHTML); 
        }
        
        let DocumentPluginContainer = document.getElementById("DocumentPlugin");

        if(DocumentPluginContainer != ""){
               eval(DocumentPluginContainer.innerHTML); 
        }
        
    };
    
    
    /***
     * Load the Member 
     * @param {type} parameter
     * @returns {undefined}
     */
    Profil.LoadMember = function(parameter)
    {
        ProfilForm.Init();
        
        let SkillPluginContainer = document.getElementById("SkillPlugin");

        if(SkillPluginContainer){
            eval(SkillPluginContainer.innerHTML); 
        }

        let CaracteristicPluginContainer = document.getElementById("CaracteristicPlugin");

        if(CaracteristicPluginContainer != ""){
            eval(CaracteristicPluginContainer.innerHTML); 
        }

        let DocumentPluginContainer = document.getElementById("DocumentPlugin");

        if(DocumentPluginContainer != ""){
            eval(DocumentPluginContainer.innerHTML); 
        }

        let UserAdressPluginContainer = document.getElementById("UserAdressPlugin");

        if(UserAdressPluginContainer){
               eval(UserAdressPluginContainer.innerHTML); 
        }
    };

    /*
    * Chargement des �venements
    */
    Profil.LoadEvent = function()
    {
        Dashboard.AddEventAppMenu(Profil.Execute, "", "Profil");
        Dashboard.AddEventWindowsTool("Profil");
    };

/*
    * Execute une fonction
    */
    Profil.Execute = function(e)
    {
        //Appel de la fonction
        Dashboard.Execute(this, e, "Profil");
        return false;
    };

    /*
    *	Affichage de commentaire
    */
    Profil.Comment = function()
    {
        Dashboard.Comment("Profil", "1");
    };

    /*
    *	Affichage de a propos
    */
    Profil.About = function()
    {
        Dashboard.About("Profil");
    };

    /*
    *	Affichage de l'aide
    */
    Profil.Help = function()
    {
        Dashboard.OpenBrowser("Profil","{$BaseUrl}/Help-App-Profil.html");
    };

    /*
    *	Affichage de report de bug
    */
    Profil.ReportBug = function()
    {
        Dashboard.ReportBug("Profil");
    };

    /*
    * Fermeture
    */
    Profil.Quit = function()
    {
        Dashboard.CloseApp("","Profil");
    };

    // Evenement
    ProfilAction = function(){};

    /**
     * Charge les informations du profil
     */
    ProfilAction.LoadInformation = function()
    {
        var data = "Class=Profil&Methode=LoadInformation&App=Profil";
        Dashboard.LoadControl("dvDesktop", data, "" , "div", "Profil");
    };

    /**
     * Charge les compétences du profil
     */
    ProfilAction.LoadCompetence = function()
    {
        var data = "Class=Profil&Methode=LoadCompetence&App=Profil";
        Dashboard.LoadControl("dvDesktop", data, "" , "div", "Profil");
    };

    /*
     * Load Administration
     */
    ProfilAction.LoadAdmin = function()
    {
        var data = "Class=Profil&Methode=LoadAdmin&App=Profil";
        Dashboard.LoadControl("dvDesktop", data, "" , "div", "Profil");
    };
    
    /**
     * Sauvagarde les compétences de l'utilisateur
     */
    ProfilAction.SaveCompetence = function()
    {
        //Recuperation des controles
        var dvCompetenceUser = document.getElementById("dvCompetenceUser");

        var controls = dvCompetenceUser.getElementsByTagName("input");
        idCompetences = Array();

        for(i=0; i < controls.length; i++)
        {
            if(controls[i].type == "checkbox" && controls[i].checked )
            {
                idCompetences.push(controls[i].id);
            }
        }

         var data = "Class=Profil&Methode=SaveCompetence&App=Profil";
             data += "&competenceId=" + idCompetences.join(";");

        Dashboard.LoadControl("dvDesktop", data, "" , "div", "Profil");
    };
    
    /*
     * Add Category
     */
    ProfilAction.ShowAddCategory = function(categoryId)
    {
        var param = Array();
        param['App'] = 'Profil';
        param['Title'] = 'Profil.ShowAddCategory';
        
        if(categoryId != undefined)
        {
            param["entityId"] = categoryId;
        }

        Dashboard.OpenPopUp('Profil','ShowAddCategory', '','','', 'ProfilAction.RefreshTabCategory()', serialization.Encode(param));
    };
    
    /*
     * Refresh list Category
     */
    ProfilAction.RefreshTabCategory = function()
    {
        var data = "Class=Profil&Methode=GetTabCategory&App=Profil";
            Dashboard.LoadControl("dvCategory", data, "" , "div", "Profil");
    };
    
    /*
     * Add Competence
     */
    ProfilAction.ShowAddCompetence = function(competenceId)
    {
        var param = Array();
        param['App'] = 'Profil';
        param['Title'] = 'Profil.ShowAddCompetence';
        
        if(competenceId != undefined)
        {
            param["entityId"] = competenceId;
        }

        Dashboard.OpenPopUp('Profil','ShowAddCompetence', '','','', 'ProfilAction.RefreshTabCompetence()', serialization.Encode(param));
    };
    
    /*
     * Refresh list Competence
     */
    ProfilAction.RefreshTabCompetence = function()
    {
        var data = "Class=Profil&Methode=GetTabCompetence&App=Profil";
            Dashboard.LoadControl("dvCompetence", data, "" , "div", "Profil");
    };
    
    
    Profil.Init = function(){
        
    };
    
    /***
     * Init User Tab
     * @returns {undefined}
     */
    Profil.InitTabUser = function(){
        EntityGrid.Init("gdUser");
    };
    
    /***
     * Edition d'un utilisateur
     * @returns {undefined}
     */
    Profil.EditUser = function(userId){
        Dialog.open('', {"title": Dashboard.GetCode("Profil.EditUser"),
        "app": "Profil",
        "class": "DialogAdminProfil",
        "method": "EditUser",
        "params": userId
    });
    };
    
    /**
     * Refresh trh user Tab
     * @returns {undefined}
     */
    Profil.ReloadUser = function(){
        let gdUser = Dom.GetById("gdUser");
        
        if(gdUser){        
        let data = "Class=Admin&Methode=GetTabUser&App=Profil";
        
            Request.Post("Ajax.php", data).then(data => {
                gdUser.parentNode.innerHTML = data;
                Profil.InitTabUser();

                Dialog.Close();
            });
        }   
    };
    
    /***
     * Edit
     * @returns {undefined}
     */
    Profil.InitAdminWidget = function(e){
        
        Event.AddByClass("editProfil", "click", function(e){
          let UserId = e.srcElement.id;
            Profil.EditUser(UserId);
        });
    };

    /***
 * Ajout d'un plugin
 */
Profil.AddPlugin = function(e){
  
    e.preventDefault();
    
     Dialog.open('', {"title": Dashboard.GetCode("Profil.AddPlugin"),
     "app": "EeApp",
     "class": "DialogEeApp",
     "method": "AddPluginApp",
     "params": "Profil",
     "type" : "right"
     });
 };
 
 /***
  * Remove plugin to the shop 
  * @returns {undefined}
  */
 Profil.RemovePlugin = function(e){
     
     Animation.Confirm(Language.GetCode("Profil.RemovePlugin"), function(){
         let container = e.srcElement.parentNode;
         
         let  data = "Class=EeApp&Methode=RemovePluginApp&App=EeApp";
              data += "&pluginId="+e.srcElement.id;
              
         Request.Post("Ajax.php", data).then(data => {
             container.parentNode.removeChild(container);
         });
     });
 };
 
/***
 * Refresh 
 * @returns {undefined}
 */
Profil.RefreshPlugin = function(){
    Dashboard.StartApp("", "Profil", "");
};
     