var DownloadManagerCategoryForm = function(){};

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

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

/*
* Save the Element
*/
DownloadManagerCategoryForm.SaveElement = function(e){
   
    if(Form.IsValid("DownloadManagerCategoryFormForm"))
    {
    let request = new Http("DownloadManager", "SaveCategory");
        request.SetData(Form.Serialize("DownloadManagerCategoryFormForm"));

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("DownloadManagerCategoryFormForm", data.data.Id);
            }
        });
    }
};

