var AssoMemberShipForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("AssoMemberShipFormForm", data.data.Id);
                Asso.ReloadMemberShip(data.data);    
                Dialog.Close();
            }
        });
    }
};

