Download widget template improvements
Good day
It would be nice if I could define my own extra download templates like other templates as well. It seems there is no option yet to choose/create another.
Also the size for small documents is shown like 27,91 KB kilo bytes. I a time where we need 500 MB to run SF and a braoad band internet connection for all our content I think it would be enough to show 27 KB instead of 27,91 KB
See screenshot.
Markus
Hi Markus,
Yes there is no option to create new widget template and add it to the list of download list templates out of the box. I have logged the feature request, here is the link to pits.
For the bytes calculation create new template using the template for documents table (I have attached it here). Map the template to be used instead of the built in template by going to Administration->Settings->Advanced->ContentView->controls->Create new
Host: Telerik.Sitefinity.Modules.Libraries.Web.UI.Documents.MasterTableView
LayoutTemplate: ~/DocumentsTableView.ascx (relative path to the template in your project)
save changes and restart the project to use the mapped template.
In the code behind of the template I have subscribed to the databinding event of the grid that makes up the table of documents to download
void
documentsGrid_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
if
((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem))
var dataItem = e.Item.DataItem;
var gridItem = e.Item
as
GridDataItem;
var document = (Document)dataItem;
if
(document !=
null
)
var ext = document.Extension;
if
(ext.Length > 0)
ext = ext.Remove(0, 1);
gridItem.CssClass +=
" sf"
+ ext.ToLower();
TableCell typeCell = gridItem[
"documentType"
];
if
(typeCell !=
null
)
typeCell.Text = ext.ToUpperInvariant();
TableCell totalSizeCell = gridItem[
"totalSize"
];
if
(totalSizeCell !=
null
)
//here is the binding of bytes
totalSizeCell.Text =
this
.ConfigureBytes(document.TotalSize);
var documentLink = e.Item.FindControl(
"documentLink"
)
as
HyperLink;
if
(documentLink !=
null
)
documentLink.NavigateUrl = document.MediaUrl;
Dear Stanislav
Thanks for opening a PITS on this. I first proposed this in May 2011! Yes 1 1/2 years ago. www.sitefinity.com/.../download-link-download-list-dokuments-and-files
Steves post from Februar 2011! www.sitefinity.com/.../download-list-templates
I hope it does not take that long to implement some consistency here. Why can I choose templates on so many widgets but not on decument list is a secret to me.
-----------
About the KB download. Thank you for providing the solution. I don't feel like having to do this in every new project. I simply wished that Telerik would see that it does not make sense to show 24.79 KB and would change it so that out of the box you get 24,5 MB or if smaller 399 KB.
This would I guess help anyone here.
-----------
Markus
Yeah, no pickable templating has been a big pet peeve of mine since "RELEASE". I think it was one of the first controls likely created when they didn't have that functionality yet, and nobody has ever gone back to update the designer to support it.
(Just a guess)
Allmost a year later and I still miss the option to choose from different layoutwidget.
Markus
Also in Gallery
Dear Stanislav
Thanks for your solution from April 2013 but I don't want to extend SF on every new project to get some sense into the download widget.
a) 6.2 still not lets you choose different templates
b) I still think it would be nice if someone at Telerik found some time to fix the way size is displayed. See screenshot.
- I know its not a big deal
- I know I can work around it
But do my clients care if a document is 156 KB or 156,06 KB
Markus
Hello Markus,
The ability to select different templates have to be added to download list widget designer as new feature for the widget. Refer to the workaround and if you have need for another customization on the widget please let me know.
Regards,
Stanislav Velikov
Telerik
Dear Stanislav
Do I read you correctly? Telerik is not going to add the option to use different download templates and we have to do it ourself?
Markus
@Markus
I'll put money it's not fixed for 6.3....JustDecompile the widget and you can pretty much see why...
Other controls like the nav widget have their "Modes" but each "Mode" is just a new template (shapes the markup differently). The Download widget though seems to be pretty gimpy in the way it was designed.
Have a look at "Telerik.Sitefinity.Resources.Templates.Frontend.Libraries.Documents.MasterListView.ascx"...it's a repeater who's data is set IN THE CODE BEHIND instead of Eval statements in the markup for you to change....so even if you could change the markup in a new template you don't have the control you would want.
...the widget needs a re-write...not just a template picker. I shudder at this thought after twitter was given to someone to rewrite (more than once) and the end result was terrible both times, like no oversight...it's STILL terrible (who makes a client-side twitter widget when the data is pulled from SF publishing not twitter).
Steve
@Steve
This might be the reason for the do-it-yourself -> we are not going to do it answer from Stanislav (unless I did missread it totaly)
Markus
Hi,
The markup of download list template and most of the templates for sitefintiy widgets have the datasource toward which the template is bound available in a class outside of the widget template, based on this the provided approach to subscribe to documentsGrid_ItemDataBound event is the way to handle customization on this template.
I can provide you with another approaches for having control over the whole class includes the download list implementation where additional functionality/modifications can be injected to server certain business case.
Dear Stanislav
Thanks for the option of an another approach and again thanks for the code for the workaround.
Acutally I would prefer Telerik simply doing this for every single Sitefinity user in the world and like on other widgets give as the option to choose. Well we can make different download widget in the designer just choosing them is a pain in the neck - And for every project must be done again.
I assume that I have not missread all the comments and we will not get the option to choose different widgets on the download template anytime soon - or anytime.
Markus
PS: But I am sure 6.3 will bring a lot of other new features we can be looking for. Guess you can close this thread :-(
@Markus I'm with you 100% on this...Stanislav doesn't understand the problem.
We're not looking to extend functionality, we're looking to do what we can do with 98% of the other widgets...change and create new templates. Without this functionality you're telling us we have to use the same markup for EVERY download widget across the entire site...which is crazy.
Steve
Sorry to bring this up again.
But now I have a project where I am in the need of having two templates.
After 3 years it is still not possible. You can create different widget templates but use only the default. Unless I am missing something again.
Even modules created with module builder let you choose templates: www.marktold.com/screencast/sf_7_0_tempaltes.swf
Markus
PS: @Steve you were right about 6.3 :-)
Hi Markus,
Since the desired implementation is not yet available out of the box a custom solution should be used if you require the control to be able to display different templates throughout the project. The below example uses the List type for simplicity's sake, but this can be implemented for the other view types the controls uses (Table, List+Detail page, Table+Detail page).
The List view type uses MasterListView control. By inheriting from this control and overriding the LayoutTemplatePath property you can conditionally pass different templates to the view like so:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
Telerik.Sitefinity.Modules.Libraries.Web.UI.Documents;
namespace
SitefinityWebApp
public
class
CustomMasterListView : MasterListView
public
override
string
LayoutTemplatePath
get
if
(SiteMap.CurrentNode.Title ==
"Test"
)
//Define whatever criteria you find suitable
return
"~/CustomDownloadListTemplate.ascx"
;
else
return
base
.LayoutTemplatePath;
set
base
.LayoutTemplatePath = value;
Thanks Pavel for the work around.
Somehow I have the feeling is not quit es flexibel :-)
Markus