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