var CoursesCourForm = function(){};

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

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

/*
* Save the Element
*/
CoursesCourForm.SaveElement = function(e){
   
    if(Form.IsValid("CoursesCourFormForm"))
    {
    let request = new Http("Courses", "SaveCour");
        request.SetData(Form.Serialize("CoursesCourFormForm"));

        request.Post(data => {

            data = JSON.parse(data);

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

                Form.SetId("CoursesCourFormForm", data.data.Id);

                Dialog.Close();
                Courses.ReloadCour(data);
            }
        });
    }
};

