var OneProductWidget = function(){};

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

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

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

        request.Post(data => {

            data = JSON.parse(data);

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

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

