|
|
|
|
@ -14,7 +14,13 @@ var SocketHandler = function () { |
|
|
|
|
var message = JSON.parse(event.data); |
|
|
|
|
var inbox; |
|
|
|
|
if (message.answer_type == 'contact' || message.answer_type == 'add_message_contact') { |
|
|
|
|
inbox = document.getElementById('message-chat-space'); |
|
|
|
|
var sumSenderRecipent = parseInt(message.recipent_id) + parseInt(message.sender_id); |
|
|
|
|
var inboxClass = document.getElementsByClassName('contact-space' + sumSenderRecipent); |
|
|
|
|
if (inboxClass.length > 0) { |
|
|
|
|
inbox = inboxClass[0]; |
|
|
|
|
}else{ |
|
|
|
|
$(".contact-count-" + sumSenderRecipent).text(parseInt($(".contact-count-" + sumSenderRecipent).text()) + 1); |
|
|
|
|
} |
|
|
|
|
} else if (message.answer_type == 'order' || message.answer_type == 'add_message_order') { |
|
|
|
|
inbox = document.getElementById('message-chat-order-space'); |
|
|
|
|
} else if (message.answer_type == 'add_message_team') { |
|
|
|
|
@ -123,6 +129,99 @@ $(function () { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Вытащить сообщения для конактов
|
|
|
|
|
|
|
|
|
|
$('.user-block').on('click', function () { |
|
|
|
|
var contactId = $(this).attr('data-id'); |
|
|
|
|
$("#contact-chat-form #recipentContactId").val(contactId); |
|
|
|
|
$("#add-form-contractor-note #recipentNoteContractor").val(contactId); |
|
|
|
|
|
|
|
|
|
$('.user-block').each(function () { |
|
|
|
|
$(this).removeClass('mesAct'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$(this).addClass('mesAct'); |
|
|
|
|
var inbox = document.getElementById('message-chat-space'); |
|
|
|
|
var sumSenderRecipent = parseInt(userId) + parseInt(contactId); |
|
|
|
|
|
|
|
|
|
$("#message-chat-space").removeClass().addClass("contact-space" + sumSenderRecipent); |
|
|
|
|
$(".contact-count-"+ sumSenderRecipent).text(0); |
|
|
|
|
var docList = document.getElementById('documentSpace'); |
|
|
|
|
inbox.innerHTML = ''; |
|
|
|
|
docList.innerHTML = ''; |
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/api/documents', |
|
|
|
|
type: 'GET', |
|
|
|
|
data: { |
|
|
|
|
csrfmiddlewaretoken: csrftoken, |
|
|
|
|
'operand': 'in', |
|
|
|
|
'sender_id': userId, |
|
|
|
|
'recipent_id': contactId, |
|
|
|
|
}, |
|
|
|
|
dataType: 'json', |
|
|
|
|
|
|
|
|
|
success: function (json) { |
|
|
|
|
console.log(json); |
|
|
|
|
|
|
|
|
|
$.each(json.results, function (i, v) { |
|
|
|
|
docList.innerHTML += '<li style="word-break: break-all;">' + v.file + '</li>'; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
error: function (e) { |
|
|
|
|
console.log(e); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/api/message', |
|
|
|
|
type: 'GET', |
|
|
|
|
data: { |
|
|
|
|
csrfmiddlewaretoken: csrftoken, |
|
|
|
|
'operand': 'in', |
|
|
|
|
'sender_id': userId, |
|
|
|
|
'recipent_id': contactId |
|
|
|
|
}, |
|
|
|
|
dataType: 'json', |
|
|
|
|
success: function (json) { |
|
|
|
|
$.each(json.results, function (i, v) { |
|
|
|
|
var senderName = 'Вы'; |
|
|
|
|
var className = 'youChat'; |
|
|
|
|
if (v.sender.id == contactId) { |
|
|
|
|
senderName = v.sender.username; |
|
|
|
|
className = ''; |
|
|
|
|
} |
|
|
|
|
inbox.innerHTML += '<div class="col-lg-12 insetCommChat ' + className + '"><div class="topCommChat">' + |
|
|
|
|
'<p class="nameCommChat">' + senderName + '</p> <span>' + v.created + '</span></div>' + |
|
|
|
|
'<p class="textCommChat">' + v.text + '</p></div>'; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/api/note/', |
|
|
|
|
type: 'GET', |
|
|
|
|
data: { |
|
|
|
|
csrfmiddlewaretoken: csrftoken, |
|
|
|
|
'operand': 'in', |
|
|
|
|
'sender_id': userId, |
|
|
|
|
'recipent_id': contactId |
|
|
|
|
}, |
|
|
|
|
dataType: 'json', |
|
|
|
|
success: function (json) { |
|
|
|
|
console.log(json.results); |
|
|
|
|
var noteHtmlInbox = ''; |
|
|
|
|
$.each(json.results, function (i, v) { |
|
|
|
|
noteHtmlInbox += '<li>' + v.text + '<li>'; |
|
|
|
|
}); |
|
|
|
|
$(".contractor-notes-block").html(noteHtmlInbox); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.deleteMess').on('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
@ -182,81 +281,111 @@ $(function () { |
|
|
|
|
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, |
|
|
|
|
if (chatMessage) { |
|
|
|
|
$("#chat-order-add .errorEmptyMessage").hide(); |
|
|
|
|
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(""); |
|
|
|
|
} else { |
|
|
|
|
$("#chat-order-add .errorEmptyMessage").show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#contact-chat-add-message').on('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
var chatMessage = $("#chat").val(); |
|
|
|
|
var recipentId = $("#recipentContactId").val(); |
|
|
|
|
var senderId = $("#senderContactId").val(); |
|
|
|
|
if (chatMessage) { |
|
|
|
|
$("#contact-chat-form .errorEmptyMessage").hide(); |
|
|
|
|
socket.add_contact_message({ |
|
|
|
|
"format_type": "add_message_contact", |
|
|
|
|
"data": { |
|
|
|
|
"sender_id": senderId, |
|
|
|
|
"recipent_id": recipentId, |
|
|
|
|
"chat_message": chatMessage, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
$("#chat").val(""); |
|
|
|
|
$("#document-send-contact").html(""); |
|
|
|
|
} else { |
|
|
|
|
$("#contact-chat-form .errorEmptyMessage").show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$("#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); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
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").bind('fileuploadsubmit', function(e, data){ |
|
|
|
|
data.formData = { |
|
|
|
|
$("#upload-document-order").bind('fileuploadsubmit', function (e, data) { |
|
|
|
|
data.formData = { |
|
|
|
|
sender: $("#chat-order-add #senderId").val(), |
|
|
|
|
recipent: $("#chat-order-add #recipentId").val(), |
|
|
|
|
order: $("#chat-order-add #orderId").val(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//Загрузка документов
|
|
|
|
|
@ -296,17 +425,15 @@ $(function () { |
|
|
|
|
.parent().addClass($.support.fileInput ? undefined : 'disabled'); //Загрузка документов
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#upload-document-contact").bind('fileuploadsubmit', function(e, data){ |
|
|
|
|
data.formData = { |
|
|
|
|
sender: $("#contact-chat-form #senderContactId").val(), |
|
|
|
|
recipent: $("#contact-chat-form #recipentContactId").val(), |
|
|
|
|
} |
|
|
|
|
$("#upload-document-contact").bind('fileuploadsubmit', function (e, data) { |
|
|
|
|
data.formData = { |
|
|
|
|
sender: $("#contact-chat-form #senderContactId").val(), |
|
|
|
|
recipent: $("#contact-chat-form #recipentContactId").val(), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#upload-document-contact').fileupload({ |
|
|
|
|
url: '/chat/create/', |
|
|
|
|
crossDomain: false, |
|
|
|
|
|