4eb4251d7b69d4a43f1693737fa54ba90cf1ed81
[redakcja.git] / src / fileupload / templatetags / upload_tags.py
1 from django import template
2 from django.utils.safestring import mark_safe
3
4 register = template.Library()
5
6 @register.simple_tag
7 def upload_js():
8     return mark_safe("""
9 <!-- The template to display files available for upload -->
10 <script id="template-upload" type="text/x-tmpl">
11 {% for (var i=0, file; file=o.files[i]; i++) { %}
12     <tr class="template-upload fade">
13         <td class="preview"><span class="fade"></span></td>
14         <td class="name"><span>{%=file.name%}</span></td>
15         <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
16         {% if (file.error) { %}
17             <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
18         {% } else if (o.files.valid && !i) { %}
19             <td>
20                 <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
21             </td>
22             <td class="start">{% if (!o.options.autoUpload) { %}
23                 <button class="btn btn-success">
24                     <i class="icon-upload icon-white"></i>
25                     <span>{%=locale.fileupload.start%}</span>
26                 </button>
27             {% } %}</td>
28         {% } else { %}
29             <td colspan="2"></td>
30         {% } %}
31         <td class="cancel">{% if (!i) { %}
32             <button class="btn btn-warning">
33                 <i class="icon-ban-circle icon-white"></i>
34                 <span>{%=locale.fileupload.cancel%}</span>
35             </button>
36         {% } %}</td>
37     </tr>
38 {% } %}
39 </script>
40 <!-- The template to display files available for download -->
41 <script id="template-download" type="text/x-tmpl">
42 {% for (var i=0, file; file=o.files[i]; i++) { %}
43     <tr class="template-download fade">
44         {% if (file.error) { %}
45             <td></td>
46             <td class="name"><span>{%=file.name%}</span></td>
47             <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
48             <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
49         {% } else { %}
50             <td class="preview">{% if (file.thumbnail_url) { %}
51                 <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
52             {% } %}</td>
53             <td class="name">
54                 <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
55             </td>
56             <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
57             <td colspan="2"></td>
58         {% } %}
59         <td class="delete">
60             <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
61                 <i class="icon-trash icon-white"></i>
62                 <span>{%=locale.fileupload.destroy%}</span>
63             </button>
64             <input type="checkbox" name="delete" value="1">
65         </td>
66     </tr>
67 {% } %}
68 </script>
69 """)