PDA

View Full Version : Toobar item.


Animal
10-02-2006, 04:39 AM
Would it be possible to have a toolbar item be an anchor (an <a href=""> element)?

Currently, one supplies an onclick handler.

I've tried setting


toolbar.addButton({
text:"&nbsp ('" + pdfUrl + "')",
className: 'pdf-button',
tooltip: "View as PDF"
});
toolbar.addButton({
text:"&nbsp ('" + excelUrl + "')",
className: 'excel-button',
tooltip: "View as Excel"
});


But the <A> element doesn't occupy the whole of the button, you have to "aim" your clicks at just the right place and keep an eye on the statusbar to see when you are over a link.

I have some nice methods to automagically generate a nicely featured spreadsheet, or a PDF from the backend object which feeds my Grid.

jack.slocum
10-02-2006, 05:30 AM
Just wondering, how come you can't do something like:

function onClick(url, newWindow){
if(newWindow){
window.open(url);
} else {
window.location = url;
}
}

toolbar.addButton({
className: 'pdf-button',
tooltip: "View as PDF"
click: onClick.createCallback('url-to-pdf', true)
});

toolbar.addButton({
className: 'excel-button',
tooltip: "View as Excel"
click: onClick.createCallback('url-to-excel', false)
});


If that doesn't work there is another solution.

Animal
10-02-2006, 06:36 AM
The reason is the way browsers handle inline and attachments of different content-types. I want documents to be in a new window - but Firefox can't embed Excel into a page. So what I want is to have PDFs inline in a new browser window, and Excel opened as an attachment.

The PDF generation uses "content-disposition:inline". This could be changed to a window.open().

Excel likes to be opened in the same window, but with "content-disposition:attachment" so that it doesn't overwrite the document but opens in an instance of Excel. This situation - opening in the same window... I'll try setting document.location.href - but that might actually destroy the current document which isn't what I want.

Animal
10-02-2006, 06:48 AM
It's OK, I changed it to:


toolbar.addButton({
className: 'pdf-button',
tooltip: "View as PDF",
click: function()
{
window.open(pdfUrl);
}
});
toolbar.addButton({
className: 'excel-button',
tooltip: "View as Excel",
click: function()
{
window.location.href = excelUrl;
}
});


And that seems to work.

jack.slocum
10-02-2006, 07:16 AM
I was going to say, window.open should work the same as _blank.

BTW, the ToolbarButton class is pretty simple. If you did want to make it an A with display:block instead of a span, I'm sure it would easy.

Animal
10-03-2006, 10:21 AM
Of course I've just come up against the reason why they should be links rather than onclicks.

So that I can do right click, Save As...

I'll have to change the ToolbarItem class.