Newer
Older
EMS-WEB-3.0 / src / main / webapp / s / app / org / Org.js
wxn on 9 Aug 2016 8 KB first commit
/**
 * Created by lenovo on 2016/4/13.
 */


var Org = function () {
//    var oTable;
//    var selectedNode;
//    var onNodeClick = function (event, treeId, treeNode, clickFlag) {
//        selectedNode = treeNode;
////        $("#clickedParentId").val(treeNode["id"]);
////        oTable.fnDraw();
//    };
//点击右键,弹出右键菜单
    function zTreeOnRightClick(event, treeId, treeNode) {
        if (treeNode == null) {
            return;
        }
        tree.pNode = treeNode;
        tree.showRightMenu({//显示右键菜单
            x: event.clientX,
            y: event.clientY+window.pageYOffset
        });
    };

    var setting = {

        callback: {
            onRightClick: zTreeOnRightClick
//            onClick: onNodeClick
        }

    };

    return {
        init: function () {
            Org.modalOpt();
            Org.initTree();
            Org.initLineTree();
            //Org.initAreaTable(8);//8是root节点的id
//            Org.initTable();
        },
        initTree: function () {
            $.ajax({
                url: $('#context').val() + "/feature/org-list.do",
                data:{type:1},
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    var treeObj = $.fn.zTree.init($("#treeMenu"), setting, eval(data));
                    treeObj.expandAll(true);
                }

            });
        },
        initLineTree: function () {
            $.ajax({
                url: $('#context').val() + "/feature/org-list.do",
                data:{type:2},
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    var treeObj = $.fn.zTree.init($("#treeLineMenu"), setting, eval(data));
                    treeObj.expandAll(true);
                }

            });
        },

//        initTable:function() {
//
//            function retrieveData(sSource, aoData, fnCallback) {
//                var parentId = $("#clickedParentId").val();
//                var pid = parentId?parentId:8;
//                $.ajax({
//                    type: "POST",
//                    url: sSource,
//                    dataType: "json",
//                    data: {"jsonParams": JSON.stringify(aoData), "parentId": pid},
//                    success: function (data) {
//                        //$("#url_sortdata").val(data.aaData);
//                        fnCallback(data); //服务器端返回的对象的returnObject部分是要求的格式
//                    }
//                });
//            };
//
//            oTable = $('#feature-table').dataTable({
//                "iDisplayLength": 5,
//                "bServerSide": true,
//                "bFilter": false,
//                "bPaginate": false,
//                "sAjaxSource": $('#context').val() + "/feature/getSubFeatureList.do",
//                "fnServerData": retrieveData,
//                "oLanguage": {
//                    "sZeroRecords": "抱歉, 没有找到",
//                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
//                    "sInfoEmpty": "没有数据",
//                    "oPaginate": {
//                        "sPrevious": "上一页",
//                        "sNext": "下一页",
//                        "sLast": "末页",
//                        "sFirst": "首页"
//                    }
//                },
//                "aoColumns": [
//                    {
//                        "mDataProp": "id"
//                    },
//                    {
//                        "mDataProp": "featureName",
//                        "sWidth": '60px'
//                    },
//                    {
//                        "mDataProp": "memo",
//                        "sWidth": '200px'
//                    },
//                    {
//                        "mDataProp": "btnEdit",
//                        "sWidth": '60px'
//                    },
//                    {
//                        "mDataProp": "btnDelete",
//                        "sWidth": '60px'
//                    }
//                ],
//                "aoColumnDefs": [
//                    {
//                        'bVisible': false,
//                        'aTargets': [0]
//                    },
//                    {
//                        'bSortable': false,
//                        'aTargets': [1,2,3,4]
//                    }
//                ]
//            });
//
////            //TODO LIST:删除资源n操作
//            $('#feature-table a.red').live('click', function (e) {
//                e.preventDefault();
//                if (confirm("确认要删除该操作 ?") == false) {
//                    return;
//                }
//                var nRow = $(this).parents('tr')[0];
//                var aData = oTable.fnGetData(nRow);
//                var id = aData.id;
//                $.ajax({
//                    type: "POST",
//                    url: $('#context').val() + "/feature/delete.do",
//                    dataType: "json",
//                    data: {id: id },
//                    success: function (data) {
//                        var jData = eval(data);
//                        if (jData.success == true) {
//                            oTable.fnDraw();
//                        }
//                        alert(jData.message);
//                    },
//                    error: function (request) {
//
//                        alert("删除失败");
//
//                    }
//                });
//
//            });
//
//            //TODO LIST:编辑用户操作
//            $('#feature-table a.blue').live('click', function (e) {
//                e.preventDefault();
//                $("#parentName").children().remove();//移除展示当前父节点的信息
//                var nRow = $(this).parents('tr')[0];
//                var aData = oTable.fnGetData(nRow);
//                var id = aData.id;
//                $("#clickedParentId").val(id);
//                $.ajax({
//                    type: "POST",
//                    url: $('#context').val() + "/feature/getFeatureById.do",
//                    data: {"id": id},
//                    dataType: "json",
//                    success: function (r) {
//                        //获取面的列表,将下拉列表初始化
//                        if (r.data) {
//                            $("#treeNodeId").text(id);
//                            $("#treeParentId").text(r.data.parentId);
//                            $("#featureName").val(r.data.featureName);
//                            $("#memo").val(r.data.memo);
//                            $('#newFeature').modal('show');
//                            $("#clickedParentId").val("");
//                        }
//                    },
//                    error: function (request) {
//                        //提示错误信息
//                        alert(r.message);
//                    }
//                });
//
//            });
//
//        },
        //绑定一些模态框的操作
        modalOpt: function () {
            $("#cancel-feature-btn").live('click', function (e) {
                $('#newFeature').modal('hide');
            });
            $("#save-feature-btn").live('click', function (e) {
                //做一些保存操作
                var parentId = $("#treeParentId").text();
                var nodeName = $("#featureName").val();
                var memo = $("#memo").val();
                var id = $("#treeNodeId").text();

                $.ajax({
                    type: "POST",
                    url: $('#context').val() + "/feature/save.do",
                    data: {"params": "{'id':'" + id + "','parentId':'" + parentId + "','featureName':'" + nodeName + "','memo':'" + memo + "'}"},
                    dataType: "json",
                    success: function (r) {
                        //获取面的列表,将下拉列表初始化
//                            alert("保存成功");
                        //刷新页面
                        location.href = $('#context').val() + "/content/org/org.jsp";
                    },
                    error: function (request) {
                        //提示错误信息
                        alert(r.message);
                    }
                });
                $('#newFeature').modal('hide');
            });
        }
    };
}();