var CoursesOrganizerForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

