﻿Ext.ux.ClientDeviceMetadataGridPanel = Ext.extend(Ext.ux.MetadataGridPanel, {

    // standard initializer
    initComponent: function() {
        Ext.ux.ClientDeviceMetadataGridPanel.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.ClientDeviceMetadataGridView({ 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.ClientDeviceMetadataGridPanel.superclass.onRowContextMenu.call(this, grid, rowIndex, e);
    },


    // ------ context menu creation helper functions ------ //

    // create the context menu
    createActionsContextMenu: function(grid, rowIndex) {
        var selections  = this.getSelections();
        var contextMenu = this.createEmptyActionsContextMenu();
        
        contextMenu = this.addMetadataStreamingMenuItems(contextMenu, rowIndex);

        // extract the type from the first item
        var type    = selections[0].data.type;
        var idArray = idHelper_createIdArray(selections);

        contextMenu.add(new Ext.menu.Item({
            text: g_resourceStrings['Js_TracksGrid_PopupMenu_AddToUploads'],
            handler: function() { clientDeviceMetadataGridPanel_handleAddToUploadQueueClicked(type, idArray); }
        }));

        // add any generic menu items
        contextMenu = this.addGenericMenuItems(grid, contextMenu, rowIndex);

        return contextMenu;
    }
});

Ext.ux.ClientDeviceMetadataGridView = Ext.extend(Ext.ux.MetadataGridView, {
});

Ext.ux.ClientDeviceMetadataGridDragZone = Ext.extend(Ext.ux.MetadataGridDragZone, {
});


// ------ context menu item click handler functions ------ //

// Add menu item clicked from master
function clientDeviceMetadataGridPanel_handleAddToUploadQueueClicked(type, idArray) {

    var deviceId = clientDevicesPanelHelper.getDeviceId();

    // set the queue status
    ajax_setQueueStatus(deviceId, g_cloud_deviceId, type, idArray, true, g_lowUserPriorityDefault, false);
}