var ImmoProjectEventForm = function(){};

/***
 * Init the form
 * @returns {undefined}
 */
ImmoProjectEventForm.Init = function(){
    Event.AddById("btnSaveEventProject", "click", ImmoProjectEventForm.SaveElement);
};

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

               Immo.ReloadProject(data.data);    
               Dialog.Close();
            }
        });
    }
};