/**
 * 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();
    TOP.init();
});

/**
 * show page
 */
TOP.init = function () {
    COMMON.showLoading();
    HEADER.goToHomePage();
    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';
        }
    }
};
