From 70315404b327788586bdf8f604d1e317eb4ff79c Mon Sep 17 00:00:00 2001 From: llj Date: Thu, 30 Apr 2015 21:19:35 +0800 Subject: [PATCH 1/2] [folder perm, share] select contacts: enable search contact name --- seahub/views/ajax.py | 2 +- static/scripts/app/views/folder-perm.js | 6 +++--- static/scripts/app/views/share.js | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 9551ec01a3..6f4ff585c5 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -2423,7 +2423,7 @@ def set_group_folder_perm(request, repo_id): content_type = 'application/json; charset=utf-8' if not (is_pro_version() and ENABLE_FOLDER_PERM): - return HttpResponse(json.dumps({"error": True}), + return HttpResponse(json.dumps({"error": _(u"Permission denied")}), status=403, content_type=content_type) group_id = request.POST.get('group_id', None) diff --git a/static/scripts/app/views/folder-perm.js b/static/scripts/app/views/folder-perm.js index 712acad6b0..24e415b2d7 100644 --- a/static/scripts/app/views/folder-perm.js +++ b/static/scripts/app/views/folder-perm.js @@ -97,7 +97,7 @@ define([ for (var i = 0, len = contacts.length; i < len; i++) { contact_list.push({ // 'id' & 'text' are required by the plugin "id": contacts[i].email, - "text": contacts[i].email, + "text": contacts[i].name + contacts[i].email, // for search. both name & email can be searched. "avatar": contacts[i].avatar, "name": contacts[i].name }); @@ -107,13 +107,13 @@ define([ tokenSeparators: [',', ' '], formatResult: function(item) { // format items shown in the drop-down menu if (item.avatar) { - return item.avatar + '' + item.name + '
' + item.text + '
'; + return item.avatar + '' + item.name + '
' + item.id + '
'; } 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 + return item.name || item.id; // if no name, show the email, i.e., when directly input, show the email }, escapeMarkup: function(m) { return m; } }); diff --git a/static/scripts/app/views/share.js b/static/scripts/app/views/share.js index fa8efd06be..788d7c7ce1 100644 --- a/static/scripts/app/views/share.js +++ b/static/scripts/app/views/share.js @@ -420,7 +420,7 @@ define([ for (var i = 0, len = contacts.length; i < len; i++) { contact_list.push({ // 'id' & 'text' are required by the plugin "id": contacts[i].email, - "text": contacts[i].email, + "text": contacts[i].name + contacts[i].email, // for search. both name & email can be searched. "avatar": contacts[i].avatar, "name": contacts[i].name }); @@ -429,13 +429,13 @@ define([ }, formatResult: function(item) { // format items shown in the drop-down menu if (item.avatar) { - return item.avatar + '' + item.name + '
' + item.text + '
'; + return item.avatar + '' + item.name + '
' + item.id + '
'; } 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 + return item.name || item.id; // if no name, show the email, i.e., when directly input, show the email }, tokenSeparators: [',', ' '], escapeMarkup: function(m) { return m; } @@ -499,7 +499,7 @@ define([ for (var i = 0, len = contacts.length; i < len; i++) { contact_list.push({ // 'id' & 'text' are required by the plugin "id": contacts[i].email, - "text": contacts[i].email, + "text": contacts[i].name + contacts[i].email, // for search. both name & email can be searched. "avatar": contacts[i].avatar, "name": contacts[i].name }); @@ -508,13 +508,13 @@ define([ }, formatResult: function(item) { // format items shown in the drop-down menu if (item.avatar) { - return item.avatar + '' + item.name + '
' + item.text + '
'; + return item.avatar + '' + item.name + '
' + item.id + '
'; } 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 + return item.name || item.id; // if no name, show the email, i.e., when directly input, show the email }, tokenSeparators: [',', ' '], escapeMarkup: function(m) { return m; } From a4509d30febb3a0223a8ac0f309770d519a46ef8 Mon Sep 17 00:00:00 2001 From: llj Date: Tue, 5 May 2015 11:10:56 +0800 Subject: [PATCH 2/2] [folder perm, share] contacts input: improvement --- static/scripts/app/views/folder-perm.js | 29 +--------- static/scripts/app/views/share.js | 73 ++----------------------- static/scripts/common.js | 39 +++++++++++++ 3 files changed, 46 insertions(+), 95 deletions(-) diff --git a/static/scripts/app/views/folder-perm.js b/static/scripts/app/views/folder-perm.js index 24e415b2d7..9693e1aca8 100644 --- a/static/scripts/app/views/folder-perm.js +++ b/static/scripts/app/views/folder-perm.js @@ -89,34 +89,7 @@ define([ }); // use select2 to 'user' input in 'add user perm' - $('[name="email"]', $add_user_perm).select2({ - 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({ // 'id' & 'text' are required by the plugin - "id": contacts[i].email, - "text": contacts[i].name + contacts[i].email, // for search. both name & email can be searched. - "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 + '' + item.name + '
' + item.id + '
'; - } else { - return; // if no match, show nothing - } - }, - formatSelection: function(item) { // format selected item shown in the input - return item.name || item.id; // if no name, show the email, i.e., when directly input, show the email - }, - escapeMarkup: function(m) { return m; } - }); + $('[name="email"]', $add_user_perm).select2(Common.contactInputOptionsForSelect2); // use select2 to 'group' input in 'add group perm' var groups = app.pageOptions.groups || [], diff --git a/static/scripts/app/views/share.js b/static/scripts/app/views/share.js index 788d7c7ce1..386338847f 100644 --- a/static/scripts/app/views/share.js +++ b/static/scripts/app/views/share.js @@ -405,43 +405,12 @@ define([ }, filePrivateSharePanelInit: function() { - var loading_tip = this.$('.loading-tip'); var form = this.$('#file-private-share-form'); - loading_tip.show(); - $('[name="emails"]', form).select2({ - placeholder: gettext("Enter emails or select contacts"), - width: '400px', - // with 'tags', the user can directly enter, not just select - // tags need ``, not ``, not `