2015-05-04 09:02:20 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'jquery.magnific-popup',
|
|
|
|
'app/views/starred-file-item',
|
2017-09-18 07:38:26 +00:00
|
|
|
'app/collections/starred-files'
|
2015-05-04 09:02:20 +00:00
|
|
|
], function($, _, Backbone, Common, magnificPopup, StarredFileItem,
|
|
|
|
StarredFilesCollection) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var StarredFileView = Backbone.View.extend({
|
2017-12-05 09:53:45 +00:00
|
|
|
el: '.main-panel',
|
2015-05-04 09:02:20 +00:00
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
template: _.template($('#starred-file-tmpl').html()),
|
2016-12-15 08:54:51 +00:00
|
|
|
theadTemplate: _.template($('#starred-file-thead-tmpl').html()),
|
2015-05-04 09:02:20 +00:00
|
|
|
|
|
|
|
initialize: function() {
|
2016-03-24 06:43:20 +00:00
|
|
|
this.starredFiles = new StarredFilesCollection();
|
|
|
|
this.listenTo(this.starredFiles, 'reset', this.reset);
|
|
|
|
},
|
|
|
|
|
|
|
|
addOne: function(starredFile) {
|
|
|
|
var view = new StarredFileItem({model: starredFile});
|
|
|
|
this.$tableBody.append(view.render().el);
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.$tableBody.empty();
|
|
|
|
this.$loadingTip.hide();
|
|
|
|
if (this.starredFiles.length) {
|
|
|
|
this.$emptyTip.hide();
|
2016-12-15 08:54:51 +00:00
|
|
|
this.renderThead();
|
|
|
|
this.starredFiles.each(this.addOne, this);
|
2016-03-24 06:43:20 +00:00
|
|
|
this.$table.show();
|
2017-04-19 08:21:33 +00:00
|
|
|
this.getThumbnail();
|
2016-03-24 06:43:20 +00:00
|
|
|
} else {
|
|
|
|
this.$emptyTip.show();
|
|
|
|
this.$table.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-19 08:21:33 +00:00
|
|
|
getThumbnail: function() {
|
2017-04-01 08:59:17 +00:00
|
|
|
if (!app.pageOptions.enable_thumbnail) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-19 08:21:33 +00:00
|
|
|
var items = this.starredFiles.filter(function(item) {
|
2017-04-01 08:59:17 +00:00
|
|
|
// 'item' is a model
|
2017-04-19 08:21:33 +00:00
|
|
|
return Common.imageCheck(item.get('file_name')) || Common.videoCheck(item.get('file_name'));
|
2017-04-01 08:59:17 +00:00
|
|
|
});
|
2017-04-19 08:21:33 +00:00
|
|
|
if (items.length == 0) {
|
2017-04-01 08:59:17 +00:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2017-04-19 08:21:33 +00:00
|
|
|
var items_len = items.length;
|
2017-04-01 08:59:17 +00:00
|
|
|
var thumbnail_size = app.pageOptions.thumbnail_default_size;
|
|
|
|
|
|
|
|
var get_thumbnail = function(i) {
|
2017-04-19 08:21:33 +00:00
|
|
|
var cur_item = items[i];
|
2017-04-01 08:59:17 +00:00
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({
|
|
|
|
name: 'thumbnail_create',
|
2017-04-19 08:21:33 +00:00
|
|
|
repo_id: cur_item.get('repo_id')
|
2017-04-01 08:59:17 +00:00
|
|
|
}),
|
|
|
|
data: {
|
2017-04-19 08:21:33 +00:00
|
|
|
'path': cur_item.get('path'),
|
2017-04-01 08:59:17 +00:00
|
|
|
'size': thumbnail_size
|
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2017-04-19 08:21:33 +00:00
|
|
|
cur_item.set({
|
2017-04-01 08:59:17 +00:00
|
|
|
'encoded_thumbnail_src': data.encoded_thumbnail_src
|
|
|
|
});
|
|
|
|
},
|
|
|
|
complete: function() {
|
2017-04-19 08:21:33 +00:00
|
|
|
if (i < items_len - 1) {
|
2017-04-01 08:59:17 +00:00
|
|
|
get_thumbnail(++i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
get_thumbnail(0);
|
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
showStarredFiles: function() {
|
|
|
|
this.$table.hide();
|
|
|
|
this.$loadingTip.show();
|
|
|
|
this.starredFiles.fetch({reset: true});
|
|
|
|
},
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
renderMainCon: function() {
|
|
|
|
this.$mainCon = $('<div class="main-panel-main" id="org-repos"></div>').html(this.template());
|
|
|
|
this.$el.append(this.$mainCon);
|
2016-03-24 06:43:20 +00:00
|
|
|
|
2015-05-04 09:02:20 +00:00
|
|
|
this.$table = this.$('table');
|
|
|
|
this.$tableBody = this.$('tbody');
|
|
|
|
this.$loadingTip = this.$('.loading-tip');
|
|
|
|
this.$emptyTip = this.$('.empty-tips');
|
|
|
|
|
|
|
|
this.$el.magnificPopup({
|
|
|
|
type: 'image',
|
|
|
|
delegate: '.img-name-link',
|
|
|
|
tClose: gettext("Close (Esc)"), // Alt text on close button
|
|
|
|
tLoading: gettext("Loading..."), // Text that is displayed during loading. Can contain %curr% and %total% keys
|
|
|
|
gallery: {
|
|
|
|
enabled: true,
|
|
|
|
tPrev: gettext("Previous (Left arrow key)"), // Alt text on left arrow
|
|
|
|
tNext: gettext("Next (Right arrow key)"), // Alt text on right arrow
|
|
|
|
tCounter: gettext("%curr% of %total%") // Markup for "1 of 7" counter
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
titleSrc: function(item) {
|
|
|
|
var el = item.el;
|
|
|
|
var img_name = el[0].innerHTML;
|
|
|
|
var img_link = '<a href="' + el.attr('href') + '" target="_blank">' + gettext("Open in New Tab") + '</a>';
|
|
|
|
return img_name + '<br />' + img_link;
|
|
|
|
},
|
|
|
|
tError: gettext('<a href="%url%" target="_blank">The image</a> could not be loaded.') // Error message when image could not be loaded
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-12-15 08:54:51 +00:00
|
|
|
renderThead: function() {
|
|
|
|
this.$('thead').html(this.theadTemplate());
|
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
show: function() {
|
2017-12-05 09:53:45 +00:00
|
|
|
this.renderMainCon();
|
2016-03-24 06:43:20 +00:00
|
|
|
this.showStarredFiles();
|
2015-05-04 09:02:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2017-12-05 09:53:45 +00:00
|
|
|
this.$mainCon.detach();
|
2015-05-04 09:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return StarredFileView;
|
|
|
|
});
|