1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 22:01:06 +00:00

[favorites] show thumbnail for image files

This commit is contained in:
llj
2017-04-01 16:59:17 +08:00
parent f40aa6341b
commit ab67b1b5a3
3 changed files with 62 additions and 2 deletions

View File

@@ -1165,7 +1165,13 @@
</tr> </tr>
</script> </script>
<script type="text/template" id="starred-file-item-tmpl"> <script type="text/template" id="starred-file-item-tmpl">
<td class="alc"><img src="{{ MEDIA_URL }}img/file/<%= icon_path %>" alt="{% trans "icon" %}" /></td> <td class="alc">
<% if (encoded_thumbnail_src) { %>
<img class="thumbnail" src="{{ SITE_ROOT }}<%= encoded_thumbnail_src %>" alt="" />
<% } else { %>
<img src="{{ MEDIA_URL }}img/file/<%= icon_path %>" alt="{% trans "icon" %}" />
<% } %>
</td>
<td> <td>
<% if (is_img) { %> <% if (is_img) { %>
<a class="img-name-link" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<%- encoded_path %>" target="_blank" data-mfp-src="{{ SITE_ROOT }}repo/<%= repo_id %>/raw<%- encoded_path %>"><%- file_name %></a> <a class="img-name-link" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<%- encoded_path %>" target="_blank" data-mfp-src="{{ SITE_ROOT }}repo/<%= repo_id %>/raw<%- encoded_path %>"><%- file_name %></a>
@@ -1180,7 +1186,13 @@
</td> </td>
</script> </script>
<script type="text/template" id="starred-file-item-mobile-tmpl"> <script type="text/template" id="starred-file-item-mobile-tmpl">
<td class="alc"><img src="{{ MEDIA_URL }}img/file/<%= icon_path %>" alt="{% trans "icon" %}" /></td> <td class="alc">
<% if (encoded_thumbnail_src) { %>
<img class="thumbnail" src="{{ SITE_ROOT }}<%= encoded_thumbnail_src %>" alt="" />
<% } else { %>
<img src="{{ MEDIA_URL }}img/file/<%= icon_path %>" alt="{% trans "icon" %}" />
<% } %>
</td>
<td> <td>
<% if (is_img) { %> <% if (is_img) { %>
<a class="img-name-link" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<%- encoded_path %>" target="_blank" data-mfp-src="{{ SITE_ROOT }}repo/<%= repo_id %>/raw<%- encoded_path %>"><%- file_name %></a> <a class="img-name-link" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<%- encoded_path %>" target="_blank" data-mfp-src="{{ SITE_ROOT }}repo/<%= repo_id %>/raw<%- encoded_path %>"><%- file_name %></a>

View File

@@ -19,6 +19,8 @@ define([
initialize: function() { initialize: function() {
HLItemView.prototype.initialize.call(this); HLItemView.prototype.initialize.call(this);
this.listenTo(this.model, "change", this.render);
}, },
render: function () { render: function () {
@@ -26,6 +28,7 @@ define([
data['is_img'] = Common.imageCheck(data['file_name']); data['is_img'] = Common.imageCheck(data['file_name']);
data['encoded_path'] = Common.encodePath(data['path']); data['encoded_path'] = Common.encodePath(data['path']);
data.encoded_thumbnail_src = this.model.get('encoded_thumbnail_src') || '';
var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate; var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate;
this.$el.html(tmpl(data)); this.$el.html(tmpl(data));

View File

@@ -35,12 +35,57 @@ define([
this.renderThead(); this.renderThead();
this.starredFiles.each(this.addOne, this); this.starredFiles.each(this.addOne, this);
this.$table.show(); this.$table.show();
this.getImageThumbnail();
} else { } else {
this.$emptyTip.show(); this.$emptyTip.show();
this.$table.hide(); this.$table.hide();
} }
}, },
getImageThumbnail: function() {
if (!app.pageOptions.enable_thumbnail) {
return false;
}
var images = this.starredFiles.filter(function(item) {
// 'item' is a model
return Common.imageCheck(item.get('file_name'));
});
if (images.length == 0) {
return ;
}
var images_len = images.length;
var thumbnail_size = app.pageOptions.thumbnail_default_size;
var get_thumbnail = function(i) {
var cur_img = images[i];
$.ajax({
url: Common.getUrl({
name: 'thumbnail_create',
repo_id: cur_img.get('repo_id')
}),
data: {
'path': cur_img.get('path'),
'size': thumbnail_size
},
cache: false,
dataType: 'json',
success: function(data) {
cur_img.set({
'encoded_thumbnail_src': data.encoded_thumbnail_src
});
},
complete: function() {
if (i < images_len - 1) {
get_thumbnail(++i);
}
}
});
};
get_thumbnail(0);
},
showStarredFiles: function() { showStarredFiles: function() {
this.$table.hide(); this.$table.hide();
this.$loadingTip.show(); this.$loadingTip.show();