var AssoMemberForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("AssoMemberFormForm", data.data.Id);
                Asso.ReloadMember(data.data);    
                Dialog.Close();
            }
        });
    }
};

