﻿Ext.ux.DownloadGridPanel = Ext.extend(Ext.ux.ClientDeviceFileGridPanel, {

    // internal fields
    m_gridType: null,


    // standard initializer
    initComponent: function() {
        Ext.ux.DownloadGridPanel.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.DownloadGridView({ scrollOffset: g_gridScrollOffset })
        };

        Ext.apply(this, config);
        Ext.apply(this.initialConfig, config);

        this.on('rowcontextmenu', this.onRowContextMenu, this);
    },


    // ------ event handler functions ------ //
    
    // row context menu
    onRowContextMenu: function(grid, rowIndex, e) {
        this.contextMenu = this.createActionsContextMenu(grid, rowIndex);

        Ext.ux.DownloadGridPanel.superclass.onRowContextMenu.call(this, grid, rowIndex, e);
    },


    // ------ context menu creation helper functions ------ //

    // create the context menu
    createActionsContextMenu: function(grid, rowIndex) {
        var selections  = this.getSelections(rowIndex);
        var contextMenu = this.createEmptyActionsContextMenu();
        
        contextMenu = this.addStreamingMenuItems(contextMenu, rowIndex);

        contextMenu.add(new Ext.menu.Item({
            text: g_resourceStrings['Js_TransfersGrid_PopupMenu_RemoveFromDownloads'],
            handler: function() { downloadGridPanel_handleRemoveFromDownloadQueueClicked(); }
        }));

        // add any generic menu items
        contextMenu = this.addGenericMenuItems(grid, contextMenu, rowIndex);

        return contextMenu;
    }
});

Ext.ux.DownloadGridView = Ext.extend(Ext.ux.ClientDeviceFileGridView, {
});

// configure drag & drop
Ext.ux.DownloadGridDragZone = Ext.extend(Ext.ux.ClientDeviceFileGridDragZone, {
});


// ------ context menu handler functions ------ //

function downloadGridPanel_handleRemoveFromDownloadQueueClicked() {
    showRemoveSelectedTracksFromDownloadQueueModalForm();
}