angular.module('app').directive('tree', function () {
    return {
        require: '?ngModel',
        restrict: 'A',
        scope: {
            treeObj: '=ngTree',
            nodes:'=ngTreeNodes',
            onCheck: '=ngTreeCheck',
            onClick: '=ngTreeClick'
        },
        link: function ($scope, element, attrs, ngModel) {
            var setting = {
                async: {
                    enable: true,
                    autoParam: ["id", "name"],
                    url: ""
                },
                view: {
                    showIcon: true,
                    addDiyDom: $scope.addDiyDom
                },
                data: {
                    key: {
                        title: "t"
                    },
                    simpleData: {
                        enable: true
                    }
                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    chkboxType: { "Y": "ps", "N": "ps" }
                },
                callback: {
                    onClick: $scope.onClick,
                    onCheck: $scope.onCheck
                }
            };
            $scope.treeObj = $.fn.zTree.init(element, setting, $scope.nodes);
        }
    };
});

// angular.module('app').directive('tree', function () {
//     return {
//         require: '?ngModel',
//         restrict: 'A',
//         link: function ($scope, element, attrs, ngModel) {
//             //var opts = angular.extend({}, $scope.$eval(attrs.nlUploadify)); 
//             var setting = {
//                 async: {
//                     enable: true,
//                     autoParam: ["id", "name"],
//                     url: ""
//                 },
//                 view: {
//                     showIcon: true
//                 },
//                 data: {
//                     key: {
//                         title: "t"
//                     },
//                     simpleData: {
//                         enable: true
//                     }
//                 },
//                 check: {
//                     enable: true,
//                     chkStyle: "checkbox",
//                     chkboxType: { "Y": "ps", "N": "ps" }
//                 },
//                 callback: {
//                     onClick: $scope.onClick,
//                     onCheck: $scope.onCheck
//                 }
//             };
//             // alert(attrs['class']);
//             // alert(JSON.stringify(element));
//             $scope.treeObj_c = $.fn.zTree.init($("#treeCompany"), setting, $scope.zNodes_c);//单位树
//             $scope.treeObj_b = $.fn.zTree.init($("#treeBranchs"), setting, $scope.zNodes_b);//部门树
//             $scope.treeObj_a = $.fn.zTree.init($("#treeAddressL"), setting, $scope.zNodes_a);//通讯录树
//             $scope.treeObj_g = $.fn.zTree.init($("#groupUsers"), setting, $scope.groups);//群组树
//             $scope.treeObj_u = $.fn.zTree.init($("#userSelected"), setting, $scope.groups);//用户搜索列表树
//             $scope.treeObj_child = $.fn.zTree.init($("#treeChild"), setting, $scope.groups);//虚拟用户子树
//         }
//     };
// }); 