/**
@class TreeView
@namespace ProspectDirector.Types.KendoExtensions
**/
ProspectDirector.Types.KendoExtensions.TreeView = function () {

};

//---------------------------
//--- STATIC PROPERTIES
//---------------------------

/**
@property tempNodeText {string}
@static
**/
ProspectDirector.Types.KendoExtensions.TreeView.tempNodeText = "{node:identifier}";

//---------------------------
//--- STATIC METHODS
//---------------------------

/**
@method newAdd 
@return {Object}
**/
ProspectDirector.Types.KendoExtensions.TreeView.addNode = function (treeView, options) {

    var node = null;

    options = ProspectDirector.Types.KendoExtensions.TreeView.prepareOptions(options);

    treeView.append({
        text: ProspectDirector.Types.KendoExtensions.TreeView.tempNodeText
    }, options.parent);

    node = treeView.findByText(ProspectDirector.Types.KendoExtensions.TreeView.tempNodeText);

    ProspectDirector.Types.KendoExtensions.TreeView.prepareNode(node, options);

    return node;

};

/**
@method setContent 
@return {Object}
**/
ProspectDirector.Types.KendoExtensions.TreeView.parent = function (treeView, node) {

    return node.closest(".k-group").closest(".k-item");

};

/**
Determines if an element is a root node of the tree view.
@method isRootNode
@return {Boolean}
**/
ProspectDirector.Types.KendoExtensions.TreeView.prepareNode = function (node, options) {

    node.attr(options.attributes);

    if (options.data !== null) {
        for (prop in options.data) {
            node.attr("data-" + prop, options.data[prop]);
        }
    }

    node.find(".k-in").first().html(options.text);

};

ProspectDirector.Types.KendoExtensions.TreeView.prepareOptions = function (options) {
    
    return $.extend({
        parent: null,
        text: null,
        info: {},
        attributes: {},
        data: null
    }, options);

};