1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-19 11:52:41 +00:00
seahub/static/scripts/sysadmin-app/views/dirent.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-05-25 02:45:22 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
2016-05-27 08:42:40 +00:00
var DirentView = HLItemView.extend({
2016-05-25 02:45:22 +00:00
tagName: 'tr',
template: _.template($('#dirent-item-tmpl').html()),
events: {
'click .dirent-download-btn': 'downloadDirent',
'click .dirent-delete-btn': 'deleteDirent',
},
initialize: function(options) {
HLItemView.prototype.initialize.call(this);
this.dir = options.dirView.dir;
},
downloadDirent: function() {
var _this = this;
$.ajax({
url: _this.model.getDownloadUrl(),
dataType: 'json',
success: function(data) {
location.href = data['download_url']
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
}
})
return false;
},
deleteDirent: function() {
var _this = this;
$.ajax({
url: _this.model.getDeleteUrl(),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
success: function() {
_this.$el.remove();
Common.feedback(gettext("Success"), 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
}
})
return false;
},
render: function() {
var file_icon_size = Common.isHiDPI() ? 48 : 24;
var data = this.model.toJSON(),
last_update = Moment(data['last_update']);
data['time'] = last_update.format('LLLL');
data['time_from_now'] = Common.getRelativeTimeStr(last_update);
data['icon_url'] = this.model.getIconUrl(file_icon_size);
data['download_url'] = this.model.getDownloadUrl(),
data['repo_id'] = this.dir.repo_id;
data['is_system_library'] = this.dir.is_system_library;
data['url'] = this.model.getWebUrl(),
this.$el.html(this.template(data));
return this;
}
});
2016-05-27 08:42:40 +00:00
return DirentView;
2016-05-25 02:45:22 +00:00
});