2015-01-21 14:22:34 +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-01-21 14:22:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-03-22 03:47:52 +00:00
|
|
|
var GroupRepoView = HLItemView.extend({
|
2015-01-21 14:22:34 +00:00
|
|
|
tagName: 'tr',
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
template: _.template($('#group-repo-tmpl').html()),
|
2016-11-30 07:56:25 +00:00
|
|
|
mobileTemplate: _.template($('#group-repo-mobile-tmpl').html()),
|
2015-01-21 14:22:34 +00:00
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .cancel-share': 'unshare'
|
|
|
|
},
|
2015-04-11 07:14:56 +00:00
|
|
|
|
|
|
|
initialize: function(options) {
|
2016-03-22 03:47:52 +00:00
|
|
|
HLItemView.prototype.initialize.call(this);
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
this.group_id = options.group_id;
|
2015-04-20 06:31:22 +00:00
|
|
|
this.is_staff = options.is_staff;
|
2015-01-22 09:15:17 +00:00
|
|
|
|
2015-12-17 06:57:21 +00:00
|
|
|
this.show_shared_by = true; // default
|
|
|
|
if (options.show_shared_by !== undefined) { // e.g. views/group-item.js
|
|
|
|
this.show_shared_by = options.show_shared_by;
|
|
|
|
}
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.remove);
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-04-11 07:14:56 +00:00
|
|
|
var obj = this.model.toJSON();
|
2017-07-31 09:30:43 +00:00
|
|
|
var icon_size = Common.isHiDPI() ? 48 : 24;
|
2016-03-11 04:10:55 +00:00
|
|
|
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;
|
2015-04-11 07:14:56 +00:00
|
|
|
$.extend(obj, {
|
|
|
|
group_id: this.group_id,
|
2016-01-06 08:28:26 +00:00
|
|
|
is_staff: this.is_staff,
|
|
|
|
// for '#groups' (no 'share_from_me')
|
|
|
|
share_from_me: app.pageOptions.username == this.model.get('owner') ? true : false,
|
|
|
|
// 'owner_name' for '#groups', 'owner_nickname' for '#group/id/'
|
2016-01-13 02:19:56 +00:00
|
|
|
owner_name: this.model.get('owner_nickname') || this.model.get('owner_name'),
|
2016-03-11 04:10:55 +00:00
|
|
|
show_shared_by: this.show_shared_by,
|
2016-03-14 04:15:28 +00:00
|
|
|
icon_url: icon_url,
|
|
|
|
icon_title: this.model.getIconTitle()
|
2015-04-11 07:14:56 +00:00
|
|
|
});
|
2016-11-30 07:56:25 +00:00
|
|
|
this.$el.html(tmpl(obj));
|
2015-01-21 14:22:34 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
unshare: function() {
|
2015-04-22 07:01:07 +00:00
|
|
|
var lib_name = this.model.get('name');
|
2015-04-21 06:20:18 +00:00
|
|
|
this.model.destroy({
|
|
|
|
wait: true,
|
2015-04-22 07:01:07 +00:00
|
|
|
success: function() {
|
2016-07-04 07:31:55 +00:00
|
|
|
var msg = gettext('Successfully unshared 1 item.');
|
2015-04-22 07:01:07 +00:00
|
|
|
Common.feedback(msg, 'success', Common.SUCCESS_TIMOUT);
|
2015-04-21 06:20:18 +00:00
|
|
|
},
|
2015-04-22 07:01:07 +00:00
|
|
|
error: function(model, response) {
|
|
|
|
var err;
|
|
|
|
if (response.responseText) {
|
|
|
|
err = $.parseJSON(response.responseText).error_msg;
|
|
|
|
} else {
|
|
|
|
err = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
Common.feedback(err, 'error');
|
2015-04-21 06:20:18 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-12 03:17:27 +00:00
|
|
|
|
|
|
|
return false;
|
2015-06-10 05:43:41 +00:00
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return GroupRepoView;
|
|
|
|
});
|