diff --git a/assets/js/chat.js b/assets/js/chat.js index 028d93f..8072b98 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -56,53 +56,13 @@ var SocketHandler = function () { }; - this.send_order_message = function (orderId) { - var data = { - "format_type": "order_message", - "order_id": orderId - } - sock.send(JSON.stringify(data)); - console.log(data); - }; - this.send_stages_approve = function (data) { sock.send(JSON.stringify(data)); - console.log(data); }; - this.send_contact_message = function (userId) { - var data = { - "format_type": "add_message", - "user_id": userId - } - sock.send(JSON.stringify(data)); - console.log(data); - }; - - this.add_team_message = function (messageData) { - console.log(messageData); + this.send_message = function (messageData) { sock.send(JSON.stringify(messageData)); } - - this.add_contact_message = function (messageData) { - console.log(messageData); - sock.send(JSON.stringify(messageData)); - }; - - this.send_message = function (form) { - var elements = form.elements; - var data = {}; - var i = 0; - for (var i; i < elements.length; i++) { - if (elements[i].name == 'message') { - data[elements[i].name] = elements[i].value; - } - } - sock.send(JSON.stringify(data)); - var textareaMessage = document.getElementById("message"); - textareaMessage.value = ""; - } - } function csrfSafeMethod(method) { @@ -452,7 +412,7 @@ $(function () { $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; }); - socket.add_contact_message({ + socket.send_message({ "format_type": "add_message_order", "data": { "sender_id": senderId, @@ -485,7 +445,7 @@ $(function () { sendLinkIds += $(this).attr('data-id') + ';'; }); console.log(sendLinkIds); - socket.add_contact_message({ + socket.send_message({ "format_type": "add_message_contact", "data": { "sender_id": senderId, diff --git a/assets/js/chat_contractor.js b/assets/js/chat_contractor.js index c17cc60..fd7d13a 100644 --- a/assets/js/chat_contractor.js +++ b/assets/js/chat_contractor.js @@ -547,7 +547,7 @@ $(function () { $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; }); - socket.add_team_message({ + socket.send_message({ "format_type": "add_message_team", "data": { "sender_id": senderId, diff --git a/assets/js/chat_customer.js b/assets/js/chat_customer.js deleted file mode 100644 index 3e758a9..0000000 --- a/assets/js/chat_customer.js +++ /dev/null @@ -1,320 +0,0 @@ -$(function () { - var currentChatUser = { - { - request.user.pk - } -} - ; - var socket = new SocketHandler(); - var form = document.getElementById('message_form'); - var csrftoken = getCookie('csrftoken'); - - $("#reserve-button").on("click", function (e) { - e.preventDefault(); - var orderId = $(this).attr('data-order-id'); - $.ajax({ - url: '/api/stages/', - type: 'GET', - data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - dataType: 'json', - success: function (json) { - console.log(json.results); - } - }); - }); - - function getStages(orderId, senderId, recipentId) { - - $.ajax({ - url: '/api/stages/', - type: 'GET', - data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - dataType: 'json', - success: function (json) { - var stageCount = json.results.length; - if (stageCount == 0) { - stageCountVal = 1; - } else { - stageCountVal = stageCount; - } - - var htmlInbox = ""; - - var htmlInboxStage = '

Какое кол-во этапов подразумевает работа? ' + - '

'; - - if (stageCount == 0) { - htmlInboxStage += '
' + - '

Этап 1

' + - '' + - '' + - '' + - '' + - '' + - '' + - '
'; - } - var statusNotAgreed = true; - $.each(json.results, function (i, v) { - if (v.status == "not_agreed") { - htmlInbox += '
' + - '

Этап

' + - '' + - '' + - '' + - '' + - '' + - '
'; - } else { - statusNotAgreed = false; - htmlInboxStage = ""; - htmlInbox += '
' + - '

Этап ' + v.pos + '' + v.name + '

' + - '

Результаты этапа:' + v.result + '

' + - '

до Дата

' + v.cost + '
'; - - } - }); - - if (statusNotAgreed) { - htmlInbox += '
Перейти в режим безопасной сделки' + - '
' + - 'отправить на согласование
'; - } - htmlInbox = htmlInboxStage + htmlInbox; - $("#order-stages").html(htmlInbox); - } - }); - } - - setTimeout(function () { - $(".user-block").first().trigger('click'); - }, 10); - - setTimeout(function () { - $(".order-block").first().trigger('click'); - }, 100); - - $("#order-stages").on('click', "#addStagesForm", function (e) { - e.preventDefault(); - $(".new-stages-form").each(function (i, v) { - - $.ajax({ - url: '/api/stages/', - type: 'POST', - beforeSend: function (xhr) { - xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) - }, - data: $(this).serialize(), - dataType: 'json', - success: function (json) { - console.log(json); - }, - error: function (e) { - console.log(e); - } - }); - - }); - - $(".update-stages-form").each(function (i, v) { - var currentStageId = parseInt($(this).attr('data-stage-id')); - $.ajax({ - url: '/api/stages/' + currentStageId + '/', - type: 'PUT', - beforeSend: function (xhr) { - xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) - }, - data: $(this).serialize(), - dataType: 'json', - success: function (json) { - console.log(json); - }, - error: function (e) { - console.log('error'); - console.log(e); - } - }); - }); - - - var currentOrderId = $(this).attr('data-order-id'); - var currentRecipentId = $(this).attr('data-recipent-id'); - - getStages(currentOrderId, userId, currentRecipentId); - - socket.send_stages_approve({ - "format_type": "approve_stages", - "data": { - "sender_id": userId, - "recipent_id": currentRecipentId, - "order_id": currentOrderId, - } - }); - - - }); - - $('#order-stages-tab').on('change', '#countStage', function () { - var countStage = parseInt($(this).val()); - var currentCountStage = $(".numberStepp").length; - - if (countStage > currentCountStage) { - for (var jj = currentCountStage; jj < countStage; jj++) { - var pos = jj + 1; - var lastFormStage = $(".numberStepp").last(); - var orderId = lastFormStage.find('.orderStagesInput').val(); - var addFormTemplate = '
' + - '

Этап ' + pos + '

' + - '' + - '' + - '' + - '' + - '' + - '' - '
'; - - lastFormStage.after(addFormTemplate); - - } - - } else if (countStage < currentCountStage) { - var ii = currentCountStage; - $($(".numberStepp").get().reverse()).each(function () { - var currenFormName = ($(this).find('form').attr('class')); - if (ii > countStage) { - $(this).remove(); - } - ii--; - }); - } - }); - - $('.order-block').on('click', function () { - $("#chat-order-add").css("display", "block"); - $("#formsetStage").css("display", "block"); - - $('.order-block').each(function () { - $(this).removeClass('orAct'); - }); - - $(this).addClass('orAct'); - var orderId = $(this).attr('data-id'); - var recipentId = $(this).attr('data-recipent-id'); - $("#chat-order-add #orderId").val(orderId); - $("#projectReviewId").val(orderId); - $("#reserve-button").attr('data-order-id', orderId); - $("#targetContractorId").val(recipentId); - $("#chat-order-add #recipentId").val(recipentId); - $(".orderStagesInput").val(orderId); - var inbox = document.getElementById('message-chat-order-space'); - inbox.innerHTML = ''; - $.ajax({ - url: '/api/message', - type: 'GET', - data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - dataType: 'json', - success: function (json) { - $.each(json.results, function (i, v) { - var senderName = 'Вы'; - var className = 'youChat'; - - if (v.sender.id !== currentChatUser) { - senderName = v.sender.username; - className = ''; - } - - inbox.innerHTML += '
' + - '

' + senderName + '

' + v.created + '
' + - '

' + v.text + '

'; - }); - } - }); - getStages(orderId, userId, recipentId); - }); - - // Вытащить сообщения для конактов - $('.user-block').on('click', function () { - var userId = $(this).attr('data-id'); - $("#contact-chat-form #recipentId").val(userId); - $("#add-form-contractor-note #recipentNoteContractor").val(userId); - - $('.user-block').each(function () { - $(this).removeClass('mesAct'); - }); - - $(this).addClass('mesAct'); - var inbox = document.getElementById('message-chat-space'); - inbox.innerHTML = ''; - $.ajax({ - url: '/api/message', - type: 'GET', - data: { - csrfmiddlewaretoken: csrftoken, - 'operand': 'in', - 'sender_id': currentChatUser, - 'recipent_id': userId - }, - dataType: 'json', - success: function (json) { - $.each(json.results, function (i, v) { - var senderName = 'Вы'; - var className = 'youChat'; - if (v.sender.id == userId) { - senderName = v.sender.username; - className = ''; - } - inbox.innerHTML += '
' + - '

' + senderName + '

' + v.created + '
' + - '

' + v.text + '

'; - }); - } - }); - - }); - - $('#contact-chat-add-message').on('click', function (e) { - e.preventDefault(); - var chatMessage = $("#chat").val(); - var recipentId = $("#recipentId").val(); - var senderId = $("#senderId").val(); - - socket.add_contact_message({ - "format_type": "add_message_contact", - "data": { - "sender_id": senderId, - "recipent_id": recipentId, - "chat_message": chatMessage, - } - }); - - $("#chat").val(""); - }); - - $('#order-review-add').on('click', function () { - alert('add review'); - }); - - $('#order-chat-add-message').on('click', function (e) { - e.preventDefault(); - var chatMessage = $("#chat-order-add #chat").val(); - var recipentId = $("#chat-order-add #recipentId").val(); - var senderId = $("#chat-order-add #senderId").val(); - var orderId = $("#chat-order-add #orderId").val(); - - socket.add_contact_message({ - "format_type": "add_message_order", - "data": { - "sender_id": senderId, - "recipent_id": recipentId, - "chat_message": chatMessage, - "order_id": orderId, - - } - }); - - $("#chat-order-add #chat").val(""); - }); - -}); -var userId = '{{ request.user.pk }}'; diff --git a/chat/filters.py b/chat/filters.py index 2027c08..5caab95 100644 --- a/chat/filters.py +++ b/chat/filters.py @@ -21,6 +21,7 @@ class MessageFilterSet(FilterSet): recipent = RelatedFilter('users.filters.UserFilterSet') private_type = AllLookupsFilter() team = RelatedFilter('users.filters.TeamFilterSet') + order = RelatedFilter('projects.filters.OrderFilterSet') class Meta: model = Message diff --git a/chat/views.py b/chat/views.py index f520532..5ee3681 100644 --- a/chat/views.py +++ b/chat/views.py @@ -91,7 +91,7 @@ class ChatUserView(LoginRequiredMixin, View): chat_messages = Message.objects.filter(Q(sender=request.user.pk) | Q(recipent=request.user.pk)).order_by( 'created') - your_teams = teams + your_teams = Team.objects.filter(Q(contractors__id=request.user.pk) | Q(owner=request.user)) self.template_name = 'chat_contractor.html' return render(request, self.template_name, {'orders': orders, 'contacts_users': contacts_users, diff --git a/users/templates/contractor_office_chat_projects.html b/users/templates/contractor_office_chat_projects.html index d391fd9..2151a68 100644 --- a/users/templates/contractor_office_chat_projects.html +++ b/users/templates/contractor_office_chat_projects.html @@ -136,8 +136,6 @@ {% endblock %} - - {% block js_block %}