1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-21 10:51:17 +00:00

Merge pull request #538 from haiwen/folder-perm

[folder perm] modified 'user perm'
This commit is contained in:
Daniel Pan
2015-04-30 14:40:08 +08:00
6 changed files with 276 additions and 154 deletions

View File

@@ -19,11 +19,7 @@ define([
this.repo_id = options.repo_id;
this.obj_name = options.obj_name;
this.dir_path = options.dir_path;
if (this.dir_path === '/') {
this.path = this.dir_path + this.obj_name;
} else {
this.path = this.dir_path + '/' + this.obj_name;
}
this.path = Common.pathJoin([this.dir_path, this.obj_name])
this.render();
@@ -94,16 +90,31 @@ define([
// use select2 to 'user' input in 'add user perm'
$('[name="email"]', $add_user_perm).select2({
maximumSelectionSize: 1,
placeholder: gettext("Enter emails or select contacts"),
tags: function () {
var contacts = app.pageOptions.contacts || [];
var contact_list = [];
for (var i = 0, len = contacts.length; i < len; i++) {
contact_list.push(contacts[i].email);
contact_list.push({ // 'id' & 'text' are required by the plugin
"id": contacts[i].email,
"text": contacts[i].email,
"avatar": contacts[i].avatar,
"name": contacts[i].name
});
}
return contact_list;
},
tokenSeparators: [',', ' '],
formatResult: function(item) { // format items shown in the drop-down menu
if (item.avatar) {
return item.avatar + '<span class="text">' + item.name + '<br />' + item.text + '</span>';
} else {
return; // if no match, show nothing
}
},
formatSelection: function(item) { // format selected item shown in the input
return item.name || item.text; // if no name, show the email, i.e., when directly input, show the email
},
escapeMarkup: function(m) { return m; }
});
@@ -114,7 +125,7 @@ define([
g_opts += '<option value="' + groups[i].id + '" data-index="' + i + '">' + groups[i].name + '</option>';
}
$('[name="group"]', $add_group_perm).html(g_opts).select2({
maximumSelectionSize: 1,
placeholder: gettext("Select groups"),
escapeMarkup: function(m) { return m; }
});
},
@@ -147,18 +158,22 @@ define([
'perm': perm
},
'after_op_success': function(data) {
var perm_item = new FolderPermItemView({
'repo_id': _this.repo_id,
'path': _this.path,
'item_data': {
'user': email,
'perm': perm,
'is_user_perm': true
}
$(data.success).each(function(index, item) {
var perm_item = new FolderPermItemView({
'repo_id': _this.repo_id,
'path': _this.path,
'item_data': {
'user': email,
'user_name': item.user_name,
'perm': perm,
'is_user_perm': true
}
});
form.after(perm_item.el);
});
form.after(perm_item.el);
$('[name="email"]', form).select2("val", "");
$('#user-folder-perm .error').addClass('hide');
},
'after_op_error': function(xhr) {
var err;
@@ -175,9 +190,8 @@ define([
addGroupFolderPerm: function() {
var _this = this;
var form = this.$add_group_perm, // pseudo form
group_input = $('[name="group"]', form),
group_id = group_input.val()[0];
if (!group_id) {
group_ids = $('[name="group"]', form).val().join(',');
if (!group_ids) {
return false;
}
@@ -192,21 +206,24 @@ define([
'post_data': {
'path': this.path,
'type': 'add',
'group_id': group_id,
'group_id': group_ids,
'perm': perm
},
'after_op_success': function(data) {
var perm_item = new FolderPermItemView({
'repo_id': _this.repo_id,
'path': _this.path,
'item_data': {
'is_user_perm': false,
'perm': perm,
'group_id': group_id,
'group_name': $('[name="group"]', form).select2('data')[0].text
}
$(data.success).each(function(index, item) {
var perm_item = new FolderPermItemView({
'repo_id': _this.repo_id,
'path': _this.path,
'item_data': {
'is_user_perm': false,
'perm': perm,
'group_id': item.group_id,
'group_name': item.group_name
}
});
form.after(perm_item.el);
$('#group-folder-perm .error').addClass('hide');
});
form.after(perm_item.el);
$('[name="group"]', form).select2("val", "");
},

View File

@@ -409,19 +409,34 @@ define([
var form = this.$('#file-private-share-form');
loading_tip.show();
var contacts = app.pageOptions.contacts || [];
$('[name="emails"]', form).select2({
placeholder: gettext("Select contacts or input"),
placeholder: gettext("Enter emails or select contacts"),
width: '400px',
// with 'tags', the user can directly enter, not just select
// tags need `<input type="hidden" />`, not `<select>`
tags: function () {
var contacts = app.pageOptions.contacts || [];
var contact_list = [];
for (var i = 0, len = contacts.length; i < len; i++) {
contact_list.push(contacts[i].email);
contact_list.push({ // 'id' & 'text' are required by the plugin
"id": contacts[i].email,
"text": contacts[i].email,
"avatar": contacts[i].avatar,
"name": contacts[i].name
});
}
return contact_list;
},
formatResult: function(item) { // format items shown in the drop-down menu
if (item.avatar) {
return item.avatar + '<span class="text">' + item.name + '<br />' + item.text + '</span>';
} else {
return; // if no match, show nothing
}
},
formatSelection: function(item) { // format selected item shown in the input
return item.name || item.text; // if no name, show the email, i.e., when directly input, show the email
},
tokenSeparators: [',', ' '],
escapeMarkup: function(m) { return m; }
});
@@ -479,12 +494,28 @@ define([
placeholder: gettext("Select contacts or input"),
width: '400px',
tags: function () {
var contacts = app.pageOptions.contacts || [];
var contact_list = [];
for (var i = 0, len = contacts.length; i < len; i++) {
contact_list.push(contacts[i].email);
contact_list.push({ // 'id' & 'text' are required by the plugin
"id": contacts[i].email,
"text": contacts[i].email,
"avatar": contacts[i].avatar,
"name": contacts[i].name
});
}
return contact_list;
},
formatResult: function(item) { // format items shown in the drop-down menu
if (item.avatar) {
return item.avatar + '<span class="text">' + item.name + '<br />' + item.text + '</span>';
} else {
return; // if no match, show nothing
}
},
formatSelection: function(item) { // format selected item shown in the input
return item.name || item.text; // if no name, show the email, i.e., when directly input, show the email
},
tokenSeparators: [',', ' '],
escapeMarkup: function(m) { return m; }
});