var SeoForm = function(){};

/***
 * Initialise le formulaire
 * @returns {undefined}
 */
SeoForm.Init = function(){
   // Event.AddById("btnSave", "click", SeoForm.SaveElement);
    Event.AddById("btnAddPlugin", "click", SeoForm.AddPlugin);
    Event.AddByClass("removePlugin", "click" , SeoForm.RemovePlugin);
    
    SeoForm.RegisterPlugin();
};

/***
 * Registert the plugin
 * @returns {undefined}
 */
SeoForm.RegisterPlugin = function(){
    let pluginScript = Dom.GetById("pluginScript");
    
    if(pluginScript){
        eval(pluginScript.innerHTML);
    }
};

/***
* Obtient l'id de l'itin�raire courant 
*/
SeoForm.GetId = function(){
    return Form.GetId("SeoFormForm");
};

/*
* Sauvegare l'itineraire
*/
SeoForm.SaveElement = function(e){
   
    if(Form.IsValid("SeoFormForm"))
    {

    let data = "Class=Blog&Methode=SaveBlog&App=Blog";
        data +=  Form.Serialize("SeoFormForm");

        Request.Post("Ajax.php", data).then(data => {
            
            if(Form.GetValue("SeoFormForm", "Id") == ""){
                Dashboard.StartApp('', 'Seo', '');
            } else {
               Animation.Notify(Language.GetCode("Blog.BlogSaved"));
           }
        });
    }
};

/***
 * Ajout d'un plugin
 */
SeoForm.AddPlugin = function(e){
  
    e.preventDefault();
    
     Dialog.open('', {"title": Dashboard.GetCode("Blog.AddPlugin"),
     "app": "EeApp",
     "class": "DialogEeApp",
     "method": "AddPluginApp",
     "params": "Seo",
     "type" : "right"
     });
 };
 
 /***
  * Remove plugin to the shop 
  * @returns {undefined}
  */
 SeoForm.RemovePlugin = function(e){
     
     Animation.Confirm(Language.GetCode("Seo.ConfirmRemovePlugin"), 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);
         });
     });
 };
 