2015-02-04 13:57:26 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2016-03-22 03:47:52 +00:00
|
|
|
'common',
|
|
|
|
'app/views/widgets/hl-item-view'
|
|
|
|
], function($, _, Backbone, Common, HLItemView) {
|
2015-02-04 13:57:26 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-03-22 03:47:52 +00:00
|
|
|
var SharedRepoView = HLItemView.extend({
|
2015-02-04 13:57:26 +00:00
|
|
|
tagName: 'tr',
|
|
|
|
|
2015-04-03 04:15:41 +00:00
|
|
|
template: _.template($('#shared-repo-tmpl').html()),
|
2016-11-30 07:56:25 +00:00
|
|
|
mobileTemplate: _.template($('#shared-repo-mobile-tmpl').html()),
|
2015-02-04 13:57:26 +00:00
|
|
|
|
|
|
|
events: {
|
2015-03-06 09:53:41 +00:00
|
|
|
'click .unshare-btn': 'removeShare'
|
2015-02-04 13:57:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2016-03-22 03:47:52 +00:00
|
|
|
HLItemView.prototype.initialize.call(this);
|
2015-03-06 09:53:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeShare: function(e) {
|
|
|
|
var _this = this,
|
2015-03-07 07:56:10 +00:00
|
|
|
success_callback = function(data) {
|
2015-03-06 09:53:41 +00:00
|
|
|
Common.feedback(gettext('Success'), 'success', Common.SUCCESS_TIMOUT);
|
|
|
|
_this.$el.remove();
|
|
|
|
_this.collection.remove(_this.model, {silent: true});
|
|
|
|
if (_this.collection.length == 0) {
|
|
|
|
$('#repos-shared-to-me table').hide();
|
|
|
|
$('#repos-shared-to-me .empty-tips').show();
|
2016-04-12 03:17:27 +00:00
|
|
|
}
|
2015-03-06 09:53:41 +00:00
|
|
|
};
|
|
|
|
|
2015-10-19 07:04:37 +00:00
|
|
|
$.ajax({
|
2016-06-20 10:34:30 +00:00
|
|
|
url: Common.getUrl({name: 'beshared_repo', repo_id: this.model.get('id')})
|
|
|
|
+ "?share_type=personal&from=" + encodeURIComponent(this.model.get('owner')),
|
|
|
|
type: 'DELETE',
|
2015-10-19 07:04:37 +00:00
|
|
|
beforeSend: Common.prepareCSRFToken,
|
|
|
|
dataType: 'json',
|
|
|
|
success: success_callback
|
2015-03-06 09:53:41 +00:00
|
|
|
});
|
2016-04-12 03:17:27 +00:00
|
|
|
|
|
|
|
return false;
|
2015-02-04 13:57:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-03-11 04:10:55 +00:00
|
|
|
var obj = this.model.toJSON();
|
|
|
|
var icon_size = Common.isHiDPI() ? 96 : 24;
|
|
|
|
var icon_url = this.model.getIconUrl(icon_size);
|
2016-11-30 07:56:25 +00:00
|
|
|
var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate;
|
2016-03-14 04:15:28 +00:00
|
|
|
_.extend(obj, {
|
|
|
|
'icon_url': icon_url,
|
|
|
|
'icon_title': this.model.getIconTitle()
|
|
|
|
});
|
2016-11-30 07:56:25 +00:00
|
|
|
this.$el.html(tmpl(obj));
|
2015-02-04 13:57:26 +00:00
|
|
|
return this;
|
2015-06-10 05:43:41 +00:00
|
|
|
}
|
2016-03-22 03:47:52 +00:00
|
|
|
|
2015-02-04 13:57:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return SharedRepoView;
|
|
|
|
});
|