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

modified msg-reply

This commit is contained in:
llj
2012-08-14 16:33:16 +08:00
committed by plt
parent dc65e319a1
commit 432c2473cc
4 changed files with 96 additions and 81 deletions

View File

@@ -6,9 +6,11 @@
{% block main_panel %} {% block main_panel %}
{% if messages %} {% if messages %}
<ul class="messages hide">
{% for message in messages %} {% for message in messages %}
<p class="notification">{{ message }}</p> <li class="info">{{ message }}</li>
{% endfor %} {% endfor %}
</ul>
{% endif %} {% endif %}
<h2>{{ group.group_name }}</h2> <h2>{{ group.group_name }}</h2>
@@ -116,19 +118,9 @@
{% endif %} {% endif %}
{{ msg.message|linebreaksbr|seahub_urlize|find_at }} {{ msg.message|linebreaksbr|seahub_urlize|find_at }}
</p> </p>
{% if msg.reply_cnt == 0 %} <button class="reply op" data="{{ msg.id }}"><span class="reply-cnt">{% if msg.reply_cnt != 0 %}{{ msg.reply_cnt }} {% endif %}</span>回复</button>
<a class="reply op" href="#" data="{{ msg.id }}">回复</a> <button class="replyclose op hide">收起回复</button>
{% else %} <div class="reply-bd"></div>
<a class="reply op" href="#" data="{{ msg.id }}">{{ msg.reply_cnt }} 回复</a>
{% endif %}
<a class="replyclose op hide" href="#">收起回复</a>
<div class="reply-list hide"></div>
<form id="form{{ msg.id }}" class="reply-form hide" method="post" action="">
<input type="hidden" name="msg_id" value="{{ msg.id }}" />
<input type="text" name="message" class="text-input" value=""/>
<input type="submit" class="submit" value="回复" />
<p class="error hide">输入不能为空且应少于150个字符。</p>
</form>
</div> </div>
</div> </div>
</li> </li>
@@ -258,7 +250,14 @@ $('#user-profile').hover(
$(this).addClass('hide'); $(this).addClass('hide');
} }
); );
$('.reply, .replyclose').hover(
function() {
$(this).css('color', '#f93');
},
function() {
$(this).css('color', '#080');
}
);
$('.reply').click(function() { $('.reply').click(function() {
var msg_id = $(this).attr('data'), var msg_id = $(this).attr('data'),
msg_bd = $(this).parent(); msg_bd = $(this).parent();
@@ -268,59 +267,46 @@ $('.reply').click(function() {
cache: false, cache: false,
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
success: function(data) { success: function(data) {
msg_bd.children('.reply-list').html(data['html']).removeClass('hide'); msg_bd.children('.reply-bd').html(data['html']).attr('class', 'reply-bd');
} msg_bd.find('.reply-at').click(function() {
}); msg_bd.find('.reply-input').val('@' + $(this).attr('data') + ' ').focus();
msg_bd.children('.reply-form').removeClass('hide'); });
$(this).addClass('hide'); msg_bd.find('.submit').click(function() {
msg_bd.children('.replyclose').removeClass('hide'); var reply = $.trim(msg_bd.find('.reply-input').val());
return false; if (reply && reply.length <= 150) {
}); $.ajax({
type: "POST",
function reply_at(nickname, msgID) { url: '{{ SITE_ROOT }}group/reply/' + msg_id + '/',
var form_selector = '#form'+msgID+' .text-input'; dataType: 'json',
$(form_selector).focus(); cache: false,
$(form_selector).val(nickname); contentType: 'application/json; charset=utf-8',
return false; beforeSend: prepareCSRFToken,
} data: "message=" + reply,
success: function(data) {
$('.replyclose').click(function() { msg_bd.find('.reply-list').append(data['html']);
var msg_bd = $(this).parent(); msg_bd.find('.reply-input').val('');
msg_bd.children('.reply-list').addClass('hide'); msg_bd.find('.error').attr('class', 'error hide');
msg_bd.children('.reply-form').addClass('hide'); var reply_cnt = parseInt(msg_bd.find('.reply-cnt').html()) + 1 || 1;
$(this).addClass('hide'); msg_bd.find('.reply-cnt').html(reply_cnt + ' ');
msg_bd.children('.reply').removeClass('hide'); msg_bd.find('.reply-at').click(function() {
return false; msg_bd.find('.reply-input').val('@' + $(this).attr('data') + ' ').focus();
}); });
}
$('.reply-form').each(function(){ });
$(this).submit(function(event) { } else {
var form = $(this), msg_bd.find('.error').removeClass('hide');
m_id = form.children('input[name="msg_id"]').val(),
m = $.trim(form.children('input[name="message"]').val()),
msg_bd = form.parent();
if (m && m.length <= 150) {
$.ajax({
type: "POST",
url: '{{ SITE_ROOT }}group/reply/' + m_id + '/',
dataType: 'json',
cache: false,
contentType: 'application/json; charset=utf-8',
beforeSend: prepareCSRFToken,
data: "message="+m,
success: function(data) {
msg_bd.children('.reply-list').html(data['html']).attr('class', 'reply-list');
form.children('input[name="message"]').val('');
form.children('.error').attr('Class' , 'error hide');
msg_bd.children('.reply').html(data['reply_cnt'] + ' 回复');
} }
}); });
} else {
form.children('.error').removeClass('hide');
} }
return false;
}); });
$(this).addClass('hide');
$(this).next().removeClass('hide'); // show 'replyclose'
}); });
$('.replyclose').click(function() {
$(this).parent().children('.reply-bd').addClass('hide');
$(this).addClass('hide');
$(this).prev().removeClass('hide'); // show 'reply'
});
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -1,13 +1,30 @@
{% load seahub_tags avatar_tags %} {% load seahub_tags avatar_tags %}
<ul> {% if request != 'POST' %}
<ul class="reply-list">
{% for reply in replies %} {% for reply in replies %}
<li class="w100 ovhd"> <li class="w100 ovhd">
<a href="{% url user_profile reply.from_email %}" class="pic fleft">{% avatar reply.from_email 28 %}</a> <a href="{% url user_profile reply.from_email %}" class="pic fleft">{% avatar reply.from_email 28 %}</a>
<div class="txt fright"> <div class="txt fright">
<a href="{% url user_profile reply.from_email %}">{{ reply.nickname }}</a> : {{ reply.message|seahub_urlize|find_at }} -- <a href="{% url user_profile reply.from_email %}">{{ reply.nickname }}</a> : {{ reply.message|seahub_urlize|find_at }} --
<a href="javascript:void(0);" class="" onclick="reply_at('@{{ reply.nickname }} ', {{ msg.id }})">回复</a> <button class="reply-at op" data="{{ reply.nickname }}">回复</button>
</div> </div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<input type="text" name="message" class="reply-input" value=""/>
<button class="submit">回复</button>
<p class="error hide">输入不能为空且应少于150个字符。</p>
{% else %}
<li class="w100 ovhd">
<a href="{% url user_profile reply.from_email %}" class="pic fleft">{% avatar reply.from_email 28 %}</a>
<div class="txt fright">
<a href="{% url user_profile reply.from_email %}">{{ reply.nickname }}</a> : {{ reply.message|seahub_urlize|find_at }} --
<button class="reply-at op" data="{{ reply.nickname }}">回复</button>
</div>
</li>
{% endif %}

View File

@@ -285,18 +285,27 @@ def msg_reply(request, msg_id):
raise HttpResponse(status=400) raise HttpResponse(status=400)
ctx = {} ctx = {}
replies = MessageReply.objects.filter(reply_to=msg) if request.method == 'POST':
for e in replies: e = msg_reply
try: try:
p = Profile.objects.get(user=e.from_email) p = Profile.objects.get(user=e.from_email)
e.nickname = p.nickname e.nickname = p.nickname
except Profile.DoesNotExist: except Profile.DoesNotExist:
e.nickname = e.from_email.split('@')[0] e.nickname = e.from_email.split('@')[0]
ctx['replies'] = replies ctx['request'] = 'POST'
ctx['msg'] = msg ctx['reply'] = e
else:
replies = MessageReply.objects.filter(reply_to=msg)
for e in replies:
try:
p = Profile.objects.get(user=e.from_email)
e.nickname = p.nickname
except Profile.DoesNotExist:
e.nickname = e.from_email.split('@')[0]
ctx['replies'] = replies
html = render_to_string("group/group_reply_list.html", ctx) html = render_to_string("group/group_reply_list.html", ctx)
serialized_data = json.dumps({"html": html, serialized_data = json.dumps({"html": html})
"reply_cnt": len(replies)})
return HttpResponse(serialized_data, content_type=content_type) return HttpResponse(serialized_data, content_type=content_type)
else: else:
return HttpResponseBadRequest(content_type=content_type) return HttpResponseBadRequest(content_type=content_type)

View File

@@ -708,20 +708,21 @@ p {
.msg-hd .group { .msg-hd .group {
margin-left:30px; margin-left:30px;
} }
.msg-bd .op:hover {
text-decoration:none;
}
.msg-bd a { .msg-bd a {
font-weight: normal; font-weight: normal;
} }
.msg-bd .recommend { .msg-bd .op {
color: #880088; padding:0;
background:none;
border:none;
} }
.msg-bd .recommend,
.msg-bd .at { .msg-bd .at {
color:#808; color:#808;
} }
.reply-list { .reply-list {
color:#444; color:#444;
font-size:12px;
width:90%; width:90%;
} }
.reply-list li { .reply-list li {
@@ -730,13 +731,15 @@ p {
.reply-list .txt { .reply-list .txt {
width: 93%; width: 93%;
} }
.reply-list a { .reply-input {
font-size:12px;
}
.reply-form .text-input {
width:82%; width:82%;
} }
.reply-at {
font-size:12px;
}
.reply-at:hover {
color:#f93;
}
/*file upload*/ /*file upload*/
.upload-file-panel { .upload-file-panel {
width:400px; width:400px;