diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index 06a25f2..3aeba58 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -1439,22 +1439,50 @@ div.dataTables_wrapper div.dataTables_paginate { .message-sender-container .message-field { padding-left: 10px; padding-right: 0px; - height: 46px; + min-height: 46px; + max-height: 90px; text-align: left; } .message-sender-container .message-field h4 { margin-top: 0px; } -.message-sender-container .message-field div { - height: 46px; +.message-sender-container .message-field div.message-container { + min-height: 46px; + max-height: 90px; + overflow-y: scroll; padding-top: 14px; - padding-bottom: 14px; + padding-bottom: 10px; padding-left: 10px; padding-right: 10px; border-width: 1px; border-style: solid; } +.msg_placeholder { + position: absolute; + z-index: 0; + pointer-events: none; + visibility: visible; +} + +#msg_editable { + width: 100%; + z-index: 1; +} + +.action-button { + position: absolute; + bottom: 5px; + right: 20px; + height: 36px; + font-size: 18px; + width: 40px; + padding: 2px; + border: none; + background: none; + margin-bottom: 0px !important; +} + .talking-header { line-height: 0.5 !important; margin-top: 0px; diff --git a/amadeus/static/js/chat.js b/amadeus/static/js/chat.js index d140e8b..23183e8 100644 --- a/amadeus/static/js/chat.js +++ b/amadeus/static/js/chat.js @@ -18,13 +18,47 @@ function getModalInfo(btn, space, space_type) { $(this).animate({scrollTop: height}, 0); }); + + setShortChatFormSubmit(); + }); + + $("#msg_editable").on('click', function () { + $(this).trigger('focusin'); + }); + + $("#msg_editable").on('focusin', function () { + $("#send-img").hide(); + $("#send-msg").show(); + + $(".msg_placeholder").hide(); + }); + + $("#msg_editable").on('focusout', function (event) { + if (!$(event.relatedTarget).is("#send-msg")) { + $("#send-img").show(); + $("#send-msg").hide(); + + var content = $(this).html(); + + if (content == "") { + $(".msg_placeholder").show(); + } + } + }); + + $("#msg_editable").on('keydown', function (e) { + if (e.keyCode == 13 && !e.shiftKey) { + e.preventDefault(); + + $("#short-chat").submit(); + } }); } }); } function getForm(field) { - var url = field.find('h4').data('url'); + var url = field.data('url'); $.ajax({ url: url, @@ -74,4 +108,50 @@ function setChatFormSubmit() { return false; }); +} + +function setShortChatFormSubmit() { + var frm = $('#short-chat'), + editable = $("#msg_editable"); + + frm.submit(function (e) { + e.preventDefault(); + e.stopImmediatePropagation(); + + if (editable.html() != "") { + $("#id_text").val("
" + editable.html() + "
"); + var formData = new FormData($(this)[0]); + + $.ajax({ + type: frm.attr('method'), + url: frm.attr('action'), + data: formData, + dataType: "json", + async: false, + success: function (data) { + $('.messages-list').append(data.view); + + $(".messages-container").each(function () { + var height = $(this)[0].scrollHeight; + + $(this).animate({scrollTop: height}, 0); + }); + + editable.html(""); + editable.trigger("focusout"); + + alertify.success(data.message); + }, + error: function(data) { + alertify.error(data.responseText); + setShortChatFormSubmit(); + }, + cache: false, + contentType: false, + processData: false + }); + } + + return false; + }); } \ No newline at end of file diff --git a/chat/templates/chat/talk.html b/chat/templates/chat/talk.html index e3c73d2..8c6b997 100644 --- a/chat/templates/chat/talk.html +++ b/chat/templates/chat/talk.html @@ -1,4 +1,5 @@ {% load static i18n chat_tags %} +{% load widget_tweaks %} {% is_online participant as status %} @@ -56,8 +57,20 @@ diff --git a/chat/views.py b/chat/views.py index 77d1136..8bbf995 100644 --- a/chat/views.py +++ b/chat/views.py @@ -137,7 +137,9 @@ class GetTalk(LoginRequiredMixin, generic.ListView): context['talk_id'] = self.talk_id context['space'] = self.request.GET.get('space', '0') context['space_type'] = self.request.GET.get('space_type', 'general') - + context['form'] = ChatMessageForm() + context['form_url'] = reverse_lazy('chat:create', args = (), kwargs = {'email': self.kwargs.get('email', ''), 'talk_id': self.talk_id, 'space': self.kwargs.get('space', '0'), 'space_type': self.kwargs.get('space_type', 'general')}) + return context class SendMessage(LoginRequiredMixin, generic.edit.CreateView): @@ -205,7 +207,7 @@ class SendMessage(LoginRequiredMixin, generic.edit.CreateView): def get_context_data(self, **kwargs): context = super(SendMessage, self).get_context_data(**kwargs) - context['form_url'] = reverse_lazy('chat:create', args = (), kwargs = {'email': self.kwargs.get('email', ''), 'talk_id': self.kwargs.get('talk_id', None), 'space': self.kwargs.get('space', '0'), 'space_type': self.kwargs.get('space_type', 'general')}) + context['form_url'] = reverse_lazy('chat:create', args = (), kwargs = {'email': self.kwargs.get('email', ''), 'talk_id': self.kwargs.get('talk_id', '-1'), 'space': self.kwargs.get('space', '0'), 'space_type': self.kwargs.get('space_type', 'general')}) return context -- libgit2 0.21.2