/// class PD.Web.UI.Controls.GridRowContextMenuModule
/// using PD.Web.UI.Controls.GridModule

PD.Web.UI.Controls.GridRowContextMenuModule =
PD.Web.UI.Controls.GridModule.extend({

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

    start: function () {

        var option = this.getOption("contextMenu");

        if (_.isFunction(option)) {
            option();
            return;
        }

        if (_.isArray(option) || _.isObject(option)) {

            var contextMenu = new PD.Web.UI.Controls.ContextMenu({
                target: this.get_kendo().content,
                filter: "TR[role=row][data-uid]",
                segments: this._getSegments(),
                animation: false
            });

            this.get_grid().get_children().add(contextMenu);
            return;

        }

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _getSegments: function () {

        var segments = this.getOption("contextMenu", []);
    
        if (!$.isArray(segments)) {
            segments = [segments];
        }

        segments = this._transformSegments(segments);

        return segments;

    },

    _transformSegments: function (segments) {

        var that = this,
            result = new PD.BCL.List(segments);

        result = result.transform(function (item) {
            var type = PD.Type.getType(item.type);
            return new type($.proxy(item.context, that.get_grid()));
        });

        return result.toArray();

    }

});