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