1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 16:37:56 +00:00
seahub/static/scripts/app/views/starred-file-item.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-05-04 09:02:20 +00:00
define([
'jquery',
'underscore',
'backbone',
2016-03-21 13:29:14 +00:00
'common',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
2015-05-04 09:02:20 +00:00
'use strict';
2016-03-21 13:29:14 +00:00
var StarredFileView = HLItemView.extend({
2015-05-04 09:02:20 +00:00
tagName: 'tr',
template: _.template($('#starred-file-item-tmpl').html()),
events: {
'click .unstar': 'removeShare'
},
initialize: function() {
2016-03-21 13:29:14 +00:00
HLItemView.prototype.initialize.call(this);
2015-05-04 09:02:20 +00:00
},
render: function () {
var data = this.model.toJSON();
2015-05-04 09:02:20 +00:00
data['is_img'] = Common.imageCheck(data['file_name']);
data['encoded_path'] = Common.encodePath(data['path']);
2015-05-04 09:02:20 +00:00
this.$el.html(this.template(data));
return this;
},
removeShare: function() {
var _this = this,
2015-07-22 13:01:10 +00:00
repo_id = this.model.get('repo_id'),
2015-05-04 09:02:20 +00:00
file_name = this.model.get('file_name'),
path = this.model.get('path');
$.ajax({
2015-07-22 13:01:10 +00:00
url: Common.getUrl({name: 'starred_files'}) + '?p=' + encodeURIComponent(path) + '&repo_id=' + encodeURIComponent(repo_id),
2015-05-04 09:02:20 +00:00
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
success: function() {
_this.remove();
Common.feedback(gettext("Successfully unstared {placeholder}").replace('{placeholder}', Common.HTMLescape(file_name)), 'success');
},
error: function (xhr) {
Common.ajaxErrorHandler(xhr);
2015-05-04 09:02:20 +00:00
}
});
2016-04-12 03:17:27 +00:00
return false;
2015-05-04 09:02:20 +00:00
}
});
return StarredFileView;
});