var NewMessageForm = function(){};

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

    NewMessageForm.txtEditor = new TextRichEditor( Dom.GetById("Message"));
};

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

/*
* Save the Element
*/
NewMessageForm.SaveElement = function(e){
   
    Animation.AddLoading("NewMessageFormForm");
    Animation.Hide("NewMessageFormForm");

    if(Form.IsValid("NewMessageFormForm"))
    {
     
        let request = new Http("Forum", "NewMessage");
        request.SetData(Form.Serialize("NewMessageFormForm"));

        request.Post(data => {

            Animation.RemoveLoading("NewMessageFormForm");
            Animation.Show("NewMessageFormForm");
     
            data = JSON.parse(data);

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

                Animation.Load("NewMessageFormForm", Language.GetCode("Forum.MessageAdded"));
            }
        });
    }
};