Skip to content

Commit 3f2e254

Browse files
author
Mike Bethany
committed
Moved upload and download templates out of index
1 parent 3eb252c commit 3f2e254

File tree

4 files changed

+81
-79
lines changed

4 files changed

+81
-79
lines changed

app/models/upload.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
class Upload < ActiveRecord::Base
2-
attr_accessible :upload
3-
has_attached_file :upload,
4-
styles: {
5-
original: "600x600>",
6-
thumbnail: "40x40#"
7-
}
1+
class Upload < ActiveRecord::Base
2+
attr_accessible :upload
3+
has_attached_file :upload,
4+
styles: {
5+
original: "600x600>",
6+
thumbnail: "40x40#"
7+
}
88

99

10-
include Rails.application.routes.url_helpers
10+
include Rails.application.routes.url_helpers
1111

12-
def to_jq_upload
13-
{
14-
"name" => read_attribute(:upload_file_name),
15-
"size" => read_attribute(:upload_file_size),
16-
"url" => upload.url(:original),
17-
"delete_url" => upload_path(self),
18-
"delete_type" => "DELETE",
19-
"thumbnail_url" => upload.url(:thumbnail)
20-
}
21-
end
12+
def to_jq_upload
13+
{
14+
"name" => read_attribute(:upload_file_name),
15+
"size" => read_attribute(:upload_file_size),
16+
"url" => upload.url(:original),
17+
"delete_url" => upload_path(self),
18+
"delete_type" => "DELETE",
19+
"thumbnail_url" => upload.url(:thumbnail)
20+
}
21+
end
2222

23-
end
23+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- The template to display files available for download -->
2+
<script id="template-download" type="text/x-tmpl">
3+
{% for (var i=0, file; file=o.files[i]; i++) { %}
4+
<tr class="template-download fade">
5+
{% if (file.error) { %}
6+
<td></td>
7+
<td class="name"><span>{%=file.name%}</span></td>
8+
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
9+
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
10+
{% } else { %}
11+
<td class="preview">{% if (file.thumbnail_url) { %}
12+
<a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
13+
{% } %}</td>
14+
<td class="name">
15+
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
16+
</td>
17+
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
18+
<td colspan="2"></td>
19+
{% } %}
20+
<td class="delete">
21+
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
22+
<i class="icon-trash icon-white"></i>
23+
<span>{%=locale.fileupload.destroy%}</span>
24+
</button>
25+
<input type="checkbox" name="delete" value="1">
26+
</td>
27+
</tr>
28+
{% } %}
29+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- The template to display files available for upload -->
2+
<script id="template-upload" type="text/x-tmpl">
3+
{% for (var i=0, file; file=o.files[i]; i++) { %}
4+
<tr class="template-upload fade">
5+
<td class="preview"><span class="fade"></span></td>
6+
<td class="name"><span>{%=file.name%}</span></td>
7+
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
8+
{% if (file.error) { %}
9+
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
10+
{% } else if (o.files.valid && !i) { %}
11+
<td>
12+
<div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
13+
</td>
14+
<td class="start">{% if (!o.options.autoUpload) { %}
15+
<button class="btn btn-primary">
16+
<i class="icon-upload icon-white"></i>
17+
<span>{%=locale.fileupload.start%}</span>
18+
</button>
19+
{% } %}</td>
20+
{% } else { %}
21+
<td colspan="2"></td>
22+
{% } %}
23+
<td class="cancel">{% if (!i) { %}
24+
<button class="btn btn-warning">
25+
<i class="icon-ban-circle icon-white"></i>
26+
<span>{%=locale.fileupload.cancel%}</span>
27+
</button>
28+
{% } %}</td>
29+
</tr>
30+
{% } %}
31+
</script>

app/views/uploads/index.html.erb

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -51,66 +51,8 @@
5151
};
5252
</script>
5353

54-
<!-- The template to display files available for upload -->
55-
<script id="template-upload" type="text/x-tmpl">
56-
{% for (var i=0, file; file=o.files[i]; i++) { %}
57-
<tr class="template-upload fade">
58-
<td class="preview"><span class="fade"></span></td>
59-
<td class="name"><span>{%=file.name%}</span></td>
60-
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
61-
{% if (file.error) { %}
62-
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
63-
{% } else if (o.files.valid && !i) { %}
64-
<td>
65-
<div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
66-
</td>
67-
<td class="start">{% if (!o.options.autoUpload) { %}
68-
<button class="btn btn-primary">
69-
<i class="icon-upload icon-white"></i>
70-
<span>{%=locale.fileupload.start%}</span>
71-
</button>
72-
{% } %}</td>
73-
{% } else { %}
74-
<td colspan="2"></td>
75-
{% } %}
76-
<td class="cancel">{% if (!i) { %}
77-
<button class="btn btn-warning">
78-
<i class="icon-ban-circle icon-white"></i>
79-
<span>{%=locale.fileupload.cancel%}</span>
80-
</button>
81-
{% } %}</td>
82-
</tr>
83-
{% } %}
84-
</script>
85-
<!-- The template to display files available for download -->
86-
<script id="template-download" type="text/x-tmpl">
87-
{% for (var i=0, file; file=o.files[i]; i++) { %}
88-
<tr class="template-download fade">
89-
{% if (file.error) { %}
90-
<td></td>
91-
<td class="name"><span>{%=file.name%}</span></td>
92-
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
93-
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
94-
{% } else { %}
95-
<td class="preview">{% if (file.thumbnail_url) { %}
96-
<a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
97-
{% } %}</td>
98-
<td class="name">
99-
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
100-
</td>
101-
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
102-
<td colspan="2"></td>
103-
{% } %}
104-
<td class="delete">
105-
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
106-
<i class="icon-trash icon-white"></i>
107-
<span>{%=locale.fileupload.destroy%}</span>
108-
</button>
109-
<input type="checkbox" name="delete" value="1">
110-
</td>
111-
</tr>
112-
{% } %}
113-
</script>
54+
<%== render "upload_template" %>
55+
<%== render "download_template" %>
11456

11557
<script type="text/javascript" charset="utf-8">
11658
$(function () {

0 commit comments

Comments
 (0)