diff --git a/assets/js/chat.js b/assets/js/chat.js index 06eacb9..028d93f 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -19,7 +19,7 @@ var SocketHandler = function () { var inboxClass = document.getElementsByClassName('contact-space' + sumSenderRecipent); if (inboxClass.length > 0) { inbox = inboxClass[0]; - }else{ + } else { $(".contact-count-" + sumSenderRecipent).text(parseInt($(".contact-count-" + sumSenderRecipent).text()) + 1); } } else if (message.answer_type == 'order' || message.answer_type == 'add_message_order') { @@ -52,7 +52,6 @@ var SocketHandler = function () { var height = inbox.scrollHeight; inbox.scrollTop = height; - inbox.animate({scrollTop: height}); } }; @@ -115,7 +114,6 @@ var csrftoken = getCookie('csrftoken'); $(function () { var currentHash = URI(location.href).hash(); - if (currentHash.indexOf("#order") == 0) { var ordHashId = currentHash.replace("#order", ""); setTimeout(function () { @@ -125,53 +123,84 @@ $(function () { } else if (currentHash.indexOf("#team") == 0) { } else { - setTimeout(function () { $(".user-block").first().trigger('click'); }, 10); - setTimeout(function () { $(".order-block").first().trigger('click'); }, 500); } + $(".full-order-info").click('on', function (e) { + e.preventDefault(); + e.stopPropagation(); + var orderId = $(this).closest('.orderBlock').attr('data-id'); + $.ajax({ + url: '/api/orders/' + orderId + '/', + data: { + csrfmiddlewaretoken: csrftoken, + }, + dataType: 'json', + success: function (data) { + var outTable = ''; + outTable += 'Название' + data.project.name + ''; + outTable += 'Безопасная сделка' + data.secure + ''; + if (data.project.realty) { + outTable += 'Тип здания' + data.project.realty.building_classification.name + ''; + outTable += 'Классификация здания' + data.project.realty.construction_type.name + ''; + } + $("#order-info table").html(outTable); + $("#order-info").modal('show'); + }, + error: function (e, jqxhr) { + console.log(e); + } + }); + }); + $(".conMess").click('on', function (e) { + e.preventDefault(); + e.stopPropagation(); - $(".full-order-info").click('on',function(e){ - e.preventDefault(); - e.stopPropagation(); - var orderId = $(this).closest('.orderBlock').attr('data-id'); - $.ajax({ - url: '/api/orders/' + orderId + '/', - data: { - csrfmiddlewaretoken: csrftoken, - }, - dataType: 'json', - success: function(data){ - var outTable = ''; - outTable += 'Название'+data.project.name +''; - outTable += 'Безопасная сделка'+data.secure +''; - if(data.project.realty) { - outTable += 'Тип здания' + data.project.realty.building_classification.name + ''; - outTable += 'Классификация здания' + data.project.realty.construction_type.name + ''; - } - $("#order-info table").html(outTable); - $("#order-info").modal('show'); - }, - error: function(e,jqxhr){ - console.log(e); - } - }); - }); + var userId = $(this).attr('data-id'); + $.ajax({ + url: '/api/users/' + userId + '/', + data: { + csrfmiddlewaretoken: csrftoken, + }, + dataType: 'json', + success: function (data) { + var outTable = ''; + if(data.username) { + outTable += 'Ник' + data.username + ''; + } + + if(data.fio) { + outTable += 'Ф.И.О' + data.fio + ''; + } + if(data.skype) { + outTable += 'Skype'+ data.skype +''; + } + + if(data.website) { + outTable += 'Сайт'+ data.website +''; + } + + if(data.phone) { + outTable += 'Телефон'+ data.phone +''; + } - $(".conMess").click('on',function(e){ - e.preventDefault(); - e.stopPropagation(); + $("#contact-info table").html(outTable); $("#contact-info").modal('show'); + console.log(data); + }, + error: function (e, jqxhr) { + console.log(e); + } + }); }); - - $("#paymentfromSite").on('click',function(){ + $("#paymentfromSite").on('click', function () { var sum = $("#stageSumPay").val(); var stages = $("#stagesIds").val(); var orderId = $("#ordermodalId").val(); @@ -185,31 +214,31 @@ $(function () { }, dataType: 'json', success: function (json) { - if(json.status == 'ok'){ + if (json.status == 'ok') { $("#reserve-stage-modal").modal('hide'); $("#orderBlock" + orderId).trigger('click'); } }, - error: function(e, jqxhr){ + error: function (e, jqxhr) { console.log(e); } }) }); //Удаление документа - $('.tab-content').on('click','.remove-document', function(e){ + $('.tab-content').on('click', '.remove-document', function (e) { e.preventDefault(); var dataId = $(this).attr('data-id'); var _this = $(this); $.ajax({ - url: '/api/documents/' + dataId +'/', + url: '/api/documents/' + dataId + '/', type: 'PATCH', beforeSend: function (xhr) { xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) }, - data: {is_delete:true}, + data: {is_delete: true}, dataType: 'json', - success: function(json){ + success: function (json) { _this.parent().remove(); console.log(json); }, @@ -234,7 +263,7 @@ $(function () { var sumSenderRecipent = parseInt(userId) + parseInt(contactId); $("#message-chat-space").removeClass().addClass("contact-space" + sumSenderRecipent); - $(".contact-count-"+ sumSenderRecipent).text(0); + $(".contact-count-" + sumSenderRecipent).text(0); var docList = document.getElementById('documentSpace'); inbox.innerHTML = ''; docList.innerHTML = ''; @@ -256,7 +285,7 @@ $(function () { console.log(json); $.each(json.results, function (i, v) { - docList.innerHTML += '
  • ' + v.file + '
  • '; + docList.innerHTML += '
  • ' + v.file + '
  • '; }); }, error: function (e) { @@ -343,7 +372,6 @@ $(function () { }); }); - $('#add-note-contractor').on('click', function (e) { e.preventDefault(); $.ajax({ @@ -366,6 +394,50 @@ $(function () { }); }); + //Добавить заметку. + $('#add-note-button').on('click', function (e) { + e.preventDefault(); + $.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) { + $("
  • "+ json.text +"
  • ").appendTo(".order-notes-block"); + $("#add-form-order-note #chat2").val(""); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + + //Добавить заметку. + $('#add-team-note-button').on('click', function (e) { + e.preventDefault(); + $.ajax({ + url: '/api/note/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: $("#add-form-team-note").serialize(), + dataType: 'json', + success: function (json) { + $("
  • "+ json.text +"
  • ").appendTo(".team-notes-block"); + $("#add-form-team-note #chat2").val(""); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + // Добавление сообщения для заказа. $('#order-chat-add-message').on('click', function (e) { e.preventDefault(); @@ -377,7 +449,7 @@ $(function () { if (chatMessage) { var sendLinks = $("#document-send-order a"); var sendLinkIds = ""; - $.each(sendLinks, function(i, v){ + $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; }); socket.add_contact_message({ @@ -409,7 +481,7 @@ $(function () { $("#contact-chat-form .errorEmptyMessage").hide(); var sendLinks = $("#document-send-contact a"); var sendLinkIds = ""; - $.each(sendLinks, function(i, v){ + $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; }); console.log(sendLinkIds); @@ -509,10 +581,10 @@ $(function () { dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { - // var currentValue = ''; - // currentValue += file.id + ';'; + // var currentValue = ''; + // currentValue += file.id + ';'; //$("#documentSendIds").val(currentValue); - var htmlImg = '' + file.name + '
    '; + var htmlImg = '' + file.name + '
    '; var document_send = $(htmlImg).appendTo("#document-send-order"); }); }, @@ -555,7 +627,7 @@ $(function () { dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { - var htmlImg = '' + file.name + ''; + var htmlImg = '' + file.name + ''; var document_send = $(htmlImg).appendTo("#document-send-contact"); }); }, diff --git a/assets/js/chat_contractor.js b/assets/js/chat_contractor.js new file mode 100644 index 0000000..c17cc60 --- /dev/null +++ b/assets/js/chat_contractor.js @@ -0,0 +1,568 @@ +$(function () { + var form = document.getElementById('message_form'); + setTimeout(function () { + $(".team-order-block").first().trigger('click'); + }, 1000); + + var url = '/chat/create/'; + + $("#upload-document-team").bind('fileuploadsubmit', function (e, data) { + data.formData = { + sender: $("#team-chat-form #senderTeamId").val(), + recipent: $("#team-chat-form #recipentTeamId").val(), + order: $("#team-chat-form #orderTeamId").val(), + team: $("#team-chat-form #teamId").val(), + } + console.log(data.formData); + }); + + //Загрузка документов + $('#upload-document-team').fileupload({ + url: url, + 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 = $("#documentSendIds").val(); + currentValue += file.id + ';'; + $("#documentSendIds").val(currentValue); + var htmlImg = '' + file.name + ''; + var document_send = $(htmlImg).appendTo("#document-send"); + }); + }, + 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'); + + // Согласование этапов + $("#order-stages").on('click', "#approve-stages", function (e) { + e.preventDefault(); + $(".stage-block-approve").each(function () { + var stageId = $(this).attr('data-id'); + $.ajax({ + url: '/api/stages/' + stageId + '/', + type: 'PATCH', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: "status=in_process", + dataType: 'json', + success: function (json) { + console.log(json); + + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + + }); + var orderId = $(this).attr('data-order-id'); + + socket.send_stages_approve({ + "format_type": "approve_stages", + "data": { + "sender_id": $(this).attr('data-sender-id'), + "recipent_id": $(this).attr('data-recipent-id'), + "order_id": orderId, + "msg": "Исполнитель согласовал этапы для заказа " + orderId, + } + }); + + }); + + // Согласование этапов + $("#order-stages").on('click', "#cancel-stages", function (e) { + e.preventDefault(); + $(".stage-block-approve").each(function () { + var stageId = $(this).attr('data-id'); + $.ajax({ + url: '/api/stages/' + stageId + '/', + type: 'PATCH', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data: "status=cancel_approve", + dataType: 'json', + success: function (json) { + console.log(json); + + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + + }); + var orderId = $(this).attr('data-order-id'); + + socket.send_stages_approve({ + "format_type": "approve_stages", + "data": { + "sender_id": $(this).attr('data-sender-id'), + "recipent_id": $(this).attr('data-recipent-id'), + "order_id": orderId, + "msg": "Исполнитель отказался от текущих этапов " + orderId, + } + }); + + }); + + $(".team-chat-user").on('click', function (e) { + e.stopPropagation(); + var recipentId = $(this).attr('data-id'); + $("#team-chat-form #recipentTeamId").val(recipentId); + }); + + $(".team-order-block").on('click', function () { + + $('.team-order-block, .team-block').each(function () { + $(this).removeClass('orAct'); + }); + $(this).addClass('orAct'); + + var teamId = $(this).attr('data-team-id'); + var orderId = $(this).attr('data-order-id'); + $("#team-chat-form #teamId").val(teamId); + $("#team-chat-form #orderTeamId").val(orderId); + + $("#add-form-team-note #teamNote").val(teamId); + $("#add-form-team-note #orderNote").val(orderId); + + + var inbox = document.getElementById('message-chat-team-space'); + inbox.innerHTML = ''; + var docList = document.getElementById('documentTeamSpace'); + docList.innerHTML = ''; + + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'team': teamId, 'order': orderId}, + 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 + '

    '; + }); + var height = inbox.scrollHeight; + inbox.scrollTop = height; + } + }); + + $.ajax({ + url: '/api/documents', + type: 'GET', + data: { + csrfmiddlewaretoken: csrftoken, + 'order': orderId, + 'team': teamId, + 'is_delete': false, + 'is_send': true, + }, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + docList.innerHTML += '
  • ' + v.file + '
  • '; + }); + }, + error: function (e) { + console.log(e); + } + }); + + $.ajax({ + url: '/api/note/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId, 'team': teamId}, + dataType: 'json', + success: function (json) { + console.log(json.results); + var noteHtmlInbox = ''; + $.each(json.results, function (i, v) { + noteHtmlInbox += '
  • ' + v.text + '
  • '; + + }); + $(".team-notes-block").html(noteHtmlInbox); + } + }); + + }); + + $('.team-block').on('click', function () { + $('.team-order-block, .team-block').each(function () { + $(this).removeClass('orAct'); + }); + $(this).addClass('orAct'); + + var inbox = document.getElementById('message-chat-team-space'); + inbox.innerHTML = ''; + + var docList = document.getElementById('documentTeamSpace'); + docList.innerHTML = ''; + + var teamId = $(this).attr('data-team-id'); + $("#team-chat-form #teamId").val(teamId); + $("#add-form-team-note #teamNote").val(teamId); + $("#team-chat-form #orderTeamId").val(""); + $("#add-form-team-note #orderNote").val(""); + + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'team': teamId, 'order__isnull': 'true'}, + 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 + '

    '; + }); + var height = inbox.scrollHeight; + inbox.scrollTop = height; + } + }); + + $.ajax({ + url: '/api/documents', + type: 'GET', + data: { + csrfmiddlewaretoken: csrftoken, + 'team': teamId, + 'is_delete': false, + 'is_send': true, + }, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + docList.innerHTML += '
  • ' + v.file + '
  • '; + }); + }, + error: function (e) { + console.log(e); + } + }); + + $.ajax({ + url: '/api/note/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'team': teamId}, + dataType: 'json', + success: function (json) { + console.log(json.results); + var noteHtmlInbox = ''; + $.each(json.results, function (i, v) { + noteHtmlInbox += '
  • ' + v.text + '
  • '; + + }); + $(".team-notes-block").html(noteHtmlInbox); + } + }); + + }); + + // Вытащить сообщения для чата заказа + $('.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'); + var projectId = $(this).attr('data-project-id'); + + $("#chat-order-add #orderId").val(orderId); + $("#add-form-order-note #orderNote").val(orderId); + $("#orderArbitrationId").val(orderId); + $("#projectReviewId").val(projectId); + + $("#chat-order-add #recipentId").val(recipentId); + $("#targetCustomerId").val(recipentId); + $("#add-form-order-note #recipentNote").val(recipentId); + + var docList = document.getElementById('documentOrderSpace'); + var inbox = document.getElementById('message-chat-order-space'); + inbox.innerHTML = ''; + docList.innerHTML = ''; + + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId, 'team__isnull': 'true'}, + 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 + '

    '; + }); + + var height = inbox.scrollHeight; + inbox.scrollTop = height; + } + }); + + $.ajax({ + url: '/api/documents', + type: 'GET', + data: { + csrfmiddlewaretoken: csrftoken, + 'order': orderId, + 'is_delete': false, + 'is_send': true, + }, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + docList.innerHTML += '
  • ' + v.file + '
  • '; + }); + }, + error: function (e) { + console.log(e); + } + }); + + $.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 + '
  • '; + + }); + $(".order-notes-block").html(noteHtmlInbox); + } + }); + + $.ajax({ + url: '/api/orders/' + orderId + '/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken}, + dataType: 'json', + }).then(function (data) { + var htmlInbox = ""; + var stagesReservedHtml = ""; + var stagesPaidProcess = []; + var stagesInWork = []; + var stagesResults = data.stages; + var statusNotAgreed = false; + var stagesCompleted = []; + if (stagesResults.length > 0) { + $.each(stagesResults, function (i, v) { + if (v.status == "completed") { + stagesCompleted.push(v); + } + if (v.status == "not_agreed" || v.status == "send_approve") { + statusNotAgreed = true; + } + if (!data.secure) { + if (v.status == "in_process") { + stagesInWork.push(v); + + } + } else if ((v.status == "in_process") && (v.is_paid)) { + stagesPaidProcess.push(v); + stagesInWork.push(v); + } + + if (data.secure) { + if (v.is_paid) { + stagesReservedHtml += '
  • Сумма за этап ' + v.pos + '.Зарезервирована.
  • '; + } else { + stagesReservedHtml += '
  • Сумма за этап ' + v.pos + '.Не зарезервирована.
  • '; + } + } + + var statusName = ''; + switch (v.status) { + case 'not_agreed': + statusName = 'Не согласован'; + break; + case 'send_approve': + statusName = 'На согласовании'; + break; + case 'cancel_approve': + statusName = 'Исполнитель отказался'; + break; + case 'in_process': + statusName = 'В процессе'; + break; + case 'completed': + statusName = 'Завершен'; + break; + } + if (v.status == 'completed') { + statusName = 'Завершен'; + } + + htmlInbox += '
    ' + + '

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

    ' + + '

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

    ' + + '

    до ' + v.term + '

    ' + v.cost + '

    ' + statusName + '

    '; + }); + + if (statusNotAgreed) { + htmlInbox += '
    ' + + 'согласовать' + + 'отказаться' + + '
    '; + } + } + + $("#order-stages").html(htmlInbox); + $(".stages-paid").html(stagesReservedHtml); + if (data.secure) { + $("#reserveSpace").show(); + + } else { + $("#reserveSpace").hide(); + } + + if (stagesInWork.length > 0) { + $("#completeWork").show(); + var stage = stagesInWork[0]; + var stageWork = '
    ' + + '

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

    ' + + '

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

    ' + + '

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

    '; + + if (!stage.close_contractor) { + stageWork += '
    Завершить этап
    '; + } else { + stageWork += '

    Этап ожидает завершения статуса от заказчика

    '; + } + if (data.secure) { + stageWork += ''; + } + $("#stagesWork").html(stageWork); + } else { + $("#completeWork").hide(); + } + + if (stagesCompleted.length == stagesResults.length && stagesCompleted.length > 0) { + $("#leaveReview").show(); + } + + if (data.status == 'completed') { + $("#leaveReview").hide(); + } + }); + + + }); + + + $('#tab2').on('click', '.closeStage', function (e) { + e.preventDefault(); + var stageId = $(this).attr('data-stage-id'); + var _this = $(this); + $.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) { + + socket.send_stages_approve({ + "format_type": "approve_stages", + "data": { + "sender_id": _this.attr('data-sender-id'), + "recipent_id": _this.attr('data-recipent-id'), + "order_id": _this.attr('data-order-id'), + "msg": "Исполнитель завершил этап " + json.name, + } + }); + + console.log(json); + }, + error: function (e) { + console.log('error'); + console.log(e); + } + }); + }); + + //Добавить сообщение для исполнителей в группе + $("#add-team-chat-message").on('click', function (e) { + e.preventDefault(); + var chatMessage = $("#team-chat-form #chatText").val(); + var recipentId = $("#team-chat-form #recipentTeamId").val(); + var senderId = $("#team-chat-form #senderTeamId").val(); + var teamId = $("#team-chat-form #teamId").val(); + var orderId = $("#team-chat-form #orderTeamId").val(); + var documentSendIds = $("#documentSendIds").val(); + + if (chatMessage) { + var sendLinks = $("#document-send a"); + var sendLinkIds = ""; + $.each(sendLinks, function (i, v) { + sendLinkIds += $(this).attr('data-id') + ';'; + }); + socket.add_team_message({ + "format_type": "add_message_team", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + "team_id": teamId, + "order_id": orderId, + "document_send_links": sendLinkIds, + } + }); + + $("#team-chat-form #chatText").val(""); + $("#document-send").html(""); + $("#documentSendIds").val(""); + } + }); + +}); diff --git a/chat/migrations/0012_notes_team.py b/chat/migrations/0012_notes_team.py new file mode 100644 index 0000000..64e3b57 --- /dev/null +++ b/chat/migrations/0012_notes_team.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-07 08:01 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0015_user_phone2'), + ('chat', '0011_documents_is_delete'), + ] + + operations = [ + migrations.AddField( + model_name='notes', + name='team', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='users.Team'), + ), + ] diff --git a/chat/migrations/0013_auto_20160907_1556.py b/chat/migrations/0013_auto_20160907_1556.py new file mode 100644 index 0000000..2a9e815 --- /dev/null +++ b/chat/migrations/0013_auto_20160907_1556.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-07 12:56 +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', '0012_notes_team'), + ] + + operations = [ + migrations.AlterField( + model_name='notes', + name='recipent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='recipent_notes', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/chat/models.py b/chat/models.py index f372c27..88b30a0 100644 --- a/chat/models.py +++ b/chat/models.py @@ -28,8 +28,9 @@ class Notes(models.Model): text = models.TextField() created = models.DateTimeField(default=timezone.now) sender = models.ForeignKey(User, related_name='sender_notes') - recipent = models.ForeignKey(User, related_name='recipent_notes') + recipent = models.ForeignKey(User, related_name='recipent_notes', null=True, blank=True) order = models.ForeignKey(Order, related_name='notes', null=True, blank=True) + team = models.ForeignKey(Team, related_name='notes', null=True, blank=True) def __str__(self): return self.text diff --git a/chat/serializers.py b/chat/serializers.py index 765bfd5..74da60e 100644 --- a/chat/serializers.py +++ b/chat/serializers.py @@ -62,8 +62,8 @@ class MessageSerializer(ModelSerializer): out = obj.text documents = obj.documents.all() if len(documents)>0: - documents_str = '
    '.join(['' + doc.file.name + '' for doc in documents]) - out += '
    ' + documents_str + documents_str = '
    '.join(['Входящий файл:
    ' + doc.file.name + '' for doc in documents]) + out += '

    ' + documents_str return out @@ -78,4 +78,5 @@ class NoteSerializer(ModelSerializer): 'order', 'sender', 'recipent', + 'team', ) diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index c33dc32..a644ad9 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -55,7 +55,7 @@
    {{ contact.username }}

    - Контакты + Контакты 0 @@ -213,14 +213,14 @@
    -
    @@ -336,16 +336,18 @@
    -
    @@ -370,553 +372,5 @@ - + {% endblock %} diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index 1d9fc2d..d4df7cb 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -49,7 +49,7 @@
    {{ contact.username }}

    - Контакты + Контакты 0 @@ -214,9 +214,16 @@
    +

    Для заметок

    - -
    сохранить +
    + + + + + сохранить +
    @@ -401,6 +408,17 @@ statusNotAgreed = false; htmlInboxStage = ""; var statusName = ""; + switch (v.status){ + case 'completed': + statusName = 'Завершен'; + break; + case 'in_process': + statusName = 'Согласовано'; + break; + default: + statusName = ''; + break; + } if (v.status == 'completed'){ statusName = 'Завершен'; } @@ -633,7 +651,6 @@ } }); - // Для заказов все вытащить $('.order-block').on('click', function () { $("#chat-order-add").css("display", "block"); @@ -650,11 +667,13 @@ var secureOrder = $(this).attr('data-secure-deal'); secureOrder = Boolean(secureOrder); $("#chat-order-add #orderId").val(orderId); + $("#add-form-order-note #orderNote").val(orderId); $("#orderArbitrationId").val(orderId); $("#projectReviewId").val(projectId); $("#reserve-button").attr('data-order-id', orderId); $("#targetContractorId").val(recipentId); $("#chat-order-add #recipentId").val(recipentId); + $("#add-form-order-note #recipentNote").val(recipentId); $(".orderStagesInput").val(orderId); var inbox = document.getElementById('message-chat-order-space'); var docList = document.getElementById('documentOrderSpace'); @@ -673,7 +692,7 @@ dataType: 'json', success: function (json){ $.each(json.results, function (i, v) { - docList.innerHTML += '
  • '+ v.file+'
  • '; + docList.innerHTML += '
  • ' + v.file+'
  • '; }); }, error: function(e){ @@ -704,6 +723,23 @@ inbox.scrollTop = height; } }); + $.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 + '
  • '; + }); + $(".order-notes-block").html(noteHtmlInbox); + } + }); getStages(orderId,userId,recipentId, secureOrder); }); diff --git a/chat/templates/contact-info.html b/chat/templates/contact-info.html index 4e4c5cb..091d5e1 100644 --- a/chat/templates/contact-info.html +++ b/chat/templates/contact-info.html @@ -7,12 +7,7 @@ diff --git a/chat/templates/order_info.html b/chat/templates/order_info.html index 0e2842f..0081160 100644 --- a/chat/templates/order_info.html +++ b/chat/templates/order_info.html @@ -7,7 +7,7 @@ diff --git a/chat/urls.py b/chat/urls.py index 23bf743..055b606 100644 --- a/chat/urls.py +++ b/chat/urls.py @@ -4,6 +4,7 @@ from .views import ( ChatUserView, DocumentCreateView, messages_delete, + download_file, ) app_name = 'chat' @@ -12,4 +13,6 @@ urlpatterns = [ urls.url(r'^$', ChatUserView.as_view(), name='chat-user'), urls.url(r'^messages_delete/$', messages_delete, name='chat-messages_delete'), urls.url(r'^create/$', DocumentCreateView.as_view()), + urls.url(r'^download/(?P.+)', download_file), + ] diff --git a/chat/views.py b/chat/views.py index 3b93839..f520532 100644 --- a/chat/views.py +++ b/chat/views.py @@ -5,6 +5,7 @@ from django.views.generic import View,CreateView from django.http import HttpResponse, Http404 from django.db.models import Q from django.contrib.auth.mixins import LoginRequiredMixin +from wsgiref.util import FileWrapper from .response import JSONResponse, response_mimetype from .utils import serialize @@ -111,3 +112,15 @@ def messages_delete(request): return HttpResponse(json.dumps(data), content_type='application/json') else: raise Http404 + + +def download_file(request,file_name): + try: + document = Documents.objects.get(file=file_name) + except Documents.DoesNotExist: + document = None + + file_name = document.file + response = HttpResponse(FileWrapper(file_name), content_type='application/force-download') + response['Content-Disposition'] = 'attachment; filename=' + file_name.name + return response diff --git a/common/migrations/0014_auto_20160907_1101.py b/common/migrations/0014_auto_20160907_1101.py new file mode 100644 index 0000000..1ac1d71 --- /dev/null +++ b/common/migrations/0014_auto_20160907_1101.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-07 08:01 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0013_liveimageupload'), + ] + + operations = [ + migrations.AlterModelOptions( + name='liveimageupload', + options={'verbose_name': 'Живая загрузка изображений', 'verbose_name_plural': 'Живая загрузка изображений'}, + ), + ] diff --git a/users/serializers.py b/users/serializers.py index 96df7b4..29139fe 100755 --- a/users/serializers.py +++ b/users/serializers.py @@ -35,6 +35,7 @@ class ContractorResumeFilesSerializer(ModelSerializer): class UserSerializer(ModelSerializer): _type = SerializerMethodField() # Distinguish when used with generic serializers id = ReadOnlyField() + fio = SerializerMethodField() class Meta: model = User @@ -60,10 +61,15 @@ class UserSerializer(ModelSerializer): 'skype', 'username', 'website', + 'phone', + 'fio', ) def get__type(self, obj): return 'User' + + def get_fio(self, obj): + return obj.get_full_name() # def create(self, validated_data): # return User.objects.create(**validated_data) diff --git a/users/templates/contractor_office_chat_projects.html b/users/templates/contractor_office_chat_projects.html index aa64a92..d391fd9 100644 --- a/users/templates/contractor_office_chat_projects.html +++ b/users/templates/contractor_office_chat_projects.html @@ -103,21 +103,30 @@ {% include 'arbitration_modal.html' %} +
    +

    Прикрепленные документы

    +
      + + Распечатать с помощью ресурса + +
      +
      -
      + {% include 'order_info.html' %} @@ -137,377 +146,5 @@ - + {% endblock %}