1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 06:33:48 +00:00

[msg] enable 'add files' for msg-send in user-msg-list page

This commit is contained in:
llj
2014-03-13 14:07:44 +08:00
parent f889c4668b
commit 38283e2ab7
4 changed files with 106 additions and 8 deletions

View File

@@ -10,6 +10,16 @@
<span class="time">{{ msg.timestamp|translate_seahub_time }}</span>
</div>
<p class="msg-con">{{ msg.message|seahub_urlize|find_at|linebreaksbr }}</p>
{% if msg.attachments %}
<ul class="msg-attachment">
{% for att in msg.attachments %}
<li>
<img src="{{ MEDIA_URL }}img/file/{{ att.name|file_icon_filter }}" alt="{% trans "File"%}" height="18" class="vam" />
<a href="{% url 'view_priv_shared_file' att.token %}" target="_blank" class="vam">{{ att.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
<span class="say"></span>
</div>
</div>

View File

@@ -3,6 +3,20 @@
{% block sub_title %}{% trans "Messages" %} - {% endblock %}
{% block extra_style %}
<style type="text/css">
#selected-files .item {
padding:2px 3px;
}
#selected-files .item.hl {
background:#e8e8e8;
}
#selected-files .icon-remove {
cursor:pointer;
}
</style>
{% endblock %}
{% block cur_messages %}tab-cur{% endblock %}
{% block right_panel %}
@@ -17,10 +31,20 @@
{% for error in form.message.errors %}
<p class="error">{{ error|escape }}</p>
{% endfor %}
<ul class="hide" id="selected-files"></ul>
<button type="submit" class="submit hide">{% trans "Submit" %}</button>
<button type="button" class="cancel hide">{% trans "Cancel" %}</button>
<img src="{{ MEDIA_URL }}img/file/file.png" alt="" title="{% trans "Add files" %}" class="add-file vam hide" style="cursor:pointer;" />
<span class="say"></span>
</form>
<div id="add-file-popup" class="file-choose-form hide">
<h3>{% trans "Choose a file or files:" %}</h3>
<div class="file-tree-cont" id="file-tree">
<img src="{{MEDIA_URL}}img/loading-icon.gif" alt="" class="loading-tip" />
</div>
<input type="submit" value="{% trans "Submit" %}" class="submit" />
<button class="simplemodal-close">{% trans "Cancel"%}</button>
</div>
{% endif %}
{% if person_msgs %}
@@ -116,18 +140,73 @@ $(window).scroll(function() {
$('#message').focus(function() {
$(this).height(75);
$('#personal-message-form').find('.submit, .cancel').removeClass('hide');
$('#personal-message-form').find('.submit, .cancel, .add-file').removeClass('hide');
});
$('#personal-message-form .cancel').click(function() {
$(this).addClass('hide');
$('#personal-message-form .submit').addClass('hide');
$('.submit, .add-file', $('#personal-message-form')).addClass('hide');
$('#selected-files').data('files', '').html('').addClass('hide');
$('#message').val('').height(25);
});
$('#personal-message-form .add-file').click(function(){
$('#add-file-popup').modal();
$.ajax({
'url': '{% url 'get_my_unenc_repos' %}',
'cache': false,
'dataType': 'json',
'success': function(data) {
var file_tree = new FileTree();
var repos = file_tree.format_repo_data(data);
if (repos.length > 0) {
file_tree.renderFileTree($('#file-tree').data('site_root', '{{SITE_ROOT}}'), repos, {'two_state': true});
} else {
$('#file-tree').html('<p class="error">' + "{% trans "You don't have any library at present" %}" + '</p>');
}
},
'error': function(jqXHR, textStatus, errorThrown) {
if (!jqXHR.responseText) {
$('#file-tree').html('<p class="error">' + "{% trans "Failed. Please check the network." %}" + '</p>');
}
}
});
});
$('#add-file-popup .submit').click(function() {
var files_ct = $('#selected-files');
var selected = files_ct.data('files') || [];
$('[name="selected"][checked="checked"]', $('#file-tree')).each(function() {
var val = $(this).val();
if (val.charAt(val.length - 1) != '/') { // only submit file
selected.push($(this).val());
}
});
$.modal.close();
var files = '';
for (var i = 0, len = selected.length; i < len; i++) {
files += '<li class="item">' + selected[i].substr(selected[i].lastIndexOf('/') + 1) + '<span class="icon-remove vh fright" data-index="' + i + '"></span></li>';
}
files_ct.data('files', selected).html(files).removeClass('hide');
$('.item', files_ct).hover(
function() {
$(this).addClass('hl').children('.icon-remove').removeClass('vh');
},
function() {
$(this).removeClass('hl').children('.icon-remove').addClass('vh');
}
);
$('.icon-remove', files_ct).click(function() {
var selected_f = files_ct.data('files');
selected_f.splice($(this).data('index'), 1);
$(this).parent().remove();
files_ct.data('files', selected_f);
});
});
$('#personal-message-form').submit(function() {
var form = $(this),
msg_input = $('[name="mass_msg"]', form),
msg = $.trim(msg_input.val());
msg = $.trim(msg_input.val()),
files_ct = $('#selected-files');
if (!msg) {
return false;
@@ -140,7 +219,8 @@ $('#personal-message-form').submit(function() {
type: 'POST',
dataType: 'json',
beforeSend: prepareCSRFToken,
data: { 'mass_msg': msg, 'mass_email': '{{to_email}}' },
data: { 'mass_msg': msg, 'mass_email': '{{to_email}}', 'selected': files_ct.data('files') || [] },
traditional: true,
success: function(data) {
var new_msg = $(data['html']);
if ($('.msg-list').length == 0) { // the new discussion is the first discussion in this page
@@ -150,6 +230,7 @@ $('#personal-message-form').submit(function() {
bind_del(new_msg);
new_msg.slideDown(400);
msg_input.val('');
files_ct.data('files','').html('').addClass('hide');
enable(sb_btn);
},
error: function (xhr, textStatus, errorThrown) {

View File

@@ -186,15 +186,22 @@ def message_send(request):
continue
usermsg = UserMessage.objects.add_unread_message(username, to_email, mass_msg)
msgs.append(usermsg)
usermsg.attachments = []
if len(attached_items) > 0:
for att_item in attached_items:
repo_id = att_item['repo_id']
path = att_item['path']
pfds = PrivateFileDirShare.objects.add_read_only_priv_file_share(
username, to_email, repo_id, path)
UserMsgAttachment.objects.add_user_msg_attachment(usermsg, pfds)
att = UserMsgAttachment.objects.add_user_msg_attachment(usermsg, pfds)
att.repo_id = repo_id
att.path = path
att.name = os.path.basename(path.rstrip('/'))
att.token = pfds.token
usermsg.attachments.append(att)
msgs.append(usermsg)
email_sended.append(to_email)
html = ''
@@ -205,7 +212,7 @@ def message_send(request):
html = render_to_string('message/all_msg.html', ctx)
else:
ctx['msg'] = msgs[0]
html = render_to_string('message/user_msg.html', ctx)
html = render_to_string('message/user_msg.html', ctx, context_instance=RequestContext(request))
return HttpResponse(json.dumps({"html": html, "error": errors}), content_type=content_type)
else:
return HttpResponse(json.dumps({"html": html, "error": errors}), status=400, content_type=content_type)