/**
 * Created by Tony on 2017/6/26.
 */
'use strict'

let rptTplObj = {
    iniPage: function() {
        let me = this
        zTreeOprObj.getReportTemplateTree(RT.GrpType.CONSTRUCT);
    }
}

let zTreeOprObj = {
    treeObj: null,
    currentNode: null,
    getReportTemplateTree: function(grpType) {
        let me = zTreeOprObj, params = {};
        params.grpType = grpType;
        params.userId = userID;
        params.tplType = RT.TplType.ALL;
        CommonAjax.postEx("report_tpl_api/getRptTplTree", params, 20000, true, function(result){
                zTreeHelper.createTree(result, setting, "rptTplTree", me);
                me.refreshNodes();
            }, null, null
        );
    },
    refreshNodes: function() {
        let me = this;
        let private_setupIsParent = function(node){
            if (node.nodeType == RT.NodeType.NODE) {
                node.isParent = true;
            } else {
                node.isParent = false;
            }
            if (node.items && node.items.length) {
                for (let i = 0; i < node.items.length; i++) {
                    private_setupIsParent(node.items[i]);
                }
            }
        };
        let topNodes = me.treeObj.getNodes();
        for (let i = 0; i < topNodes.length; i++) {
            private_setupIsParent(topNodes[i]);
        }
        me.treeObj.refresh();
    },
    onCheck: function() {
        //count();
        //if (clearFlag) {
        //    clearCheckedOldNodes();
        //}
    },
    onClick: function(event,treeId,treeNode) {
        let me = zTreeOprObj;
        if (treeNode.nodeType == RT.NodeType.NODE) {
            me.currentNode = treeNode;
            $("#rpt_tpl_display_label")[0].innerText = "...";
        } else if (treeNode.nodeType == RT.NodeType.TEMPLATE) {
            me.currentNode = null;
            $("#rpt_tpl_display_label")[0].innerText = treeNode.name;
            if (treeNode.refId < 0) {
                //创建新报表模板
            }
        }
    }
}
