﻿Ext.ux.ChartGridPanel = Ext.extend(Ext.ux.TracksGridPanelBase, {

    // internal fields
    m_chartId: g_default_xPOPropertyId,


    // standard initializer
    initComponent: function() {
        Ext.ux.ChartGridPanel.superclass.initComponent.apply(this, arguments);

        // args have to go here as base class initComponent doesn't get called for some reason
        var config = {
            view: new Ext.ux.ChartGridView({ scrollOffset: g_gridScrollOffset })
        };

        Ext.apply(this, config);
        Ext.apply(this.initialConfig, config);

        this.on('rowcontextmenu', this.onRowContextMenu, this);
        this.on('rowdblclick', this.onRowDblClick, this);
    },


    setCurrentId: function(chartId) {
        this.m_chartId = chartId;
    },

    getCurrentId: function() {
        return this.m_chartId;
    },

    onRowContextMenu: function(grid, rowIndex, e) {
        this.contextMenu = this.createActionsContextMenu(grid, rowIndex);

        Ext.ux.ChartGridPanel.superclass.onRowContextMenu.call(this, grid, rowIndex, e);
    },

    onRowDblClick: function() {  
        if (g_showStreamingMenuItems) {
            var selections = this.getSelectionModel().getSelections();
            var oneOrMoreTracksStreamable = this.isOneOrMoreTracksStreamable(selections);
            var fileHashIdArray = this.createIdArray(g_extJsGrid_dataTypeTrack, selections);

            if (oneOrMoreTracksStreamable) {
                tracksGrid_handlePlayClicked(fileHashIdArray);
            }
        }
    },

    // ------ context menu creation helper functions ------ //

    // create a context menu
    createActionsContextMenu: function(grid, rowIndex) {
        var contextMenu = this.createEmptyActionsContextMenu();
        contextMenu = this.addStreamingMenuItems(contextMenu, rowIndex);

        contextMenu.add(new Ext.menu.Item({
            text: g_resourceStrings['Js_Grid_PopupMenu_SelectAll'],
            handler: function() { grid.getSelectionModel().selectAll(); }
        }));

        return contextMenu;
    }
});

Ext.ux.ChartGridView = Ext.extend(Ext.ux.TracksGridViewBase, {

    afterRender: function() {
        Ext.ux.ChartGridView.superclass.afterRender.call(this, arguments);
        this.dragZone = new Ext.ux.ChartGridDragZone(this.grid, { ddGroup: "" });
    }
});

// configure drag & drop
Ext.ux.ChartGridDragZone = Ext.extend(Ext.ux.TracksGridDragZoneBase, {
});

Ext.ux.ChartDropTarget = Ext.extend(Ext.ux.TracksDropTargetBase, {
});