1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 07:01:12 +00:00

Modify autocomplete and contacts

This commit is contained in:
xiez
2012-09-27 17:52:04 +08:00
parent 669a556626
commit 7d0e15123a
6 changed files with 64 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
{% extends "myhome_base.html" %}
{% load avatar_tags %}
{% block nav_contacts_class %}class="cur"{% endblock %}
@@ -9,17 +10,19 @@
{% endblock %}
{% block right_panel %}
<h3>联系人列表</h3>
<h3>站内联系人列表</h3>
<button id="contact-add">添加联系人</button>
<table>
<tr>
<th width="4%"></th>
<th width="38%">邮箱</th>
<th width="20%">名字</th>
<th width="32%">备注</th>
<th width="28%">备注</th>
<th width="10%">操作</th>
</tr>
{% for contact in contacts %}
{% for contact in registered_contacts %}
<tr>
<td>{% avatar contact.contact_email 20 %}</td>
<td>{{ contact.contact_email }}</td>
<td>{{ contact.contact_name }}</td>
<td>{{ contact.note }}</td>
@@ -30,6 +33,30 @@
</tr>
{% endfor %}
</table>
<h3>站外联系人列表</h3>
<table>
<tr>
<th width="4%"></th>
<th width="38%">邮箱</th>
<th width="20%">名字</th>
<th width="32%">备注</th>
<th width="10%">操作</th>
</tr>
{% for contact in unregistered_contacts %}
<tr>
<td>{% avatar contact.contact_email 20 %}</td>
<td>{{ contact.contact_email }}</td>
<td>{{ contact.contact_name }}</td>
<td>{{ contact.note }}</td>
<td>
<a href="#" data="{{ SITE_ROOT }}contacts/edit/?email={{ contact.contact_email }}" class="contact-edit op">编辑</a>
<a href="#" data="{{ SITE_ROOT }}contacts/delete/?email={{ contact.contact_email}}" class="contact-delete op">删除</a>
</td>
</tr>
{% endfor %}
</table>
<form action="{% url contact_add_post %}" method="post" id="contact-add-form" class="hide">
<h3>添加联系人</h3>
{{ form.user_email.as_hidden }}
@@ -99,15 +126,6 @@ $('#contact-edit-form').submit(function() {
addConfirmTo($('.contact-delete'));
$("table tr:gt(0)").hover(
function() {
$(this).find('img').css('cursor', 'pointer').removeClass('vh');
},
function() {
$(this).find('img').addClass('vh');
}
);
$('#contact-add')
.click(function() {
$('#contact-add-form').modal({appendTo: '#main'});

View File

@@ -14,20 +14,31 @@ from models import Contact, ContactAddForm, ContactEditForm
from utils import render_error
from seaserv import ccnet_rpc, ccnet_threaded_rpc
from seahub.views import is_registered_user
from seahub.settings import SITE_ROOT
@login_required
def contact_list(request):
contacts = Contact.objects.filter(user_email=request.user.username)
registered_contacts = []
unregistered_contacts = []
for c in contacts:
if is_registered_user(c.contact_email):
registered_contacts.append(c)
else:
unregistered_contacts.append(c)
form = ContactAddForm({'user_email':request.user.username})
edit_init_data = {'user_email':request.user.username,
'contact_email':'',
'contact_name':'',
'note':''}
'contact_email':'',
'contact_name':'',
'note':''}
edit_form = ContactEditForm(edit_init_data)
return render_to_response('contacts/contact_list.html', {
'contacts': contacts,
'registered_contacts': registered_contacts,
'unregistered_contacts': unregistered_contacts,
'form': form,
'edit_form': edit_form,
}, context_instance=RequestContext(request))
@@ -43,14 +54,17 @@ def contact_add_post(request):
form = ContactAddForm(request.POST)
if form.is_valid():
contact_email = form.cleaned_data['contact_email']
contact = Contact()
contact.user_email = form.cleaned_data['user_email']
contact.contact_email = form.cleaned_data['contact_email']
contact.contact_email = contact_email
contact.contact_name = form.cleaned_data['contact_name']
contact.note = form.cleaned_data['note']
contact.save()
result['success'] = True
messages.success(request, u"您已成功添加 %s 为联系人" % contact_email)
return HttpResponse(json.dumps(result), content_type=content_type)
else:
return HttpResponseBadRequest(json.dumps(form.errors),
@@ -102,6 +116,7 @@ def contact_edit(request):
contact.note = note
contact.save()
result['success'] = True
messages.success(request, u'操作成功')
return HttpResponse(json.dumps(result), content_type=content_type)
else:
return HttpResponseBadRequest(json.dumps(form.errors),
@@ -114,5 +129,6 @@ def contact_delete(request):
contact_email = request.GET.get('email')
Contact.objects.filter(user_email=user_email, contact_email=contact_email).delete()
messages.success(request, u'删除成功')
return HttpResponseRedirect(reverse("contact_list"))

View File

@@ -31,7 +31,9 @@
{% block extra_script %}
<script type="text/javascript">
{% with groups=org_groups %}
{% include "snippets/myhome_extra_script.html" %}
{% endwith %}
{% url 'org_repo_create' org.url_prefix as repo_create_url %}
{% with post_url=repo_create_url %}

View File

@@ -109,6 +109,9 @@ def org_personal(request, url_prefix):
# Org groups user created
groups = get_org_groups_by_user(org.org_id, user)
# All org groups used in auto complete.
org_groups = get_org_groups(org.org_id, -1, -1)
# Org members used in auto complete
contacts = []
org_members = get_org_users_by_url_prefix(org.url_prefix, 0, MAX_INT)
@@ -123,6 +126,7 @@ def org_personal(request, url_prefix):
"in_repos": in_repos,
'org': org,
'groups': groups,
'org_groups': org_groups,
'contacts': contacts,
'create_shared_repo': False,
'allow_public_share': True,
@@ -546,8 +550,8 @@ def org_repo_share(request, url_prefix):
# TODO: if we know group id, then we can simplly call group_share_repo
group_name = share_to
# get org groups the user joined
groups = get_org_groups_by_user(org.org_id, from_email)
# Get all org groups.
groups = get_org_groups(org.org_id, -1, -1)
find = False
for group in groups:
# for every group that user joined, if group name and

View File

@@ -165,7 +165,7 @@ GROUP_AVATAR_DEFAULT_URL = 'avatars/groups/default.png'
AVATAR_MAX_AVATARS_PER_USER = 1
AVATAR_CACHE_TIMEOUT = 24 * 60 * 60
AVATAR_ALLOWED_FILE_EXTS = ('.jpg', '.png', '.jpeg', '.gif')
AUTO_GENERATE_AVATAR_SIZES = (16, 28, 48, 60, 80)
AUTO_GENERATE_AVATAR_SIZES = (16, 20, 28, 48, 60, 80)
CACHES = {
'default': {

View File

@@ -761,8 +761,9 @@ def myhome(request):
# Personal repos others shared to me
in_repos = list_personal_shared_repos(email,'to_email', -1, -1)
# my contacts
contacts = Contact.objects.filter(user_email=email)
# Get registered contacts used in autocomplete.
contacts = [ c for c in Contact.objects.filter(user_email=email) \
if is_registered_user(c.contact_email) ]
# user notifications
grpmsg_list = []
@@ -780,10 +781,7 @@ def myhome(request):
elif n.msg_type == 'org_join_msg':
orgmsg_list.append(n.detail)
# Get all personal groups used in autocomplete.
groups = get_personal_groups(-1, -1)
# Get all personal groups I joined.
# Get all personal groups I joined used in autocomplete.
joined_groups = get_personal_groups_by_user(request.user.username)
# get nickname
@@ -807,7 +805,7 @@ def myhome(request):
"quota_usage": quota_usage,
"in_repos": in_repos,
"contacts": contacts,
"groups": groups,
"groups": joined_groups,
"joined_groups": joined_groups,
"notes": notes,
"grpmsg_list": grpmsg_list,