var CalendarEventUserForm = function(){};

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

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

/*
* Save the Element
*/
CalendarEventUserForm.SaveElement = function(e){
   
    if(Form.IsValid("CalendarEventUserFormForm"))
    {
    Animation.Hide("CalendarEventUserFormForm");
    Animation.AddLoading("CalendarEventUserFormForm");
        
    let request = new Http("Calendar", "AddUserEvent");
    
        request.SetData(Form.Serialize("CalendarEventUserFormForm"));

        request.Post(data => {

            Animation.RemoveLoading("CalendarEventUserFormForm");
            
            data = JSON.parse(data);
           
            if(data.status == "error"){
                Animation.Show("CalendarEventUserFormForm");
            
                Animation.Notify(data.data.error);
            } else { 

                Animation.Notify(Language.GetCode("Calendar.UserEventAdded"));
            }
        });
    }
};

