'use strict';

angular.module('qusion.ui.jstree', [
])
    .directive('qnJstree', function () {
        return {
            require: 'ngModel',
            scope: {
                list: '=ngModel',
                options: '=qnJstree',
                treeObject: '=qnTreeobject'
            },
            
            link: function (scope, elem, attr) {

                var options;

                var settings = {
                    debugLevel: 0
                };

                scope.$watch('list', function (value) {

                    if (value) {
                       options = angular.extend(settings, scope.options);
                        
                       options.children = scope.list;
                       elem.dynatree(options);
                       scope.treeObject = elem.dynatree("getTree");
                      
                    }
                });
            }
        };
    });