var AssoBudgetExpenseForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("AssoBudgetExpenseFormForm", data.data.Id);
                Asso.ReloadReceipt(data.data);    
                Dialog.Close();
            }
        });
    }
};

