﻿Ext.ux.ClientDeviceFileGridPanel = Ext.extend(Ext.ux.FileHashGridPanel, {

    // standard initializer
    initComponent: function() {
        Ext.ux.ClientDeviceFileGridPanel.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.ClientDeviceFileGridView({ 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.ClientDeviceFileGridPanel.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);

        var fileHashIdArray = fileHashHelper_createFileHashIdArray(selections);

        contextMenu.add(new Ext.menu.Item({
            text: g_resourceStrings['Js_TracksGrid_PopupMenu_AddToUploads'],
            handler: function() { clientDeviceFileGridPanel_handleAddToUploadQueueClicked(fileHashIdArray); }
        }));

        // add any generic menu items
        contextMenu = this.addGenericMenuItems(grid, contextMenu, rowIndex);

        return contextMenu;
    }
});

Ext.ux.ClientDeviceFileGridView = Ext.extend(Ext.ux.FileHashGridView, { 
});

// configure drag & drop
Ext.ux.ClientDeviceFileGridDragZone = Ext.extend(Ext.ux.FileHashGridDragZone, {
});


// ------ context menu item click handler functions ------ //

// AddToUploadQueue menu item clicked
function clientDeviceFileGridPanel_handleAddToUploadQueueClicked(fileHashIdArray) {

    var deviceId = clientDevicesPanelHelper.getDeviceId();

    // set the queue status
    ajax_setQueueStatus(deviceId, g_cloud_deviceId, g_extJsGrid_dataTypeFileHash, fileHashIdArray, true, g_lowUserPriorityDefault, false);
}