possible to listen for file download from LABKEY.ext.EditorGridPanel?

LabKey Support Forum (Inactive)
possible to listen for file download from LABKEY.ext.EditorGridPanel? Ben Bimber  2010-05-21 15:50
Status: Closed
 
I have a page with a LABKEY.ext.EditorGridPanel. One of the columns is a file attachment. Is it possible to listen for when a user downloads a file and trigger a function that inserts on record whenever this event occurs?
 
 
Matthew Bellew responded:  2010-05-22 14:38
Are you specifically interested in when a user downloads the file from this particular page, or would you like an audit like function where you could see all downloads regardless of where they happened?
 
Ben Bimber responded:  2010-05-22 14:45
one specific page. we have a page where users view PDFs of SOPs (standard operating procedures). this page has a grid with somewhere from 5-60 rows, one per PDF. it's a LABKEY.ext.EditorGridPanel. i used this instead of the labkey grid b/c it's loaded from a store filtered on user ID.

i'd like to create a mechanism such that we can record when a user downloads each of their SOPs. is that possible?

if there's no way to listen for file-download, then the next best solution i can think of is to create a 'mark read' button, but this is less automatic.
 
jeckels responded:  2010-05-23 09:18
Hi Ben,

There's no specific support for this, but it sound like the best approach for this particular case might be to swap out a custom column renderer into your grid. You could replace the default URL with an onclick handler that inserts a record into a list (or other table) and then opens the PDF in the browser.

Thanks,
Josh
 
Ben Bimber responded:  2010-05-25 06:47
hi josh -

that sounds like a good approach. is there an example of this somewhere in labkey where you could point me? if not, maybe we could discuss on thursday's call?
 
jeckels responded:  2010-05-25 17:43
Hi Ben,

There's some sample code in the documentation for LABKEY.ext.EditorGridPanel that shows how you can replace a column's renderer. You should be able to use it as a base to swap in a renderer that builds up HTML that includes an onclick handler that calls a function that inserts the record into the list and then lets the user view the content they requested.

Thanks,
Josh
 
Ben Bimber responded:  2010-05-26 09:26
ok, i've got a start on this and have a few questions:

1. according to the ext documentation, I should be able to specify a custom columnModel with an EditorGridPanel:

        var sopGrid = new LABKEY.ext.EditorGridPanel({
            store: new LABKEY.ext.Store({..})
            ,renderTo: 'sopDiv'
            ,width: 1000
            ,cm: new Ext.grid.ColumnModel({..})
        });

When the LABKEY.ext.EditorGridPanel first renders, my custom colModel is applied, but as soon as the Labkey store loads (and rows are populated) my custom colModel gets overridden by the default labkey behavior. Is there any way to define a custom colModel beforehand (in the store or something?), or do I need to add a handler to alter the colModel using the 'colmodelcustomize' event?


2. following the example in the labkey documentation for LABKEY.ext.EditorGridPanel, I can add a custom renderer. however, what's the right approach to add an onClick handler? following the example, we have something like:

function pdfRenderer(data, cellMetaData, record, rowIndex, colIndex, store)
{
   //run the existing renderer
   var theField = _basePdfRenderer(data, cellMetaData, record, rowIndex, colIndex, store);
   
   return theField;
}

in the above example, the default renderer produces a string with the URL for the file and display icon. what's the right point to manipulate this to add the handler? should I just discard the default renderer and build the URL / display icon HTML myself? can i somehow hook into this to add the handler in another way?

Hope this makes sense. Thanks for the help.