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

78 lines
2.5 KiB
JavaScript
Raw Normal View History

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()),
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;
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();
2016-03-11 04:10:55 +00:00
var icon_size = Common.isHiDPI() ? 96 : 24;
var icon_url = this.model.getIconUrl(icon_size);
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/'
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,
icon_url: icon_url,
icon_title: this.model.getIconTitle()
2015-04-11 07:14:56 +00:00
});
this.$el.html(this.template(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');
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-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');
}
});
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;
});