diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index 9979d64..c665e3b 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -66,6 +66,15 @@ def get_chat_receivers_for_user(user): # # return list(set(receivers_list)) + +def get_tickets_Dict_by_manager(user): + tickets = MsgGroup.objects.filter(enable=True, manager=user).order_by('-modifiedDT') + + Dict = { + 'tickets': tickets, + } + return Dict + def get_messages_for_ticket(ticket): return ticket.rel_messages_for_group.filter(enable=True).order_by('-modifiedDT') diff --git a/ChatServiceApp/js_views.py b/ChatServiceApp/js_views.py index 4695d82..8bfd8b4 100644 --- a/ChatServiceApp/js_views.py +++ b/ChatServiceApp/js_views.py @@ -76,8 +76,15 @@ def update_chat_ajax(request): }) msgs = get_messages_for_ticket(ticket) + context_Dict = get_ticketsDict_for_staff(request.user) + tickets_list_html = render_to_string( + 'blocks/profile/b_list_of_tickets_support_chat.html', context_Dict, request=request) + res_Dict.update({'tickets_list_html': tickets_list_html}) else: msgs = get_msgs_for_chat_w_users(sender, receiver) + users_list_html = render_to_string( + 'blocks/profile/b_list_of_users_messenger.html', res_Dict, request=request) + res_Dict.update({'users_list_html': users_list_html}) if not msgs or (request.user != msgs[0].receiver) or (not msgs and not last_message_modifiedDT) or (msgs and last_message_modifiedDT and msgs[0].modifiedDT <= last_message_modifiedDT): Dict.update({ @@ -86,6 +93,7 @@ def update_chat_ajax(request): return JsonResponse(Dict, status=200) + res_Dict.update({ 'messages': msgs, 'cur_receiver': receiver, @@ -94,11 +102,10 @@ def update_chat_ajax(request): html = render_to_string(tpl_name, res_Dict, request=request) res_Dict.update({'receivers': get_chat_receivers_for_user(request.user)}) - users_list_html = render_to_string('blocks/profile/b_list_of_users_messenger.html', res_Dict, request=request) + Dict.update({ 'html': html, - 'users_list_html': users_list_html, 'required_beep': True, }) return JsonResponse(Dict, status=200) diff --git a/static/js/check_new_messages.js b/static/js/check_new_messages.js index b5f00df..0c8e535 100644 --- a/static/js/check_new_messages.js +++ b/static/js/check_new_messages.js @@ -1,36 +1,73 @@ +window.onload = function () { + funcFocus() +} +// +// document.querySelector(".enter-message-inp").onload( +// funcFocus() +// ) +function funcFocus(){ -$(document).ready( - check_new_messages_timeout() - -) + let inp = document.querySelector(".enter-message-inp") + if (inp !== null){ + inp.focus() + } +} var check_msg = null var it = 0 -function check_new_messages_timeout(){ + + +// function initial_function (){ +// var it_set_func = 0 +// var it_func = 0 +// check_new_messages_timeout(60000,it_set_func,it_func) +// } + +function check_new_messages_timeout(timeout_time=1000){ let window = document.querySelector(".container-messages") - if (window !== null){ - - - } + // if (window !== null){ + // + // + // } + // if (it_set_func === 0){ + // // clearInterval(check_msg) + // if (window === null){ + // it_set_func++ + // check_new_messages_timeout(60000,it_set_func,it_func) + // } else { + // let new_timeout_time = 1000 + // it_set_func++ + // check_new_messages_timeout(new_timeout_time,it_set_func,it_func) + // } + // + // } check_msg = setInterval(function () { - // let new_message = getNewMessageSession() - // let user_online = userOnline('set') - window = document.querySelector(".container-messages") - if (window === null){ + + // let new_message = getNewMessageSession() + // let user_online = userOnline('set') + window = document.querySelector(".container-messages") + if (window === null){ + // let new_timeout_time = 60000 // - } else { - it = 0 - check_new_messages(window) - } - }, - 60000) + // check_new_messages_timeout(new_timeout_time,it_set_func,it_func) + } else { + // if (it_func === 0){ + // let new_timeout_time = 1000 + // it_func++ + // check_new_messages_timeout(new_timeout_time,it_set_func,it_func) + // } + check_new_messages(window) + } + + }, + timeout_time) } @@ -114,6 +151,9 @@ function success_check_new_messages (data) { if (data.users_list_html){ document.querySelector(".block-list-of-users").innerHTML = data.users_list_html } + if (data.tickets_list_html){ + document.querySelector(".block-list-of-users").innerHTML = data.tickets_list_html + } // let updatedCookie = encodeURIComponent(name_cookie) + "=" + encodeURIComponent(''); // let search_cookie = document.cookie.match("(^|[^;]+)\s*" + name_cookie + "\s*=\s*([^;]+)")[0].substring(1) // let search_cookie = getCookieValue('user_alerts') diff --git a/static/js/user_profile(boris).js b/static/js/user_profile(boris).js index 92d7aaf..ea740bf 100644 --- a/static/js/user_profile(boris).js +++ b/static/js/user_profile(boris).js @@ -184,7 +184,9 @@ function selectedUserMessenger (ticket_id=null,user_id=null){ getNewMessageSession() } + document.querySelector(".info_profile").innerHTML = data.html; + document.querySelector(".enter-message-inp").focus() }, error: function (data){ diff --git a/templates/blocks/b_user_profile.html b/templates/blocks/b_user_profile.html index 374ebec..9507e50 100644 --- a/templates/blocks/b_user_profile.html +++ b/templates/blocks/b_user_profile.html @@ -1,4 +1,4 @@ -
+
{% csrf_token %}