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-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() {
|
|
|
|
var msg = gettext('Successfully unshared {placeholder}').replace('{placeholder}', '<span class="op-target">' + Common.HTMLescape(lib_name) + '</span>');
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
2015-01-21 14:22:34 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return GroupRepoView;
|
|
|
|
});
|