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

75 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-01-21 14:22:34 +00:00
define([
'jquery',
'underscore',
'backbone',
2015-04-03 04:15:41 +00:00
'common'
], function($, _, Backbone, Common) {
2015-01-21 14:22:34 +00:00
'use strict';
var GroupRepoView = Backbone.View.extend({
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: {
'mouseenter': 'showAction',
'mouseleave': 'hideAction',
'click .cancel-share': 'unshare'
},
2015-04-11 07:14:56 +00:00
initialize: function(options) {
this.group_id = options.group_id;
2015-01-21 14:22:34 +00:00
Backbone.View.prototype.initialize.apply(this, arguments);
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();
$.extend(obj, {
group_id: this.group_id,
});
this.$el.html(this.template(obj));
2015-01-21 14:22:34 +00:00
return this;
},
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');
},
unshare: function() {
2015-01-22 09:15:17 +00:00
var that = this;
var yesCallback = function() {
Common.closeModal();
Common.feedback(gettext('Loading...'), 'info', Common.INFO_TIMEOUT); // TODO: what if there is still response after 10 secs ?
// send delete request and wait response
that.model.destroy({
wait: true,
success: function(model, rep) {
Common.feedback(gettext('Success'), 'success', Common.SUCCESS_TIMOUT);
},
error: function() {
Common.feedback(gettext('Error'), 'error', Common.ERROR_TIMEOUT);
}
});
};
Common.showConfirm(
gettext('Unshare Library'),
gettext('Are you sure you want to unshare {placeholder} ?')
.replace(/\{placeholder\}/g, '<span class="op-target">' + Common.HTMLescape(this.model.get('name')) + '</span>'),
2015-01-22 09:15:17 +00:00
yesCallback
);
},
2015-01-21 14:22:34 +00:00
});
return GroupRepoView;
});