var CommandUserForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

