var RewardGiftForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

