From 2d968c670bd3c5dfc7ae2a088684b5a77ec68e0d Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Thu, 28 Jul 2016 19:38:50 +0300 Subject: [PATCH] #ARC-18 add stages forms for contractors --- api/views.py | 2 +- assets/css/extra.css | 14 ++++ chat/templates/chat_contractor.html | 99 ++++++++++++++++++++---- chat/templates/chat_customer.html | 114 ++++++++++++++++++---------- projects/filters.py | 1 + projects/serializers.py | 1 + templates/partials/base.html | 8 +- 7 files changed, 179 insertions(+), 60 deletions(-) diff --git a/api/views.py b/api/views.py index 11abebe..69ed315 100755 --- a/api/views.py +++ b/api/views.py @@ -40,7 +40,7 @@ class NoteViewSet(ModelViewSet): queryset = Notes.objects.all() serializer_class = NoteSerializer filter_class = NoteFilterSet - + permission_classes = (permissions.IsAuthenticatedOrReadOnly,) class MessageViewSet(ModelViewSet): queryset = Message.objects.all() diff --git a/assets/css/extra.css b/assets/css/extra.css index b058932..3a87ae4 100644 --- a/assets/css/extra.css +++ b/assets/css/extra.css @@ -68,3 +68,17 @@ .textAreaBlock2 input[type="text"] { margin: 0; } + + +.stepssBlock ul li.reserved::before { + background: rgba(0, 0, 0, 0) url("../img/reserved2.png") no-repeat scroll center center / cover ; + height: 16px; + width: 17px; +} + + +.stepssBlock ul li.unreserved::before { + background: rgba(0, 0, 0, 0) url("../img/reserved.png") no-repeat scroll center center / cover ; + height: 14px; + width: 13px; +} diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index abaa9fb..929734a 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -97,7 +97,7 @@

{{ order }}

-

Испонитель: {{ request.user.get_full_name }}

+

Исполнитель: {{ request.user.get_full_name }}

Чаты: Иванов, Петров

@@ -137,14 +137,28 @@
-
- согласовать +
+

2 / Резервирование

+

+ Резервирование заказчиком суммы оплаты по заказ. Деньги перечисляются и хранятся на + сайте. +

+
    +
    +
      + +

    Для заметок

    - - сохранить +
    + + + + + сохранить +
    @@ -198,9 +212,6 @@
    -
    - согласовать -

    2 / Резервирование

    @@ -297,16 +308,25 @@ $("#approve-stages").on('click', function(){ $(".stage-block-approve").each(function(){ var stageId = $(this).attr('data-id'); - alert(stageId); + }); }); // Вытащить сообщения для чата заказа $('.order-block').on('click', function () { + $('.order-block').each(function () { + $(this).removeClass('orAct'); + }); + $(this).addClass('orAct'); + var orderId = $(this).attr('data-id'); var recipentId = $(this).attr('data-recipent-id'); $("#chat-contractor-order #orderId").val(orderId); + $("#add-form-order-note #orderNote").val(orderId); + $("#chat-contractor-order #recipentOrderId").val(recipentId); + $("#add-form-order-note #recipentNote").val(recipentId); + var inbox = document.getElementById('message-chat-order-space'); inbox.innerHTML = ''; @@ -330,6 +350,21 @@ } }); + $.ajax({ + url: '/api/note/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + console.log(json.results); + var noteHtmlInbox = ''; + $.each(json.results, function (i, v) { + noteHtmlInbox += '

  • '+ v.text +'
  • '; + + }); + $(".notes-block").html(noteHtmlInbox); + } + }); $.ajax({ url: '/api/stages/', @@ -339,18 +374,52 @@ success: function (json) { console.log(json.results); var htmlInbox = ""; - $.each(json.results, function (i, v) { - htmlInbox += '
    ' + - '

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

    ' + - '

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

    ' + - '

    до 16.03.2015

    '+ v.cost +'
    '; - }); + var stagesReservedHtml = ""; + if (json.results.length > 0) { + + $.each(json.results, function (i, v) { + if(v.is_paid){ + stagesReservedHtml += '
  • Сумма за этап '+ i +'.Зарезервирована.
  • '; + }else{ + stagesReservedHtml += '
  • Сумма за этап '+ i +'.Не зарезервирована.
  • '; + } + htmlInbox += '
    ' + + '

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

    ' + + '

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

    ' + + '

    '+ v.status+'

    ' + v.cost + '
    '; + }); + htmlInbox += ''; + + } $("#order-stages").html(htmlInbox); + $(".stages-paid").html(stagesReservedHtml); + } }); }); + $('#add-note-button').on('click', function(){ + $.ajax({ + url: '/api/note/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data:$("#add-form-order-note").serialize(), + dataType: 'json', + success: function (json) { + console.log(json); + $("#add-form-order-note #chat2").val(""); + + }, + error: function(e){ + console.log('error'); + console.log(e); + } + }); + }); + // Вытащить сообщения для конактов $('.user-block').on('click', function () { var userId = $(this).attr('data-id'); diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index 04daa5a..babae49 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -127,7 +127,7 @@
    -
    +

    Этапы работы

    1 / Согласование условий

    @@ -136,37 +136,35 @@

    -
    -

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

    - - -
    - +{#
    #} +{#

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

    #} +{# #} +{##} +{#
    #} +{# #}
    @@ -241,8 +239,11 @@ var csrftoken = getCookie('csrftoken'); - $("#addStagesForm").on('click',function(){ - $(".new-stages-form").each(function(i,v){ + $("#order-stages").on('click', "#addStagesForm", function(){ + $(".new-stages-form").each(function(i,v){ + console.log($(this).serialize()); + alert($(this).serialize()); + $.ajax({ url: '/api/stages/', type: 'POST', @@ -255,6 +256,7 @@ console.log(json); }, error: function(e){ + console.log('error'); console.log(e); } }); @@ -262,19 +264,20 @@ }); }); - $('#countStage').on('change', function (e) { - $(".stages_form").each(function () { - $(this).remove(); - }); + $('#order-stages-tab').on('change', '#countStage', function(){ var countStage = parseInt($(this).val()); + var updateFormStages = $(".update-stages-form"); + + alert(updateFormStages.length); + alert(typeof updateFormStages.length); var limitCount = countStage + 1; for (var i = 2; i < limitCount; i++) { var stageCopy = $("#stage1").clone().attr("id", "stage" + i).addClass("stages_form"); $("#stage1").after(stageCopy); } - }); + $('.order-block').on('click', function () { $("#chat-order-add").css("display", "block"); $("#formsetStage").css("display","block"); @@ -319,8 +322,29 @@ 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 = ""; - console.log(json.results.length); + + var htmlInboxStage = '

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

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

    Этап 1

    ' + + '' + + '' + + ' />' + + '' + + '' + + '
    '; + } + var statusNotAgreed = true; $.each(json.results, function (i, v) { if (v.status == "not_agreed") { htmlInbox += '
    ' + @@ -332,6 +356,8 @@ '' + '
    '; } else { + statusNotAgreed = false; + htmlInboxStage = ""; htmlInbox += '
    ' + '

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

    ' + '

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

    ' + @@ -339,6 +365,13 @@ } }); + + if (statusNotAgreed) { + htmlInbox += '
    Перейти в режим безопасной сделки' + + '
    '; + } + htmlInbox = htmlInboxStage + htmlInbox; $("#order-stages").html(htmlInbox); } }); @@ -483,7 +516,6 @@ textareaMessage.value = ""; } - } diff --git a/projects/filters.py b/projects/filters.py index 0323424..5ba3066 100755 --- a/projects/filters.py +++ b/projects/filters.py @@ -65,6 +65,7 @@ class StageFilterSet(FilterSet): status = AllLookupsFilter() pos = AllLookupsFilter() order = RelatedFilter('projects.filters.OrderFilterSet') + is_paid = AllLookupsFilter() class Meta: model = Stage diff --git a/projects/serializers.py b/projects/serializers.py index a9ac96c..e48b5cd 100755 --- a/projects/serializers.py +++ b/projects/serializers.py @@ -76,6 +76,7 @@ class StageSerializer(ModelSerializer): 'result', 'pos', 'status', + 'is_paid', ) diff --git a/templates/partials/base.html b/templates/partials/base.html index 09ff0fb..276e662 100644 --- a/templates/partials/base.html +++ b/templates/partials/base.html @@ -60,14 +60,16 @@ - - +{##} +{##} -{% block js_block %}{% endblock %} +{% block js_block %} + +{% endblock %}