var EstimationCityForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

