var AssoBudgetReceiptForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

