var ImmoCityForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

