var RewardForm = function(){};

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

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

/*
* Save the Element
*/
RewardForm.SaveElement = function(e){
   
    if(Form.IsValid("RewardFormForm"))
    {
    let request = new Http("Reward", "SaveReward");
        request.SetData(Form.Serialize("RewardFormForm"));

        request.Post(data => {

            data = JSON.parse(data);

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

                Reward.ReloadReward(data);
                Dialog.Close();
            }
        });
    }
};

