diff --git a/api/views.py b/api/views.py index 8e4c5fd..a998e92 100755 --- a/api/views.py +++ b/api/views.py @@ -115,6 +115,7 @@ class OrderViewSet(ModelViewSet): queryset = Order.objects.all() serializer_class = OrderSerializer filter_class = OrderFilterSet + permission_classes = (permissions.IsAuthenticatedOrReadOnly,) class SpecializationViewSet(ModelViewSet): diff --git a/assets/js/chat.js b/assets/js/chat.js index 2b07259..823bafe 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -1,6 +1,6 @@ var SocketHandler = function () { domain = domain.replace(':' + port, ''); - var url = 'ws://' + domain + '/chat/' + userId + '/'; + var url = 'ws://' + domain + ':8888/chat/' + userId + '/'; var sock = new WebSocket(url); var intervalId; sock.onopen = function () { @@ -21,7 +21,7 @@ var SocketHandler = function () { inbox = document.getElementById('message-chat-team-space'); } else if (message.answer_type == 'approve_stages') { var resOrderId = message.order_id; - $.jGrowl(message.msg,{ + $.jGrowl(message.msg, { life: 4000 }); setTimeout(function () { @@ -34,12 +34,12 @@ var SocketHandler = function () { var classMessage = 'youChat'; var senderName = 'Вы'; var timeMessage = message.msg_time; - if (message.sender_id != userId){ + if (message.sender_id != userId) { senderName = message.sender_name; classMessage = ''; } - inbox.innerHTML += '
' + - '

'+ senderName +'

' + timeMessage + '
' + + inbox.innerHTML += '
' + + '

' + senderName + '

' + timeMessage + '
' + '

' + textMessage + '

'; } @@ -98,17 +98,32 @@ function csrfSafeMethod(method) { return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); } +var socket = new SocketHandler(); +var csrftoken = getCookie('csrftoken'); $(function () { - setTimeout(function () { - $(".user-block").first().trigger('click'); - }, 10); + var currentHash = URI(location.href).hash(); + console.log(currentHash); + if (currentHash.indexOf("#order") == 0) { - setTimeout(function () { - $(".order-block").last().trigger('click'); - $("a[href='#tab2']").trigger('click'); - }, 100); + var ordHashId = currentHash.replace("#order", ""); + setTimeout(function () { + $("#orderBlock" + ordHashId).trigger('click'); + $("a[href='#tab2']").trigger('click'); + }, 100); + } else if (currentHash.indexOf("#team") == 0) { + + } else { + + setTimeout(function () { + $(".user-block").first().trigger('click'); + }, 10); + + setTimeout(function () { + $(".order-block").last().trigger('click'); + }, 100); + } $('.deleteMess').on('click', function (e) { @@ -123,10 +138,10 @@ $(function () { beforeSend: function (xhr) { xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) }, - data: {'sender_id':senderId, 'recipent_id': recipentId}, + data: {'sender_id': senderId, 'recipent_id': recipentId}, dataType: 'json', success: function (json) { - if (json.status == 'ok'){ + if (json.status == 'ok') { _this.parent().remove(); $("#message-chat-space").html(""); } @@ -161,6 +176,130 @@ $(function () { } }); }); + + + // Добавление сообщения для заказа. + $('#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(""); + $("#document-send-order").html(""); + }); + + // Добавление отзыва + $('#order-review-add').on('click', function (e) { + e.preventDefault(); + e.stopPropagation(); + var formData = $("#review-adds-form").serialize(); + $.ajax({ + url: '/api/reviews/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: formData, + dataType: 'json', + success: function (json) { + console.log("Успешно"); + $("#review-add").modal('hide'); + $.jGrowl("Ваш отзыв успешно добавлен", { + life: 4000 + }); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + + // Добавление сообщения в арбитраж + $('#order-arbitration-add').on('click', function (e) { + e.preventDefault(); + e.stopPropagation(); + var formData = $("#arbitration-add-form").serialize(); + $.ajax({ + url: '/projects/arbitration/create/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: formData, + dataType: 'json', + success: function (json) { + console.log(json); + $("#arbitration-add").modal('hide'); + $.jGrowl("Обращение в арбитраж добавлено", { + life: 4000 + }); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + + + + + + //Загрузка документов + $('#upload-document-order').fileupload({ + url: '/chat/create/', + formData: { + sender: $("#chat-order-add #senderId").val(), + recipent: $("#chat-order-add #recipentId").val(), + order: $("#chat-order-add #orderId").val(), + }, + crossDomain: false, + beforeSend: function (xhr, settings) { + $('#progress .progress-bar').css( + 'width', + '0%' + ); + if (!csrfSafeMethod(settings.type)) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + } + }, + dataType: 'json', + done: function (e, data) { + $.each(data.result.files, function (index, file) { + var currentValue = ''; + currentValue += file.id + ';'; + //$("#documentSendIds").val(currentValue); + var htmlImg = '

' + file.name + '

'; + var document_send = $(htmlImg).appendTo("#document-send-order"); + }); + }, + fail: function (e) { + console.log(e); + }, + progressall: function (e, data) { + var progress = parseInt(data.loaded / data.total * 100, 10); + $('#progress .progress-bar').css( + 'width', + progress + '%' + ); + } + }).prop('disabled', !$.support.fileInput) + .parent().addClass($.support.fileInput ? undefined : 'disabled'); + }); diff --git a/chat/migrations/0007_auto_20160826_1458.py b/chat/migrations/0007_auto_20160826_1458.py new file mode 100644 index 0000000..39e17d8 --- /dev/null +++ b/chat/migrations/0007_auto_20160826_1458.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-26 11:58 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat', '0006_message_is_delete'), + ] + + operations = [ + migrations.AlterField( + model_name='documents', + name='recipent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='recipent_documents', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/chat/models.py b/chat/models.py index 04333f5..dd7f79a 100644 --- a/chat/models.py +++ b/chat/models.py @@ -44,7 +44,7 @@ class Documents(models.Model): order = models.ForeignKey(Order, related_name='documents', null=True, blank=True) team = models.ForeignKey(Team, related_name='documents', null=True, blank=True) sender = models.ForeignKey(User, related_name='sender_documents') - recipent = models.ForeignKey(User, related_name='recipent_documents') + recipent = models.ForeignKey(User, related_name='recipent_documents', null=True, blank=True) def __str__(self): return self.file.url diff --git a/chat/response.py b/chat/response.py new file mode 100644 index 0000000..e5e26f0 --- /dev/null +++ b/chat/response.py @@ -0,0 +1,19 @@ +import json +from django.http import HttpResponse + +MIMEANY = '*/*' +MIMEJSON = 'application/json' +MIMETEXT = 'text/plain' + + +def response_mimetype(request): + can_json = MIMEJSON in request.META['HTTP_ACCEPT'] + can_json |= MIMEANY in request.META['HTTP_ACCEPT'] + return MIMEJSON if can_json else MIMETEXT + + +class JSONResponse(HttpResponse): + def __init__(self, obj='', json_opts=None, mimetype=MIMEJSON, *args, **kwargs): + json_opts = json_opts if isinstance(json_opts, dict) else {} + content = json.dumps(obj, **json_opts) + super().__init__(content, mimetype, *args, **kwargs) diff --git a/chat/templates/arbitration_modal.html b/chat/templates/arbitration_modal.html new file mode 100644 index 0000000..af778e9 --- /dev/null +++ b/chat/templates/arbitration_modal.html @@ -0,0 +1,33 @@ + diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index 19d9d13..cf6570b 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -107,7 +107,7 @@

Заказы

{% for order in orders %} -

{{ order }}

@@ -126,18 +126,19 @@
-
- - - - + + + +
-
-

Прикрепить файл

- Не более 10 файлов с общим объемом 500мб +
+ +

Прикрепить файл

- отправить +
+ + отправить
@@ -181,6 +182,13 @@
+ + {% include 'review_add_modal.html' %} + + + {% include 'arbitration_modal.html' %} + +
    @@ -260,10 +268,8 @@
-
- -
- отправить +
+ отправить
@@ -291,19 +297,22 @@ {% endblock %} diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index 9f0bd98..e4c6818 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -66,7 +66,7 @@
- +
@@ -124,26 +124,22 @@
-
-
- - +
+ - - + +
-
-

Прикрепить файл

- - Не более 10 файлов с общим объемом 500мб - +
+ +

Прикрепить файл

+
отправить
-

Этапы работы

@@ -195,12 +191,14 @@ сохранить
- - {% include 'review_add_modal.html' %} + + {% include 'arbitration_modal.html' %} + +
@@ -222,9 +220,7 @@