/**
 * common js of top page.
 * top page is dashboard and operationList.
 * 
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */

var CHK_TOP = {};

$(document).ready(function () {
    
    //setting lang info
    CHK_Common.setLangCodeWeb();
    
    //Check if user is logged in
    CHK_Common.checkAuth(false);

    //setting msg of html
    CHK_Common.updateLang();
});

/**
 * show page
 */
CHK_TOP.init = function() {
    
    CHK_Common.showLoading();
    CHK_Footer.initFooter();//app should get data after initFooter
    CHK_Common.closeLoading();
};

/**
 * Show page by arbitrary id
 * 
 * @param {String} pageId 
 */
CHK_TOP.showPage = function(pageId) {
    
    //get data
    if (pageId == CHK_CONSTANT.PAGE_NAME.OPERATION_LIST) {
        CHK_OL.init();
    } else if (pageId == CHK_CONSTANT.PAGE_NAME.DASHBOARD) {
        CHK_Dashboard.init();
    }

    //show page
    const pages = document.getElementsByClassName("page-content");
    for (let i = 0; i < pages.length; i++) {
        if (pages[i].id == pageId) {
            pages[i].style.display = "block";
        } else {
            pages[i].style.display = "none";
        }
    }
}