/// class PD.Web.UI.Controls.ViewGridColumnMenuSegment
/// using PD.Web.UI.Controls.ContextMenuSegment

PD.Web.UI.Controls.ViewGridColumnMenuSegment =
PD.Web.UI.Controls.ContextMenuSegment.extend({

    //===================================
    // PROPERTIES
    //===================================

    get_viewGrid: function () {
        return this.get_context();
    },

    //===================================
    // EVENT HANDLERS
    //===================================

    onRegisterItems: function (e) {

        var contextId = this.get_viewGrid().get_id()

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/filter"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/remove-filter"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/clear-all-filters"
        }));

        e.addSeparator();

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/add-columns-left"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/add-columns-right"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/remove"
        }));

        e.addSeparator();

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/sort-ascending"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/sort-descending"
        }));

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/remove-sort"
        }));

        e.addSeparator();

        e.registerItem(new PD.Web.UI.Controls.ContextMenuCommandItem({
            contextId: contextId,
            commandId: "pd/view-grid/column/context-menu:column/remove-all-sort"
        }));

    },

    onOpen: function (e) {
        
        var contextId = this.get_viewGrid().get_id(),
            commandContext = PD.context.getContextById(contextId).get_commands();

        commandContext.setState({
            "pd/view-grid/column/context-menu": {
                viewGrid: this.get_viewGrid(),
                columnId: $(e.target).closest(".k-header").data("field")
            }
        });

    }

});