var estimation = function () {};

/*
 * Add Event when the App loaded
 */
estimation.Load = function (parameter)
{
    this.LoadEvent();
        
    estimation.InitTabCity();
};

/*
 * Add event
 */
estimation.LoadEvent = function ()
{
    Dashboard.AddEventAppMenu(estimation.Execute, "", "estimation");
    Dashboard.AddEventWindowsTool("estimation");
};

/***
 * Start the Event for Member 
 */
estimation.LoadMember = function () {
};

/*
 * Execute a function
 */
estimation.Execute = function (e)
{
    //Call the function
    Dashboard.Execute(this, e, "estimation");
    return false;
};

/***
 * Init the app front page
 */
estimation.Init = function (app, method) {
    if (app == "estimation") {
        switch (method) {
            default :
                break;
        }
    }
};

/***
 * Init the Admin Widget
 */
estimation.InitAdminWidget = function () {

};


/*
 * Init the Event for tabCity 
 */
estimation.InitTabCity = function(){
     //Catégory
    Event.AddById("btnAddCity", "click", () => {
        estimation.ShowAddCity("");
    });
    EntityGrid.Initialise('gdCity');
    
};

/**
 * Edit category
 * @param {type} categoryId
 * @returns {undefined}
 */
estimation.EditCity = function (categoryId) {
    estimation.ShowAddCity(categoryId);
};

/**
 * Dialogue add a categorie
 */
estimation.ShowAddCity = function (categoryId) {

    Dialog.open('', {"title": Dashboard.GetCode("estimation.AddCity"),
        "app": "estimation",
        "class": "DialogAdminEstimation",
        "method": "AddCity",
        "params": categoryId
    });
};

//Reload the category grid
estimation.ReloadCity = function(html){
    let categoryContainer = Dom.GetById("gdCity").parentNode;
    categoryContainer.innerHTML = html;
    estimation.InitTabCity();
};

//Delete a category
estimation.DeleteCity = function(categoryId){
      Animation.Confirm(Language.GetCode("estimation.ConfirmRemoveCategorie"), () => {

        let data = "Class=estimation&Methode=DeleteCity&App=estimation";
        data += "&categoryId=" + categoryId;

        Request.Post("Ajax.php", data).then(data => {

            data = JSON.parse(data);

            estimation.ReloadCity(data.data);
        });
    });
};
