var CrmProspectForm = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

                Dialog.Close();
                Crm.ReloadProspect(data);

            }
        });
    }
};

