/**
 * 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 TOP = {};

$(document).ready(function () {
    //setting lang info
    COMMON.setLangCodeWeb();

    //Check if user is logged in
    COMMON.checkAuth(false);

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

/**
 * show page
 */
TOP.init = function () {
    COMMON.showLoading();
    FOOTER.initFooter(); //app should get data after initFooter
    COMMON.closeLoading();
};

/**
 * Show page by arbitrary id
 *
 * @param {String} pageId
 */
TOP.showPage = function (pageId) {
    //get data
    if (pageId == CONSTANT.PAGE_NAME.OPERATION_LIST) {
        OL.init();
    } else if (pageId == 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';
        }
    }
};
