var ListAnnonce = function(){};

/***
 * Init the form
 * @returns {undefined}
 */
ListAnnonce.Init = function(){

    console.log("TODO DETECTER ");

    Plugin.Register('CaracteristicPlugin', 'CaracteristicPlugin', function(){ CaracteristicPlugin.InitFilter(ListAnnonce.Filter); });


    Event.AddById("btnSave", "click", ListAnnonce.SaveElement);
};

ListAnnonce.Filter = function(caracteristiqueFilter){
    console.log("On filte les annonce. le caractertiso plug  ad donnes les filtres et leur valeu");

    let request = new Http("Annonce", "Search");
    request.SetData(caracteristiqueFilter);

    request.Post(function(data){

        console.log(data);

            

    });

};

/***
* Get the Id of element 
*/
ListAnnonce.GetId = function(){
    return Form.GetId("ListAnnonceForm");
};

/*
* Save the Element
*/
ListAnnonce.SaveElement = function(e){
   
    if(Form.IsValid("ListAnnonceForm"))
    {
    let request = new Http("ListAnnonce", "SaveElement");
        request.SetData(Form.Serialize("ListAnnonceForm"));

        request.Post(data => {

            data = JSON.parse(data);

            if(data.status == "error"){
                Form.RenderError("ListAnnonceForm", data.data.message);
            } else{

                Form.SetId("ListAnnonceForm", data.data.Id);
            }
        });
    }
};

