diff --git a/assets/js/chat.js b/assets/js/chat.js index 1375c1f..ab650dd 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -94,6 +94,15 @@ function csrfSafeMethod(method) { $(function () { + setTimeout(function () { + $(".user-block").first().trigger('click'); + }, 10); + + setTimeout(function () { + $(".order-block").first().trigger('click'); + }, 100); + + $('.deleteMess').on('click', function (e) { e.preventDefault(); e.stopPropagation(); diff --git a/assets/js/chat_customer.js b/assets/js/chat_customer.js new file mode 100644 index 0000000..3e758a9 --- /dev/null +++ b/assets/js/chat_customer.js @@ -0,0 +1,320 @@ +$(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/templates/chat_contractor.html b/chat/templates/chat_contractor.html index 48081e4..af98f98 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -156,6 +156,18 @@ +
+

3 / Выполнение работы

+

+ Процесс выполнения задания в заказе до получения + заказчиком итогового результата работы. +

+
+ +
+
+ +
@@ -269,14 +281,6 @@ var form = document.getElementById('message_form'); var csrftoken = getCookie('csrftoken'); - setTimeout(function () { - $(".user-block").first().trigger('click'); - }, 10); - - setTimeout(function () { - $(".order-block").first().trigger('click'); - }, 100); - setTimeout(function () { $(".team-order-block").first().trigger('click'); }, 1000); @@ -448,9 +452,14 @@ console.log(json.results); var htmlInbox = ""; var stagesReservedHtml = ""; + var stagesPaidProcess = []; if (json.results.length > 0) { $.each(json.results, function (i, v) { + + if ((v.status == "in_process") && (v.is_paid)){ + stagesPaidProcess.push(v); + } if (v.is_paid) { stagesReservedHtml += '
  • Сумма за этап ' + v.pos + '.Зарезервирована.
  • '; } else { @@ -459,7 +468,7 @@ htmlInbox += '
    ' + '

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

    ' + '

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

    ' + - '

    ' + v.status + '

    ' + v.cost + '
    '; + '

    ' + v.term + '

    ' + v.cost + '
    '; }); htmlInbox += '
    согласовать
    '; @@ -467,6 +476,20 @@ $("#order-stages").html(htmlInbox); $(".stages-paid").html(stagesReservedHtml); + + if (stagesPaidProcess.length > 0){ + $("#completeWork").show(); + var stage = stagesPaidProcess[0]; + var stageWork = '

    В работе '+ stage.name +'

    ' + + '

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

    ' + + '

    Срок сдачи 25.08.2016 ' + stage.cost + 'р.

    ' + + 'Завершить этап' + + 'Обратитьсяв арбитраж'; + $("#stagesWork").html(stageWork); + }else{ + $("#completeWork").hide(); + } + } }); @@ -494,6 +517,28 @@ }); }); + $('#tab2').on('click','.closeStage', function(e){ + e.preventDefault(); + var stageId = $(this).attr('data-stage-id'); + $.ajax({ + url: '/api/stages/' + stageId + '/', + type: 'PATCH', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: "close_contractor=True", + dataType: 'json', + success: function (json) { + alert(json); + console.log(json); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + // Вытащить сообщения для конактов diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index a3db522..664c422 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -159,7 +159,7 @@

    - Зарезирвировать + Зарезирвировать
    @@ -168,12 +168,16 @@ {% include 'reverse_stage_modal.html' %} -
    -

    3 / Выполнение работы

    -

    - Процесс выполнения задания в заказе до получения заказчиком итогового результата работы. -

    -
    +
    +

    3 / Выполнение работы

    +

    + Процесс выполнения задания в заказе до получения + заказчиком итогового результата работы. +

    +
    + +
    +
    @@ -192,54 +196,7 @@ - - + {% include 'review_add_modal.html' %}
    @@ -268,19 +225,33 @@ var csrftoken = getCookie('csrftoken'); $("#reserve-button").on("click",function(e) { - e.preventDefault(); + e.preventDefault(); + $("#reserve-stage-modal").modal('show'); 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); - } - }); + + $.ajax({ + url: '/api/stages/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + var outputValues = ""; + var totalSum = 0; + $.each(json.results, function (i, v) { + console.log(v.cost); + totalSum += parseInt(v.cost); + outputValues += ""; + + }); + $("#stagesSelect").html(outputValues); + $(".totalSum").text(totalSum); + + } + }); + }); + //Получить заказы function getStages(orderId, senderId, recipentId) { $.ajax({ @@ -313,7 +284,13 @@ ''; } var statusNotAgreed = true; + var stagesPaidProcess = []; + $.each(json.results, function (i, v) { + + if ((v.status == "in_process") && (v.is_paid)){ + stagesPaidProcess.push(v); + } if (v.status == "not_agreed") { htmlInbox += '
    ' + '

    Этап

    ' + @@ -329,30 +306,67 @@ htmlInbox += '
    ' + '

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

    ' + '

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

    ' + - '

    до Дата

    ' + v.cost + '
    '; + '

    до Дата

    ' + v.cost + '' + + '
    '; } }); if (statusNotAgreed) { - htmlInbox += '
    Перейти в режим безопасной сделки' + - '
    ' + - 'отправить на согласование
    '; + htmlInbox += '
    ' + + '
    ' + + 'Перейти в режим безопасной сделки
    ' + + '
    ' + + 'отправить на согласование
    '; } htmlInbox = htmlInboxStage + htmlInbox; $("#order-stages").html(htmlInbox); + + + if (stagesPaidProcess.length > 0){ + $("#completeWork").show(); + var stage = stagesPaidProcess[0]; + var stageWork = '

    В работе '+ stage.name +'

    ' + + '

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

    ' + + '

    Срок сдачи 25.08.2016 ' + stage.cost + 'р.

    '; + + if (stage.close_contractor){ + stageWork += 'Закрыть этап '+ stage.pos +''; + } + $("#stagesWork").html(stageWork); + }else{ + $("#completeWork").hide(); + } } }); } - setTimeout(function () { - $(".user-block").first().trigger('click'); - }, 10); + //Закрыть этап + $('#tab2').on('click','.closeStage', function(e){ + e.preventDefault(); + var stageId = $(this).attr('data-stage-id'); + $.ajax({ + url: '/api/stages/' + stageId + '/', + type: 'PATCH', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: {close_customer: true, status: 'completed'}, + dataType: 'json', + success: function (json) { + console.log(json); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); - setTimeout(function () { - $(".order-block").first().trigger('click'); - }, 100); + // Добавление этапов $("#order-stages").on('click', "#addStagesForm", function (e) { e.preventDefault(); $(".new-stages-form").each(function (i, v) { @@ -398,7 +412,6 @@ }); }); - var currentOrderId = $(this).attr('data-order-id'); var currentRecipentId = $(this).attr('data-recipent-id'); @@ -416,6 +429,7 @@ }); + //Изменение счетчика $('#order-stages-tab').on('change', '#countStage', function () { var countStage = parseInt($(this).val()); var currentCountStage = $(".numberStepp").length; @@ -451,6 +465,7 @@ } }); + // Для заказов все вытащить $('.order-block').on('click', function () { $("#chat-order-add").css("display", "block"); $("#formsetStage").css("display", "block"); @@ -552,8 +567,28 @@ $("#chat").val(""); }); - $('#order-review-add').on('click', function () { - alert('add review'); + // Добавление отзыва + $('#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("Успешно"); + console.log(json); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); }); $('#order-chat-add-message').on('click', function (e) { diff --git a/chat/templates/reverse_stage_modal.html b/chat/templates/reverse_stage_modal.html index 2c483ff..5732c93 100644 --- a/chat/templates/reverse_stage_modal.html +++ b/chat/templates/reverse_stage_modal.html @@ -17,8 +17,8 @@

    Сумма оплаты всего заказа

    - Общий бюджет заказа: 300 р.
    - Итого к оплате: 344 рубля + Общий бюджет заказа: р.
    + Итого к оплате: р.

    @@ -31,17 +31,13 @@

    Оплатить этап


    - Бюджет Этапа 1: 300 р.
    - Итого к оплате: 344 р. + Бюджет Этапа 1: р.
    + Итого к оплате: р.

    -
    diff --git a/chat/templates/review_add_modal.html b/chat/templates/review_add_modal.html new file mode 100644 index 0000000..21a2b19 --- /dev/null +++ b/chat/templates/review_add_modal.html @@ -0,0 +1,49 @@ + diff --git a/projects/migrations/0014_auto_20160824_0154.py b/projects/migrations/0014_auto_20160824_0154.py new file mode 100644 index 0000000..3cfca16 --- /dev/null +++ b/projects/migrations/0014_auto_20160824_0154.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-23 22:54 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0013_auto_20160819_1735'), + ] + + operations = [ + migrations.AlterModelOptions( + name='project', + options={'ordering': ('-created',), 'verbose_name': 'Проект', 'verbose_name_plural': 'Проекты'}, + ), + migrations.AddField( + model_name='stage', + name='close_contractor', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='stage', + name='close_customer', + field=models.BooleanField(default=False), + ), + ] diff --git a/projects/models.py b/projects/models.py index 4d7ce77..49971af 100644 --- a/projects/models.py +++ b/projects/models.py @@ -233,6 +233,8 @@ class Stage(models.Model): created = models.DateTimeField(default=timezone.now) pos = models.IntegerField(default=0, null=True, blank=True) is_paid = models.BooleanField(default=False) + close_contractor = models.BooleanField(default=False) + close_customer = models.BooleanField(default=False) def __str__(self): return self.name diff --git a/projects/serializers.py b/projects/serializers.py index 89fd9f7..0d8fa2e 100755 --- a/projects/serializers.py +++ b/projects/serializers.py @@ -80,6 +80,8 @@ class StageSerializer(ModelSerializer): 'pos', 'status', 'is_paid', + 'close_contractor', + 'close_customer', )