add jquery-treegrid
authorMaciej Tronowski <mtro@man.poznan.pl>
Thu, 12 Feb 2015 11:51:33 +0000 (12:51 +0100)
committerMaciej Tronowski <mtro@man.poznan.pl>
Thu, 12 Feb 2015 11:51:33 +0000 (12:51 +0100)
qcg/static/qcg/treegrid/css/jquery.treegrid.css [new file with mode: 0644]
qcg/static/qcg/treegrid/img/collapse.png [new file with mode: 0644]
qcg/static/qcg/treegrid/img/expand.png [new file with mode: 0644]
qcg/static/qcg/treegrid/img/file.png [new file with mode: 0644]
qcg/static/qcg/treegrid/img/folder.png [new file with mode: 0644]
qcg/static/qcg/treegrid/js/jquery.treegrid.bootstrap3.js [new file with mode: 0644]
qcg/static/qcg/treegrid/js/jquery.treegrid.js [new file with mode: 0644]
qcg/static/qcg/treegrid/js/jquery.treegrid.min.js [new file with mode: 0644]

diff --git a/qcg/static/qcg/treegrid/css/jquery.treegrid.css b/qcg/static/qcg/treegrid/css/jquery.treegrid.css
new file mode 100644 (file)
index 0000000..6c95550
--- /dev/null
@@ -0,0 +1,6 @@
+.treegrid-indent {width:16px; height: 16px; display: inline-block; position: relative;}
+
+.treegrid-expander {width:16px; height: 16px; display: inline-block; position: relative; cursor: pointer;}
+
+.treegrid-expander-expanded {background-image: url(../img/collapse.png); }
+.treegrid-expander-collapsed {background-image: url(../img/expand.png);}
diff --git a/qcg/static/qcg/treegrid/img/collapse.png b/qcg/static/qcg/treegrid/img/collapse.png
new file mode 100644 (file)
index 0000000..76577a5
Binary files /dev/null and b/qcg/static/qcg/treegrid/img/collapse.png differ
diff --git a/qcg/static/qcg/treegrid/img/expand.png b/qcg/static/qcg/treegrid/img/expand.png
new file mode 100644 (file)
index 0000000..cfb42a4
Binary files /dev/null and b/qcg/static/qcg/treegrid/img/expand.png differ
diff --git a/qcg/static/qcg/treegrid/img/file.png b/qcg/static/qcg/treegrid/img/file.png
new file mode 100644 (file)
index 0000000..813f712
Binary files /dev/null and b/qcg/static/qcg/treegrid/img/file.png differ
diff --git a/qcg/static/qcg/treegrid/img/folder.png b/qcg/static/qcg/treegrid/img/folder.png
new file mode 100644 (file)
index 0000000..784e8fa
Binary files /dev/null and b/qcg/static/qcg/treegrid/img/folder.png differ
diff --git a/qcg/static/qcg/treegrid/js/jquery.treegrid.bootstrap3.js b/qcg/static/qcg/treegrid/js/jquery.treegrid.bootstrap3.js
new file mode 100644 (file)
index 0000000..ac4a835
--- /dev/null
@@ -0,0 +1,4 @@
+$.extend($.fn.treegrid.defaults, {
+    expanderExpandedClass: 'glyphicon glyphicon-chevron-down',
+    expanderCollapsedClass: 'glyphicon glyphicon-chevron-right'
+});
diff --git a/qcg/static/qcg/treegrid/js/jquery.treegrid.js b/qcg/static/qcg/treegrid/js/jquery.treegrid.js
new file mode 100644 (file)
index 0000000..5b513eb
--- /dev/null
@@ -0,0 +1,626 @@
+/*
+ * jQuery treegrid Plugin 0.3.0
+ * https://github.com/maxazan/jquery-treegrid
+ *
+ * Copyright 2013, Pomazan Max
+ * Licensed under the MIT licenses.
+ */
+(function($) {
+
+    var methods = {
+        /**
+         * Initialize tree
+         *
+         * @param {Object} options
+         * @returns {Object[]}
+         */
+        initTree: function(options) {
+            var settings = $.extend({}, this.treegrid.defaults, options);
+            return this.each(function() {
+                var $this = $(this);
+                $this.treegrid('setTreeContainer', $(this));
+                $this.treegrid('setSettings', settings);
+                settings.getRootNodes.apply(this, [$(this)]).treegrid('initNode', settings);
+                $this.treegrid('getRootNodes').treegrid('render');
+            });
+        },
+        /**
+         * Initialize node
+         *
+         * @param {Object} settings
+         * @returns {Object[]}
+         */
+        initNode: function(settings) {
+            return this.each(function() {
+                var $this = $(this);
+                $this.treegrid('setTreeContainer', settings.getTreeGridContainer.apply(this));
+                $this.treegrid('getChildNodes').treegrid('initNode', settings);
+                $this.treegrid('initExpander').treegrid('initIndent').treegrid('initEvents').treegrid('initState').treegrid('initChangeEvent').treegrid("initSettingsEvents");
+            });
+        },
+        initChangeEvent: function() {
+            var $this = $(this);
+            //Save state on change
+            $this.on("change", function() {
+                var $this = $(this);
+                $this.treegrid('render');
+                if ($this.treegrid('getSetting', 'saveState')) {
+                    $this.treegrid('saveState');
+                }
+            });
+            return $this;
+        },
+        /**
+         * Initialize node events
+         *
+         * @returns {Node}
+         */
+        initEvents: function() {
+            var $this = $(this);
+            //Default behavior on collapse
+            $this.on("collapse", function() {
+                var $this = $(this);
+                $this.removeClass('treegrid-expanded');
+                $this.addClass('treegrid-collapsed');
+            });
+            //Default behavior on expand
+            $this.on("expand", function() {
+                var $this = $(this);
+                $this.removeClass('treegrid-collapsed');
+                $this.addClass('treegrid-expanded');
+            });
+
+            return $this;
+        },
+        /**
+         * Initialize events from settings
+         *
+         * @returns {Node}
+         */
+        initSettingsEvents: function() {
+            var $this = $(this);
+            //Save state on change
+            $this.on("change", function() {
+                var $this = $(this);
+                if (typeof($this.treegrid('getSetting', 'onChange')) === "function") {
+                    $this.treegrid('getSetting', 'onChange').apply($this);
+                }
+            });
+            //Default behavior on collapse
+            $this.on("collapse", function() {
+                var $this = $(this);
+                if (typeof($this.treegrid('getSetting', 'onCollapse')) === "function") {
+                    $this.treegrid('getSetting', 'onCollapse').apply($this);
+                }
+            });
+            //Default behavior on expand
+            $this.on("expand", function() {
+                var $this = $(this);
+                if (typeof($this.treegrid('getSetting', 'onExpand')) === "function") {
+                    $this.treegrid('getSetting', 'onExpand').apply($this);
+                }
+
+            });
+
+            return $this;
+        },
+        /**
+         * Initialize expander for node
+         *
+         * @returns {Node}
+         */
+        initExpander: function() {
+            var $this = $(this);
+            var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn'));
+            var tpl = $this.treegrid('getSetting', 'expanderTemplate');
+            var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
+            if (expander) {
+                expander.remove();
+            }
+            $(tpl).prependTo(cell).click(function() {
+                $($(this).closest('tr')).treegrid('toggle');
+            });
+            return $this;
+        },
+        /**
+         * Initialize indent for node
+         *
+         * @returns {Node}
+         */
+        initIndent: function() {
+            var $this = $(this);
+            $this.find('.treegrid-indent').remove();
+            var tpl = $this.treegrid('getSetting', 'indentTemplate');
+            var expander = $this.find('.treegrid-expander');
+            var depth = $this.treegrid('getDepth');
+            for (var i = 0; i < depth; i++) {
+                $(tpl).insertBefore(expander);
+            }
+            return $this;
+        },
+        /**
+         * Initialise state of node
+         *
+         * @returns {Node}
+         */
+        initState: function() {
+            var $this = $(this);
+            if ($this.treegrid('getSetting', 'saveState') && !$this.treegrid('isFirstInit')) {
+                $this.treegrid('restoreState');
+            } else {
+                if ($this.treegrid('getSetting', 'initialState') === "expanded") {
+                    $this.treegrid('expand');
+                } else {
+                    $this.treegrid('collapse');
+                }
+            }
+            return $this;
+        },
+        /**
+         * Return true if this tree was never been initialised
+         *
+         * @returns {Boolean}
+         */
+        isFirstInit: function() {
+            var tree = $(this).treegrid('getTreeContainer');
+            if (tree.data('first_init') === undefined) {
+                tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined);
+            }
+            return tree.data('first_init');
+        },
+        /**
+         * Save state of current node
+         *
+         * @returns {Node}
+         */
+        saveState: function() {
+            var $this = $(this);
+            if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
+
+                var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || '';
+                var stateArray = (stateArrayString === '' ? [] : stateArrayString.split(','));
+                var nodeId = $this.treegrid('getNodeId');
+
+                if ($this.treegrid('isExpanded')) {
+                    if ($.inArray(nodeId, stateArray) === -1) {
+                        stateArray.push(nodeId);
+                    }
+                } else if ($this.treegrid('isCollapsed')) {
+                    if ($.inArray(nodeId, stateArray) !== -1) {
+                        stateArray.splice($.inArray(nodeId, stateArray), 1);
+                    }
+                }
+                $.cookie($this.treegrid('getSetting', 'saveStateName'), stateArray.join(','));
+            }
+            return $this;
+        },
+        /**
+         * Restore state of current node.
+         *
+         * @returns {Node}
+         */
+        restoreState: function() {
+            var $this = $(this);
+            if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
+                var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(',');
+                if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) {
+                    $this.treegrid('expand');
+                } else {
+                    $this.treegrid('collapse');
+                }
+
+            }
+            return $this;
+        },
+        /**
+         * Method return setting by name
+         *
+         * @param {type} name
+         * @returns {unresolved}
+         */
+        getSetting: function(name) {
+            if (!$(this).treegrid('getTreeContainer')) {
+                return null;
+            }
+            return $(this).treegrid('getTreeContainer').data('settings')[name];
+        },
+        /**
+         * Add new settings
+         *
+         * @param {Object} settings
+         */
+        setSettings: function(settings) {
+            $(this).treegrid('getTreeContainer').data('settings', settings);
+        },
+        /**
+         * Return tree container
+         *
+         * @returns {HtmlElement}
+         */
+        getTreeContainer: function() {
+            return $(this).data('treegrid');
+        },
+        /**
+         * Set tree container
+         *
+         * @param {HtmlE;ement} container
+         */
+        setTreeContainer: function(container) {
+            return $(this).data('treegrid', container);
+        },
+        /**
+         * Method return all root nodes of tree.
+         *
+         * Start init all child nodes from it.
+         *
+         * @returns {Array}
+         */
+        getRootNodes: function() {
+            return $(this).treegrid('getSetting', 'getRootNodes').apply(this, [$(this).treegrid('getTreeContainer')]);
+        },
+        /**
+         * Method return all nodes of tree.
+         *
+         * @returns {Array}
+         */
+        getAllNodes: function() {
+            return $(this).treegrid('getSetting', 'getAllNodes').apply(this, [$(this).treegrid('getTreeContainer')]);
+        },
+        /**
+         * Mthod return true if element is Node
+         *
+         * @returns {String}
+         */
+        isNode: function() {
+            return $(this).treegrid('getNodeId') !== null;
+        },
+        /**
+         * Mthod return id of node
+         *
+         * @returns {String}
+         */
+        getNodeId: function() {
+            if ($(this).treegrid('getSetting', 'getNodeId') === null) {
+                return null;
+            } else {
+                return $(this).treegrid('getSetting', 'getNodeId').apply(this);
+            }
+        },
+        /**
+         * Method return parent id of node or null if root node
+         *
+         * @returns {String}
+         */
+        getParentNodeId: function() {
+            return $(this).treegrid('getSetting', 'getParentNodeId').apply(this);
+        },
+        /**
+         * Method return parent node or null if root node
+         *
+         * @returns {Object[]}
+         */
+        getParentNode: function() {
+            if ($(this).treegrid('getParentNodeId') === null) {
+                return null;
+            } else {
+                return $(this).treegrid('getSetting', 'getNodeById').apply(this, [$(this).treegrid('getParentNodeId'), $(this).treegrid('getTreeContainer')]);
+            }
+        },
+        /**
+         * Method return array of child nodes or null if node is leaf
+         *
+         * @returns {Object[]}
+         */
+        getChildNodes: function() {
+            return $(this).treegrid('getSetting', 'getChildNodes').apply(this, [$(this).treegrid('getNodeId'), $(this).treegrid('getTreeContainer')]);
+        },
+        /**
+         * Method return depth of tree.
+         *
+         * This method is needs for calculate indent
+         *
+         * @returns {Number}
+         */
+        getDepth: function() {
+            if ($(this).treegrid('getParentNode') === null) {
+                return 0;
+            }
+            return $(this).treegrid('getParentNode').treegrid('getDepth') + 1;
+        },
+        /**
+         * Method return true if node is root
+         *
+         * @returns {Boolean}
+         */
+        isRoot: function() {
+            return $(this).treegrid('getDepth') === 0;
+        },
+        /**
+         * Method return true if node has no child nodes
+         *
+         * @returns {Boolean}
+         */
+        isLeaf: function() {
+            return $(this).treegrid('getChildNodes').length === 0;
+        },
+        /**
+         * Method return true if node last in branch
+         *
+         * @returns {Boolean}
+         */
+        isLast: function() {
+            if ($(this).treegrid('isNode')) {
+                var parentNode = $(this).treegrid('getParentNode');
+                if (parentNode === null) {
+                    if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').last().treegrid('getNodeId')) {
+                        return true;
+                    }
+                } else {
+                    if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').last().treegrid('getNodeId')) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        },
+        /**
+         * Method return true if node first in branch
+         *
+         * @returns {Boolean}
+         */
+        isFirst: function() {
+            if ($(this).treegrid('isNode')) {
+                var parentNode = $(this).treegrid('getParentNode');
+                if (parentNode === null) {
+                    if ($(this).treegrid('getNodeId') === $(this).treegrid('getRootNodes').first().treegrid('getNodeId')) {
+                        return true;
+                    }
+                } else {
+                    if ($(this).treegrid('getNodeId') === parentNode.treegrid('getChildNodes').first().treegrid('getNodeId')) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        },
+        /**
+         * Return true if node expanded
+         *
+         * @returns {Boolean}
+         */
+        isExpanded: function() {
+            return $(this).hasClass('treegrid-expanded');
+        },
+        /**
+         * Return true if node collapsed
+         *
+         * @returns {Boolean}
+         */
+        isCollapsed: function() {
+            return $(this).hasClass('treegrid-collapsed');
+        },
+        /**
+         * Return true if at least one of parent node is collapsed
+         *
+         * @returns {Boolean}
+         */
+        isOneOfParentsCollapsed: function() {
+            var $this = $(this);
+            if ($this.treegrid('isRoot')) {
+                return false;
+            } else {
+                if ($this.treegrid('getParentNode').treegrid('isCollapsed')) {
+                    return true;
+                } else {
+                    return $this.treegrid('getParentNode').treegrid('isOneOfParentsCollapsed');
+                }
+            }
+        },
+        /**
+         * Expand node
+         *
+         * @returns {Node}
+         */
+        expand: function() {
+            if (!this.treegrid('isLeaf') && !this.treegrid("isExpanded")) {
+                this.trigger("expand");
+                this.trigger("change");
+                return this;
+            }
+            return this;
+        },
+        /**
+         * Expand all nodes
+         *
+         * @returns {Node}
+         */
+        expandAll: function() {
+            var $this = $(this);
+            $this.treegrid('getRootNodes').treegrid('expandRecursive');
+            return $this;
+        },
+        /**
+         * Expand current node and all child nodes begin from current
+         *
+         * @returns {Node}
+         */
+        expandRecursive: function() {
+            return $(this).each(function() {
+                var $this = $(this);
+                $this.treegrid('expand');
+                if (!$this.treegrid('isLeaf')) {
+                    $this.treegrid('getChildNodes').treegrid('expandRecursive');
+                }
+            });
+        },
+        /**
+         * Collapse node
+         *
+         * @returns {Node}
+         */
+        collapse: function() {
+            return $(this).each(function() {
+                var $this = $(this);
+                if (!$this.treegrid('isLeaf') && !$this.treegrid("isCollapsed")) {
+                    $this.trigger("collapse");
+                    $this.trigger("change");
+                }
+            });
+        },
+        /**
+         * Collapse all nodes
+         *
+         * @returns {Node}
+         */
+        collapseAll: function() {
+            var $this = $(this);
+            $this.treegrid('getRootNodes').treegrid('collapseRecursive');
+            return $this;
+        },
+        /**
+         * Collapse current node and all child nodes begin from current
+         *
+         * @returns {Node}
+         */
+        collapseRecursive: function() {
+            return $(this).each(function() {
+                var $this = $(this);
+                $this.treegrid('collapse');
+                if (!$this.treegrid('isLeaf')) {
+                    $this.treegrid('getChildNodes').treegrid('collapseRecursive');
+                }
+            });
+        },
+        /**
+         * Expand if collapsed, Collapse if expanded
+         *
+         * @returns {Node}
+         */
+        toggle: function() {
+            var $this = $(this);
+            if ($this.treegrid('isExpanded')) {
+                $this.treegrid('collapse');
+            } else {
+                $this.treegrid('expand');
+            }
+            return $this;
+        },
+        /**
+         * Rendering node
+         *
+         * @returns {Node}
+         */
+        render: function() {
+            return $(this).each(function() {
+                var $this = $(this);
+                //if parent colapsed we hidden
+                if ($this.treegrid('isOneOfParentsCollapsed')) {
+                    $this.hide();
+                } else {
+                    $this.show();
+                }
+                if (!$this.treegrid('isLeaf')) {
+                    $this.treegrid('renderExpander');
+                    $this.treegrid('getChildNodes').treegrid('render');
+                }
+            });
+        },
+        /**
+         * Rendering expander depends on node state
+         *
+         * @returns {Node}
+         */
+        renderExpander: function() {
+            return $(this).each(function() {
+                var $this = $(this);
+                var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
+                if (expander) {
+
+                    if (!$this.treegrid('isCollapsed')) {
+                        expander.removeClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
+                        expander.addClass($this.treegrid('getSetting', 'expanderExpandedClass'));
+                    } else {
+                        expander.removeClass($this.treegrid('getSetting', 'expanderExpandedClass'));
+                        expander.addClass($this.treegrid('getSetting', 'expanderCollapsedClass'));
+                    }
+                } else {
+                    $this.treegrid('initExpander');
+                    $this.treegrid('renderExpander');
+                }
+            });
+        }
+    };
+    $.fn.treegrid = function(method) {
+        if (methods[method]) {
+            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
+        } else if (typeof method === 'object' || !method) {
+            return methods.initTree.apply(this, arguments);
+        } else {
+            $.error('Method with name ' + method + ' does not exists for jQuery.treegrid');
+        }
+    };
+    /**
+     *  Plugin's default options
+     */
+    $.fn.treegrid.defaults = {
+        initialState: 'expanded',
+        saveState: false,
+        saveStateMethod: 'cookie',
+        saveStateName: 'tree-grid-state',
+        expanderTemplate: '<span class="treegrid-expander"></span>',
+        indentTemplate: '<span class="treegrid-indent"></span>',
+        expanderExpandedClass: 'treegrid-expander-expanded',
+        expanderCollapsedClass: 'treegrid-expander-collapsed',
+        treeColumn: 0,
+        getExpander: function() {
+            return $(this).find('.treegrid-expander');
+        },
+        getNodeId: function() {
+            var template = /treegrid-([A-Za-z0-9_-]+)/;
+            if (template.test($(this).attr('class'))) {
+                return template.exec($(this).attr('class'))[1];
+            }
+            return null;
+        },
+        getParentNodeId: function() {
+            var template = /treegrid-parent-([A-Za-z0-9_-]+)/;
+            if (template.test($(this).attr('class'))) {
+                return template.exec($(this).attr('class'))[1];
+            }
+            return null;
+        },
+        getNodeById: function(id, treegridContainer) {
+            var templateClass = "treegrid-" + id;
+            return treegridContainer.find('tr.' + templateClass);
+        },
+        getChildNodes: function(id, treegridContainer) {
+            var templateClass = "treegrid-parent-" + id;
+            return treegridContainer.find('tr.' + templateClass);
+        },
+        getTreeGridContainer: function() {
+            return $(this).closest('table');
+        },
+        getRootNodes: function(treegridContainer) {
+            var result = $.grep(treegridContainer.find('tr'), function(element) {
+                var classNames = $(element).attr('class');
+                var templateClass = /treegrid-([A-Za-z0-9_-]+)/;
+                var templateParentClass = /treegrid-parent-([A-Za-z0-9_-]+)/;
+                return templateClass.test(classNames) && !templateParentClass.test(classNames);
+            });
+            return $(result);
+        },
+        getAllNodes: function(treegridContainer) {
+            var result = $.grep(treegridContainer.find('tr'), function(element) {
+                var classNames = $(element).attr('class');
+                var templateClass = /treegrid-([A-Za-z0-9_-]+)/;
+                return templateClass.test(classNames);
+            });
+            return $(result);
+        },
+        //Events
+        onCollapse: null,
+        onExpand: null,
+        onChange: null
+
+    };
+})(jQuery);
diff --git a/qcg/static/qcg/treegrid/js/jquery.treegrid.min.js b/qcg/static/qcg/treegrid/js/jquery.treegrid.min.js
new file mode 100644 (file)
index 0000000..7b7566f
--- /dev/null
@@ -0,0 +1,2 @@
+/*! jquery-treegrid 0.3.0 */
+!function(a){var b={initTree:function(b){var c=a.extend({},this.treegrid.defaults,b);return this.each(function(){var b=a(this);b.treegrid("setTreeContainer",a(this)),b.treegrid("setSettings",c),c.getRootNodes.apply(this,[a(this)]).treegrid("initNode",c),b.treegrid("getRootNodes").treegrid("render")})},initNode:function(b){return this.each(function(){var c=a(this);c.treegrid("setTreeContainer",b.getTreeGridContainer.apply(this)),c.treegrid("getChildNodes").treegrid("initNode",b),c.treegrid("initExpander").treegrid("initIndent").treegrid("initEvents").treegrid("initState").treegrid("initChangeEvent").treegrid("initSettingsEvents")})},initChangeEvent:function(){var b=a(this);return b.on("change",function(){var b=a(this);b.treegrid("render"),b.treegrid("getSetting","saveState")&&b.treegrid("saveState")}),b},initEvents:function(){var b=a(this);return b.on("collapse",function(){var b=a(this);b.removeClass("treegrid-expanded"),b.addClass("treegrid-collapsed")}),b.on("expand",function(){var b=a(this);b.removeClass("treegrid-collapsed"),b.addClass("treegrid-expanded")}),b},initSettingsEvents:function(){var b=a(this);return b.on("change",function(){var b=a(this);"function"==typeof b.treegrid("getSetting","onChange")&&b.treegrid("getSetting","onChange").apply(b)}),b.on("collapse",function(){var b=a(this);"function"==typeof b.treegrid("getSetting","onCollapse")&&b.treegrid("getSetting","onCollapse").apply(b)}),b.on("expand",function(){var b=a(this);"function"==typeof b.treegrid("getSetting","onExpand")&&b.treegrid("getSetting","onExpand").apply(b)}),b},initExpander:function(){var b=a(this),c=b.find("td").get(b.treegrid("getSetting","treeColumn")),d=b.treegrid("getSetting","expanderTemplate"),e=b.treegrid("getSetting","getExpander").apply(this);return e&&e.remove(),a(d).prependTo(c).click(function(){a(a(this).closest("tr")).treegrid("toggle")}),b},initIndent:function(){var b=a(this);b.find(".treegrid-indent").remove();for(var c=b.treegrid("getSetting","indentTemplate"),d=b.find(".treegrid-expander"),e=b.treegrid("getDepth"),f=0;e>f;f++)a(c).insertBefore(d);return b},initState:function(){var b=a(this);return b.treegrid(b.treegrid("getSetting","saveState")&&!b.treegrid("isFirstInit")?"restoreState":"expanded"===b.treegrid("getSetting","initialState")?"expand":"collapse"),b},isFirstInit:function(){var b=a(this).treegrid("getTreeContainer");return void 0===b.data("first_init")&&b.data("first_init",void 0===a.cookie(b.treegrid("getSetting","saveStateName"))),b.data("first_init")},saveState:function(){var b=a(this);if("cookie"===b.treegrid("getSetting","saveStateMethod")){var c=a.cookie(b.treegrid("getSetting","saveStateName"))||"",d=""===c?[]:c.split(","),e=b.treegrid("getNodeId");b.treegrid("isExpanded")?-1===a.inArray(e,d)&&d.push(e):b.treegrid("isCollapsed")&&-1!==a.inArray(e,d)&&d.splice(a.inArray(e,d),1),a.cookie(b.treegrid("getSetting","saveStateName"),d.join(","))}return b},restoreState:function(){var b=a(this);if("cookie"===b.treegrid("getSetting","saveStateMethod")){var c=a.cookie(b.treegrid("getSetting","saveStateName")).split(",");b.treegrid(-1!==a.inArray(b.treegrid("getNodeId"),c)?"expand":"collapse")}return b},getSetting:function(b){return a(this).treegrid("getTreeContainer")?a(this).treegrid("getTreeContainer").data("settings")[b]:null},setSettings:function(b){a(this).treegrid("getTreeContainer").data("settings",b)},getTreeContainer:function(){return a(this).data("treegrid")},setTreeContainer:function(b){return a(this).data("treegrid",b)},getRootNodes:function(){return a(this).treegrid("getSetting","getRootNodes").apply(this,[a(this).treegrid("getTreeContainer")])},getAllNodes:function(){return a(this).treegrid("getSetting","getAllNodes").apply(this,[a(this).treegrid("getTreeContainer")])},isNode:function(){return null!==a(this).treegrid("getNodeId")},getNodeId:function(){return null===a(this).treegrid("getSetting","getNodeId")?null:a(this).treegrid("getSetting","getNodeId").apply(this)},getParentNodeId:function(){return a(this).treegrid("getSetting","getParentNodeId").apply(this)},getParentNode:function(){return null===a(this).treegrid("getParentNodeId")?null:a(this).treegrid("getSetting","getNodeById").apply(this,[a(this).treegrid("getParentNodeId"),a(this).treegrid("getTreeContainer")])},getChildNodes:function(){return a(this).treegrid("getSetting","getChildNodes").apply(this,[a(this).treegrid("getNodeId"),a(this).treegrid("getTreeContainer")])},getDepth:function(){return null===a(this).treegrid("getParentNode")?0:a(this).treegrid("getParentNode").treegrid("getDepth")+1},isRoot:function(){return 0===a(this).treegrid("getDepth")},isLeaf:function(){return 0===a(this).treegrid("getChildNodes").length},isLast:function(){if(a(this).treegrid("isNode")){var b=a(this).treegrid("getParentNode");if(null===b){if(a(this).treegrid("getNodeId")===a(this).treegrid("getRootNodes").last().treegrid("getNodeId"))return!0}else if(a(this).treegrid("getNodeId")===b.treegrid("getChildNodes").last().treegrid("getNodeId"))return!0}return!1},isFirst:function(){if(a(this).treegrid("isNode")){var b=a(this).treegrid("getParentNode");if(null===b){if(a(this).treegrid("getNodeId")===a(this).treegrid("getRootNodes").first().treegrid("getNodeId"))return!0}else if(a(this).treegrid("getNodeId")===b.treegrid("getChildNodes").first().treegrid("getNodeId"))return!0}return!1},isExpanded:function(){return a(this).hasClass("treegrid-expanded")},isCollapsed:function(){return a(this).hasClass("treegrid-collapsed")},isOneOfParentsCollapsed:function(){var b=a(this);return b.treegrid("isRoot")?!1:b.treegrid("getParentNode").treegrid("isCollapsed")?!0:b.treegrid("getParentNode").treegrid("isOneOfParentsCollapsed")},expand:function(){return this.treegrid("isLeaf")||this.treegrid("isExpanded")?this:(this.trigger("expand"),this.trigger("change"),this)},expandAll:function(){var b=a(this);return b.treegrid("getRootNodes").treegrid("expandRecursive"),b},expandRecursive:function(){return a(this).each(function(){var b=a(this);b.treegrid("expand"),b.treegrid("isLeaf")||b.treegrid("getChildNodes").treegrid("expandRecursive")})},collapse:function(){return a(this).each(function(){var b=a(this);b.treegrid("isLeaf")||b.treegrid("isCollapsed")||(b.trigger("collapse"),b.trigger("change"))})},collapseAll:function(){var b=a(this);return b.treegrid("getRootNodes").treegrid("collapseRecursive"),b},collapseRecursive:function(){return a(this).each(function(){var b=a(this);b.treegrid("collapse"),b.treegrid("isLeaf")||b.treegrid("getChildNodes").treegrid("collapseRecursive")})},toggle:function(){var b=a(this);return b.treegrid(b.treegrid("isExpanded")?"collapse":"expand"),b},render:function(){return a(this).each(function(){var b=a(this);b.treegrid("isOneOfParentsCollapsed")?b.hide():b.show(),b.treegrid("isLeaf")||(b.treegrid("renderExpander"),b.treegrid("getChildNodes").treegrid("render"))})},renderExpander:function(){return a(this).each(function(){var b=a(this),c=b.treegrid("getSetting","getExpander").apply(this);c?b.treegrid("isCollapsed")?(c.removeClass(b.treegrid("getSetting","expanderExpandedClass")),c.addClass(b.treegrid("getSetting","expanderCollapsedClass"))):(c.removeClass(b.treegrid("getSetting","expanderCollapsedClass")),c.addClass(b.treegrid("getSetting","expanderExpandedClass"))):(b.treegrid("initExpander"),b.treegrid("renderExpander"))})}};a.fn.treegrid=function(c){return b[c]?b[c].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof c&&c?void a.error("Method with name "+c+" does not exists for jQuery.treegrid"):b.initTree.apply(this,arguments)},a.fn.treegrid.defaults={initialState:"expanded",saveState:!1,saveStateMethod:"cookie",saveStateName:"tree-grid-state",expanderTemplate:'<span class="treegrid-expander"></span>',indentTemplate:'<span class="treegrid-indent"></span>',expanderExpandedClass:"treegrid-expander-expanded",expanderCollapsedClass:"treegrid-expander-collapsed",treeColumn:0,getExpander:function(){return a(this).find(".treegrid-expander")},getNodeId:function(){var b=/treegrid-([A-Za-z0-9_-]+)/;return b.test(a(this).attr("class"))?b.exec(a(this).attr("class"))[1]:null},getParentNodeId:function(){var b=/treegrid-parent-([A-Za-z0-9_-]+)/;return b.test(a(this).attr("class"))?b.exec(a(this).attr("class"))[1]:null},getNodeById:function(a,b){var c="treegrid-"+a;return b.find("tr."+c)},getChildNodes:function(a,b){var c="treegrid-parent-"+a;return b.find("tr."+c)},getTreeGridContainer:function(){return a(this).closest("table")},getRootNodes:function(b){var c=a.grep(b.find("tr"),function(b){var c=a(b).attr("class"),d=/treegrid-([A-Za-z0-9_-]+)/,e=/treegrid-parent-([A-Za-z0-9_-]+)/;return d.test(c)&&!e.test(c)});return a(c)},getAllNodes:function(b){var c=a.grep(b.find("tr"),function(b){var c=a(b).attr("class"),d=/treegrid-([A-Za-z0-9_-]+)/;return d.test(c)});return a(c)},onCollapse:null,onExpand:null,onChange:null}}(jQuery);
\ No newline at end of file