var AssoEquipmentForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("AssoEquipmentFormForm", data.data.Id);
                Asso.ReloadEquipment(data.data);    
                Dialog.Close();
            }
        });
    }
};

