/// class PD.Web.UI.Controls.GridColumnProperties

PD.Web.UI.Controls.GridColumnProperties = Class.extend({

    //===================================
    // FIELDS
    //===================================

    _data: null,

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function (data) {
        this._data = _.extend({}, data);
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    getAll: function () {
        return this._data;
    },

    getValue: function (path) {

        var result = null;

        this.iterateData(path, false, function (e) {
            if (e.complete) {
                result = e.value;
            }
        });

        return result;

    },

    setValue: function (path, value, safe) {

        this.iterateData(path, safe, function (e) {
            if (e.complete) {
                e.parent[e.key] = value;
            }
        });

    },
    
    appendToValue: function (path, value, separator) {

        var result = this.getValue(path);

        if (value == null) {
            result = value;
        }
        else {
            result += (separator != null ? separator : "") + value
        }
        
        this.setValue(path, result, true);
        
    },
    
    iterateData: function (path, safe, fn) {

        var keys = [];
        var item = this._data;
        var parent = null;

        if (path != null) {
            keys = path.split(".");
        }

        for (var i = 0; i < keys.length; i++) {

            parent = item;

            if (item[keys[i]] !== undefined) {
                item = item[keys[i]];
            }
            else {
                if (safe && i < keys.length - 1) {
                    item[keys[i]] = {};
                }
            }

            fn({
                parent: parent,
                value: item,
                key: keys[i],
                complete: i == keys.length - 1
            });

        }
        
    }

});