2015-06-26 07:45:15 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common'
|
|
|
|
], function($, _, Backbone, Common) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var FolderShareItemView = Backbone.View.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
|
|
|
|
template: _.template($('#folder-perm-item-tmpl').html()),
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.item_data = options.item_data;
|
|
|
|
this.repo_id = options.repo_id;
|
|
|
|
this.path = options.path;
|
|
|
|
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
this.$el.html(this.template(this.item_data));
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'mouseenter': 'showOpIcons',
|
|
|
|
'mouseleave': 'hideOpIcons',
|
|
|
|
'click .perm-edit-icon': 'editIconClick',
|
|
|
|
'change .perm-toggle-select': 'editPerm',
|
|
|
|
'click .delete-icon': 'del'
|
|
|
|
},
|
|
|
|
|
|
|
|
showOpIcons: function () {
|
|
|
|
this.$el.find('.op-icon').removeClass('vh');
|
|
|
|
},
|
|
|
|
|
|
|
|
hideOpIcons: function () {
|
|
|
|
this.$el.find('.op-icon').addClass('vh');
|
|
|
|
},
|
|
|
|
|
|
|
|
editIconClick: function (e) {
|
|
|
|
$(e.currentTarget).closest('td')
|
|
|
|
.find('.perm').addClass('hide').end()
|
|
|
|
.find('.perm-toggle-select').removeClass('hide');
|
2016-04-12 07:53:51 +00:00
|
|
|
|
|
|
|
return false;
|
2015-06-26 07:45:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
editPerm: function (e) {
|
|
|
|
var _this = this;
|
|
|
|
var item_data = this.item_data;
|
2015-07-02 07:44:50 +00:00
|
|
|
var url = Common.getUrl({
|
|
|
|
name: 'dir_shared_items',
|
|
|
|
repo_id: this.repo_id
|
|
|
|
}) + '?p=' + encodeURIComponent(this.path);
|
|
|
|
if (item_data.for_user) {
|
2016-08-30 03:15:22 +00:00
|
|
|
url += '&share_type=user&username=' + encodeURIComponent(item_data.user_email);
|
2015-07-02 07:44:50 +00:00
|
|
|
} else {
|
|
|
|
url += '&share_type=group&group_id=' + encodeURIComponent(item_data.group_id);
|
|
|
|
}
|
2015-06-26 07:45:15 +00:00
|
|
|
var perm = $(e.currentTarget).val();
|
|
|
|
$.ajax({
|
2015-07-02 07:44:50 +00:00
|
|
|
url: url,
|
2015-06-26 07:45:15 +00:00
|
|
|
dataType: 'json',
|
2015-07-02 07:44:50 +00:00
|
|
|
method: 'POST',
|
2015-06-26 07:45:15 +00:00
|
|
|
beforeSend: Common.prepareCSRFToken,
|
2015-07-02 07:44:50 +00:00
|
|
|
data: {
|
|
|
|
'permission': perm
|
|
|
|
},
|
|
|
|
success: function () {
|
2016-08-30 03:15:22 +00:00
|
|
|
item_data.permission = perm;
|
2015-06-26 07:45:15 +00:00
|
|
|
_this.render();
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
2015-07-02 07:44:50 +00:00
|
|
|
var err_msg;
|
2015-06-26 07:45:15 +00:00
|
|
|
if (xhr.responseText) {
|
2015-07-02 07:44:50 +00:00
|
|
|
err_msg = gettext("Edit failed");
|
2015-06-26 07:45:15 +00:00
|
|
|
} else {
|
2015-07-02 07:44:50 +00:00
|
|
|
err_msg = gettext("Failed. Please check the network.");
|
2015-06-26 07:45:15 +00:00
|
|
|
}
|
2015-07-02 07:44:50 +00:00
|
|
|
if (item_data.for_user) {
|
|
|
|
$('#dir-user-share .error').html(err_msg).removeClass('hide');
|
2015-06-26 07:45:15 +00:00
|
|
|
} else {
|
2016-08-15 09:21:42 +00:00
|
|
|
$('#dir-group-share .error').html(err_msg).removeClass('hide');
|
2015-06-26 07:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
del: function () {
|
2015-07-01 10:28:14 +00:00
|
|
|
var _this = this;
|
|
|
|
var item_data = this.item_data;
|
|
|
|
var url = Common.getUrl({
|
|
|
|
name: 'dir_shared_items',
|
|
|
|
repo_id: this.repo_id
|
|
|
|
}) + '?p=' + encodeURIComponent(this.path);
|
|
|
|
if (item_data.for_user) {
|
2016-08-30 03:15:22 +00:00
|
|
|
url += '&share_type=user&username=' + encodeURIComponent(item_data.user_email);
|
2015-07-01 10:28:14 +00:00
|
|
|
} else {
|
2015-07-02 07:44:50 +00:00
|
|
|
url += '&share_type=group&group_id=' + encodeURIComponent(item_data.group_id);
|
2015-07-01 10:28:14 +00:00
|
|
|
}
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: 'json',
|
|
|
|
method: 'DELETE',
|
|
|
|
beforeSend: Common.prepareCSRFToken,
|
|
|
|
success: function () {
|
|
|
|
_this.remove();
|
|
|
|
},
|
2015-07-02 07:44:50 +00:00
|
|
|
error: function (xhr) {
|
|
|
|
var err_msg;
|
|
|
|
if (xhr.responseText) {
|
|
|
|
err_msg = gettext("Delete failed");
|
|
|
|
} else {
|
|
|
|
err_msg = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
if (item_data.for_user) {
|
|
|
|
$('#dir-user-share .error').html(err_msg).removeClass('hide');
|
|
|
|
} else {
|
2016-08-15 09:21:42 +00:00
|
|
|
$('#dir-group-share .error').html(err_msg).removeClass('hide');
|
2015-07-02 07:44:50 +00:00
|
|
|
}
|
2015-07-01 10:28:14 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-12 07:53:51 +00:00
|
|
|
|
|
|
|
return false;
|
2015-06-26 07:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return FolderShareItemView;
|
|
|
|
});
|