2015-05-04 09:02:20 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common'
|
|
|
|
], function($, _, Backbone, Common) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var StarredFileView = Backbone.View.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
|
|
|
|
template: _.template($('#starred-file-item-tmpl').html()),
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'mouseenter': 'showAction',
|
|
|
|
'mouseleave': 'hideAction',
|
|
|
|
'click .unstar': 'removeShare'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
2015-06-08 04:02:21 +00:00
|
|
|
var data = this.model.toJSON();
|
2015-05-04 09:02:20 +00:00
|
|
|
|
2015-06-08 04:02:21 +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,
|
|
|
|
repo_id = this.model.get('repo'),
|
|
|
|
file_name = this.model.get('file_name'),
|
|
|
|
path = this.model.get('path');
|
|
|
|
|
|
|
|
$.ajax({
|
2015-07-06 06:43:45 +00:00
|
|
|
url: Common.getUrl({name: 'starred_files'}) + '?p=' + encodeURIComponent(path) + '&repo_id=' + 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) {
|
|
|
|
var err;
|
|
|
|
if (xhr.responseText) {
|
|
|
|
err = $.parseJSON(xhr.responseText).error;
|
|
|
|
} else {
|
|
|
|
err = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
Common.feedback(err, 'error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showAction: function() {
|
|
|
|
this.$el.addClass('hl');
|
|
|
|
this.$el.find('.op-icon').removeClass('vh');
|
|
|
|
},
|
|
|
|
|
|
|
|
hideAction: function() {
|
|
|
|
this.$el.removeClass('hl');
|
|
|
|
this.$el.find('.op-icon').addClass('vh');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return StarredFileView;
|
|
|
|
});
|