2020-01-27 20:37:52 +00:00
|
|
|
{% extends "base.html" %}
|
2020-06-08 20:11:07 +00:00
|
|
|
{% block title_row %}{% endblock %}
|
|
|
|
{% block title_ruler %}{% endblock %}
|
2020-08-02 22:34:06 +00:00
|
|
|
{% block title %} {{_('Chat Box')}} {% endblock %}
|
2020-01-27 20:37:52 +00:00
|
|
|
{% block js_media %}
|
2020-06-08 20:11:07 +00:00
|
|
|
|
2020-05-17 18:35:32 +00:00
|
|
|
<script type="text/javascript" src="{{ static('mathjax_config.js') }}"></script>
|
2021-06-19 03:26:43 +00:00
|
|
|
<script type="text/javascript" src="{{ static('event.js') }}"></script>
|
|
|
|
|
2020-01-27 20:37:52 +00:00
|
|
|
<script type="text/javascript">
|
2021-06-19 03:26:43 +00:00
|
|
|
window.currentPage = 1;
|
2020-03-21 04:48:04 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
function load_page(page) {
|
|
|
|
$.get('?page=' + page)
|
|
|
|
.fail(function() {
|
|
|
|
console.log("Fail to load page " + page);
|
|
|
|
})
|
|
|
|
.done(function(data) {
|
|
|
|
setTimeout(function() {
|
|
|
|
let container = $('#chat-box');
|
|
|
|
let lastMsgPos = scrollTopOfBottom(container)
|
|
|
|
|
|
|
|
$('#loader').hide();
|
|
|
|
$('#chat-log').prepend(data);
|
|
|
|
remove_day_if_today();
|
2020-03-20 21:34:33 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
container.scrollTop(scrollTopOfBottom(container) - lastMsgPos);
|
|
|
|
}, 500);
|
|
|
|
})
|
|
|
|
}
|
2020-03-19 05:13:55 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
function scrollTopOfBottom(container) {
|
|
|
|
return container[0].scrollHeight - container.innerHeight()
|
|
|
|
}
|
2020-03-19 22:51:56 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
function scrollContainer(container, loader) {
|
|
|
|
container.scroll(function() {
|
|
|
|
if (container.scrollTop() == 0) {
|
|
|
|
if (currentPage < {{paginator.num_pages}}) {
|
|
|
|
currentPage++;
|
|
|
|
loader.show();
|
|
|
|
load_page(currentPage);
|
|
|
|
}
|
2020-03-21 04:48:04 +00:00
|
|
|
}
|
2021-06-19 03:26:43 +00:00
|
|
|
})}
|
2020-03-21 04:48:04 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
function remove_day_if_today() {
|
|
|
|
$('.message_date').each(function() {
|
|
|
|
sent_date = $(this).html()
|
|
|
|
if (sent_date === "{{today}}") {
|
|
|
|
$(this).hide();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
window.load_dynamic_update = function (last_msg) {
|
|
|
|
return new EventReceiver(
|
|
|
|
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
|
|
|
|
['chat'], last_msg, function (message) {
|
|
|
|
switch (message.type) {
|
|
|
|
case 'new_message':
|
|
|
|
add_new_message(message.message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-21 04:48:04 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
function add_new_message(message) {
|
|
|
|
// console.log(message);
|
|
|
|
$.get({
|
|
|
|
url: "{{ url('chat_message_ajax') }}",
|
|
|
|
data: {
|
|
|
|
message: message,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
$('#chat-log').append($(data));
|
|
|
|
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight)
|
|
|
|
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
|
|
|
|
},
|
|
|
|
error: function (data) {
|
|
|
|
if (data.status === 403)
|
|
|
|
console.log('No right to see: ' + message);
|
|
|
|
else {
|
|
|
|
console.log('Could not load chat message:');
|
|
|
|
console.log(data.responseText);
|
2020-03-21 04:48:04 +00:00
|
|
|
}
|
2020-03-19 22:51:56 +00:00
|
|
|
}
|
2021-06-19 03:26:43 +00:00
|
|
|
});
|
|
|
|
}
|
2020-03-21 04:48:04 +00:00
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
$(function() {
|
|
|
|
$('#loader').hide();
|
|
|
|
|
2020-03-21 04:48:04 +00:00
|
|
|
scrollContainer($('#chat-box'), $('#loader'))
|
2020-03-19 05:13:55 +00:00
|
|
|
|
2020-05-17 18:01:59 +00:00
|
|
|
{% if request.user.is_staff %}
|
2020-05-05 18:17:42 +00:00
|
|
|
$(document).on("click", ".chatbtn_remove_mess", function() {
|
|
|
|
var elt = $(this);
|
|
|
|
$.ajax({
|
2021-06-19 03:26:43 +00:00
|
|
|
url: "{{ url('delete_chat_message') }}",
|
2020-05-05 18:17:42 +00:00
|
|
|
type: 'post',
|
2021-06-19 03:26:43 +00:00
|
|
|
data: {
|
|
|
|
message: elt.attr('value'),
|
|
|
|
},
|
2020-05-05 18:17:42 +00:00
|
|
|
dataType: 'json',
|
|
|
|
success: function(data){
|
2021-06-17 00:39:09 +00:00
|
|
|
elt.closest('li').hide();
|
|
|
|
},
|
|
|
|
fail: function(data) {
|
|
|
|
alert('Fail to delete');
|
|
|
|
},
|
2020-05-05 18:17:42 +00:00
|
|
|
});
|
|
|
|
});
|
2020-05-17 18:01:59 +00:00
|
|
|
{% endif %}
|
2020-03-21 04:48:04 +00:00
|
|
|
|
2020-03-19 05:13:55 +00:00
|
|
|
$("#chat-submit").click(function() {
|
|
|
|
if ($("#chat-input").val().trim()) {
|
2020-03-19 22:51:56 +00:00
|
|
|
let body = $('#chat-input').val().trim();
|
2021-06-19 03:26:43 +00:00
|
|
|
let img = '{{ gravatar(request.user, 32) }}';
|
2020-03-19 05:13:55 +00:00
|
|
|
|
|
|
|
message = {
|
2021-06-19 03:26:43 +00:00
|
|
|
body: body,
|
|
|
|
};
|
2020-03-19 05:13:55 +00:00
|
|
|
|
2021-06-19 06:09:16 +00:00
|
|
|
$('#chat-input').val('');
|
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
$.post("{{ url('post_chat_message') }}", message)
|
|
|
|
.fail(function(res) {
|
|
|
|
console.log('Fail to send message');
|
|
|
|
})
|
|
|
|
.done(function(res, status) {
|
2021-06-19 06:09:16 +00:00
|
|
|
$('#chat-input').focus();
|
2021-06-19 03:26:43 +00:00
|
|
|
})
|
2020-03-19 05:13:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#chat-log").change(function() {
|
|
|
|
$('#chat-log').scrollTop($('#chat-log')[0].scrollHeight);
|
2020-01-27 20:37:52 +00:00
|
|
|
});
|
2020-03-19 05:13:55 +00:00
|
|
|
|
|
|
|
$('#chat-input').focus();
|
|
|
|
|
|
|
|
$('#chat-input').keydown(function(e) {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
if (e.ctrlKey || e.shiftKey) {
|
|
|
|
var val = this.value;
|
|
|
|
if (typeof this.selectionStart == "number" && typeof this.selectionEnd == "number") {
|
|
|
|
var start = this.selectionStart;
|
|
|
|
this.value = val.slice(0, start) + "\n" + val.slice(this.selectionEnd);
|
|
|
|
this.selectionStart = this.selectionEnd = start + 1;
|
|
|
|
} else if (document.selection && document.selection.createRange) {
|
|
|
|
this.focus();
|
|
|
|
var range = document.selection.createRange();
|
|
|
|
range.text = "\r\n";
|
|
|
|
range.collapse(false);
|
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#chat-submit').click();
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2020-01-27 20:37:52 +00:00
|
|
|
});
|
2020-03-19 05:13:55 +00:00
|
|
|
|
2020-06-08 20:11:07 +00:00
|
|
|
$('.chat-right-panel').hide();
|
|
|
|
$('#chat-tab').find('a').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#chat-tab').addClass('active');
|
|
|
|
$('#online-tab').removeClass('active');
|
|
|
|
$('.chat-left-panel').show();
|
|
|
|
$('.chat-right-panel').hide();
|
|
|
|
});
|
|
|
|
$('#online-tab').find('a').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#online-tab').addClass('active');
|
|
|
|
$('#chat-tab').removeClass('active');
|
|
|
|
$('.chat-left-panel').hide();
|
|
|
|
$('.chat-right-panel').show();
|
|
|
|
});
|
2021-06-19 03:26:43 +00:00
|
|
|
|
|
|
|
$('#refresh-button').on('click', function() {
|
|
|
|
$.get("{{url('online_status_ajax')}}")
|
|
|
|
.fail(function() {
|
|
|
|
console.log("Fail to get online status");
|
|
|
|
})
|
|
|
|
.done(function(data) {
|
|
|
|
if (data.status == 403) {
|
|
|
|
console.log("Fail to retrieve data");
|
|
|
|
}
|
|
|
|
else {
|
2021-07-02 06:38:48 +00:00
|
|
|
$('#chat-online-content').html(data).find('.toggle').each(function () {
|
|
|
|
register_toggle($(this));
|
|
|
|
});;
|
2021-06-19 03:26:43 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-06-19 06:09:16 +00:00
|
|
|
setInterval(function() {
|
|
|
|
$('#refresh-button').click();
|
|
|
|
}, 5 * 60 * 1000);
|
|
|
|
|
2021-06-19 03:26:43 +00:00
|
|
|
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
|
|
|
remove_day_if_today();
|
|
|
|
load_dynamic_update({{last_msg}});
|
2020-06-08 20:11:07 +00:00
|
|
|
});
|
2020-01-27 20:37:52 +00:00
|
|
|
</script>
|
2020-05-18 06:39:19 +00:00
|
|
|
|
2020-01-27 20:37:52 +00:00
|
|
|
{% endblock js_media %}
|
2020-06-08 23:19:09 +00:00
|
|
|
|
2020-06-10 18:31:53 +00:00
|
|
|
{% block media %}
|
2021-06-19 03:26:43 +00:00
|
|
|
<style>
|
|
|
|
#content {
|
|
|
|
margin-top: -0.5em;
|
|
|
|
}
|
|
|
|
#refresh-button {
|
2021-07-02 17:03:06 +00:00
|
|
|
padding: 0;
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: 0.3em;
|
|
|
|
background: transparent;
|
|
|
|
border: none;
|
|
|
|
height: 1.5em;
|
|
|
|
width: 1.5em;
|
2021-06-19 03:26:43 +00:00
|
|
|
}
|
|
|
|
#refresh-button:hover {
|
|
|
|
background: lightgreen;
|
2021-07-02 17:03:06 +00:00
|
|
|
-webkit-transform: rotate(360deg);
|
|
|
|
transform: rotate(360deg);
|
|
|
|
transition: 1.5s ease-in-out;
|
2021-06-19 03:26:43 +00:00
|
|
|
}
|
2021-07-02 06:38:48 +00:00
|
|
|
.status-pic {
|
|
|
|
height: 1.3em;
|
|
|
|
width: 1.3em;
|
|
|
|
border-radius: 0.3em;
|
|
|
|
}
|
|
|
|
.status-container {
|
|
|
|
position: relative;
|
|
|
|
display: inline-flex;
|
|
|
|
}
|
|
|
|
.status-circle {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
|
|
|
cx: 18;
|
|
|
|
cy: 18;
|
|
|
|
r: 4.5;
|
|
|
|
stroke: white;
|
|
|
|
stroke-width: 1;
|
|
|
|
}
|
|
|
|
.status-row {
|
|
|
|
display: flex;
|
|
|
|
margin-bottom: 0.5em;
|
|
|
|
font-size: 15px;
|
|
|
|
}
|
|
|
|
.status-list {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
.status-section-title {
|
|
|
|
cursor: pointer;
|
2021-07-02 17:03:06 +00:00
|
|
|
margin-top: 0.5em;
|
2021-07-02 06:38:48 +00:00
|
|
|
}
|
|
|
|
::-webkit-scrollbar {
|
2021-07-02 17:03:06 +00:00
|
|
|
width: 20px;
|
2021-07-02 06:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-track {
|
2021-07-02 17:03:06 +00:00
|
|
|
background-color: transparent;
|
2021-07-02 06:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb {
|
2021-07-02 17:03:06 +00:00
|
|
|
background-color: #d6dee1;
|
|
|
|
border-radius: 20px;
|
|
|
|
border: 6px solid transparent;
|
|
|
|
background-clip: content-box;
|
2021-07-02 06:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
2021-07-02 17:03:06 +00:00
|
|
|
background-color: #a8bbbf;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media (min-width: 800px) {
|
|
|
|
#page-container {
|
|
|
|
position:fixed;
|
|
|
|
overflow:hidden;
|
|
|
|
}
|
2021-07-02 06:38:48 +00:00
|
|
|
}
|
2021-07-08 22:09:30 +00:00
|
|
|
|
2021-07-08 22:10:53 +00:00
|
|
|
#page-container {
|
2021-07-08 22:09:30 +00:00
|
|
|
width: 100%;
|
|
|
|
}
|
2021-06-19 03:26:43 +00:00
|
|
|
</style>
|
2020-06-08 22:08:24 +00:00
|
|
|
{% endblock media %}
|
2020-06-10 18:31:53 +00:00
|
|
|
|
2020-01-27 20:37:52 +00:00
|
|
|
{% block body %}
|
2020-06-08 20:11:07 +00:00
|
|
|
{% csrf_token %}
|
|
|
|
{% block before_posts %}{% endblock %}
|
|
|
|
<div id="mobile" class="tabs">
|
|
|
|
<ul>
|
|
|
|
<li id="chat-tab" class="tab active"><a href="#">
|
|
|
|
<i class="tab-icon fa fa-comments"></i> {{ _('Chat') }}
|
|
|
|
</a></li>
|
|
|
|
<li id="online-tab" class="tab"><a href="#"><i class="tab-icon fa fa-wifi"></i> {{ _('Online Users') }}</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="chat-container">
|
|
|
|
<div id="chat-area" class="chat-left-panel">
|
|
|
|
<div id="chat-box">
|
|
|
|
<img src="http://opengraphicdesign.com/wp-content/uploads/2009/01/loader64.gif" id="loader">
|
|
|
|
<ul id="chat-log">
|
2021-06-19 03:26:43 +00:00
|
|
|
{% include 'chat/message_list.html' %}
|
2020-06-08 20:11:07 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<textarea id="chat-input" placeholder="{{_('Enter your message')}}"></textarea>
|
|
|
|
</div>
|
|
|
|
<button id="chat-submit" style="display:none;"> Send </button>
|
|
|
|
<div id="chat-online" class="chat-right-panel sidebox">
|
2021-07-02 17:03:06 +00:00
|
|
|
<h3 style="display:flex">
|
2021-06-19 03:26:43 +00:00
|
|
|
{{_('Online Users')}}
|
2021-07-02 17:03:06 +00:00
|
|
|
<button id="refresh-button" title="{{_('Refresh')}}">
|
|
|
|
<img src="/reload.png"
|
|
|
|
width="100%"
|
|
|
|
>
|
|
|
|
</button>
|
2020-06-08 20:11:07 +00:00
|
|
|
</h3>
|
2021-07-02 06:55:45 +00:00
|
|
|
<div id="chat-online-content">
|
2021-06-19 03:26:43 +00:00
|
|
|
{% include "chat/online_status.html" %}
|
2021-07-02 06:55:45 +00:00
|
|
|
</div>
|
2020-03-20 21:34:33 +00:00
|
|
|
</div>
|
2020-03-16 07:56:55 +00:00
|
|
|
</div>
|
2020-06-08 20:11:07 +00:00
|
|
|
|
2021-06-19 06:09:16 +00:00
|
|
|
{% endblock body %}
|