// ReportList function js

var RL = {};

RL.init = function() {
    console.log("ReportList init start");
    // COMMON.checkAuth(true);
    RL.loadCommon();
    RL.checkQuickReport();
    RL.initTaskReportList();
};

RL.loadCommon = function() {
	TEMPLATE.loadHearder("#includedHeader");
    TEMPLATE.loadConfirmModal("#includedConfirmModal");
	const navs = [
        {
            titleLang: 'dashboard',
            href: 'dashboard.html',
        },
        {
            titleLang: 'pickup',
        },
    ];
    TEMPLATE.loadMainNavsTitle("#includedMainTitle", "reportList", navs, null);
}

RL.checkQuickReport = function() {
    if (sessionStorage.OL_operationId) {
        let params = {};
        params.sid = COMMON.getSid();
        params.operationId = sessionStorage.OL_operationId;
        params.returnUrl = CONSTANT.URL.WEB.BASE + CONSTANT.URL.WEB.OPERATION_LIST;
        let url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) +  CONSTANT.URL.CMS.API.IS_QUICK_REPORT;
        COMMON.cmsAjax(url, params, false, function(result) {
            if (result.isQuickReport) {
                $("#btnPdfPrint").click(RL.goPdfPrint);
                $("#btnPdfPrint").show();
            } else {
                $("#btnPdfPrint").hide();
            }
        }, function() {
            COMMON.displayAlert("msgOperationEmpty");
            COMMON.avwScreenMove("index.html");
        });
    } else {
        COMMON.displayAlert("error");
        COMMON.avwScreenMove("index.html");
    }
}

RL.initTaskReportList = function() {
    if (sessionStorage.OL_operationId) {
        let params = {};
        params.sid = COMMON.getSid();
        params.operationId = sessionStorage.OL_operationId;
        params.returnUrl = CONSTANT.URL.WEB.BASE + CONSTANT.URL.WEB.OPERATION_LIST;
        let url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.HTML.BASE + CONSTANT.URL.CMS.HTML.TASK_REPORT_LIST;
        $("#reportList").load(url, params);
    } else {
        COMMON.displayAlert("error");
        COMMON.avwScreenMove("index.html");
    }
}

RL.goPdfPrint = function() {
    COMMON.avwScreenMove("pdfPrint.html");
}

