/**
 * Created by Tony on 2016/12/28.
 */

let JV = require('./jpc_value_define');
let JE = {
    F: function(fID, $CURRENT_RPT) {
        let rst = null;
        if ($CURRENT_RPT && ($CURRENT_RPT.fields[JV.NODE_DETAIL_FIELDS][JV.PROP_ID + "_" + fID])) {
            rst = $CURRENT_RPT.fields[JV.NODE_DETAIL_FIELDS][JV.PROP_ID + "_" + fID];
        } else if ($CURRENT_RPT && ($CURRENT_RPT.fields[JV.NODE_MASTER_FIELDS][JV.PROP_ID + "_" + fID])) {
            rst = $CURRENT_RPT.fields[JV.NODE_MASTER_FIELDS][JV.PROP_ID + "_" + fID];
        } else if ($CURRENT_RPT && ($CURRENT_RPT.fields[JV.NODE_DISCRETE_FIELDS][JV.PROP_ID + "_" + fID])) {
            rst = $CURRENT_RPT.fields[JV.NODE_DISCRETE_FIELDS][JV.PROP_ID + "_" + fID];
        } else if ($CURRENT_RPT && ($CURRENT_RPT.fields[JV.NODE_NO_MAPPING_FIELDS][JV.PROP_ID + "_" + fID])) {
            rst = $CURRENT_RPT.fields[JV.NODE_NO_MAPPING_FIELDS][JV.PROP_ID + "_" + fID];
        } else {
            rst = {msg: "the Field-ID is not valid, no result could be found!"};
        }
        return rst;
    },
    P: function(pID, $CURRENT_RPT) {
        let rst = null;
        if ($CURRENT_RPT && ($CURRENT_RPT.params[JV.PROP_ID + "_" + pID])) {
            rst = $CURRENT_RPT.params[JV.PROP_ID + "_" + pID];
        } else {
            rst = {msg: "the Param-ID is not valid, no result was found!"};
        }
        return rst;
    },
    getCurrentPage: function ($CURRENT_RPT) {
        let rst = 0;
        if ($CURRENT_RPT) {
            rst = $CURRENT_RPT.runTimePageData.currentPage;
        }
        return rst;
    },
    getTotalPage: function ($CURRENT_RPT) {
        let rst = 0;
        if ($CURRENT_RPT) {
            rst = $CURRENT_RPT.totalPages;
        }
        return rst;
    }
}

module.exports = JE;