You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
545 lines
19 KiB
545 lines
19 KiB
var SocketHandler = function () {
|
|
domain = domain.replace(':' + port, '');
|
|
var url = 'ws://' + domain + ':8888/chat/' + userId + '/';
|
|
var sock = new WebSocket(url);
|
|
var intervalId;
|
|
sock.onopen = function () {
|
|
console.log("Start connect");
|
|
intervalId = setInterval(function () {
|
|
sock.send('{"dummy": 1}');
|
|
}, 15000);
|
|
};
|
|
sock.onmessage = function (event) {
|
|
console.log(event.data);
|
|
var message = JSON.parse(event.data);
|
|
var inbox;
|
|
if (message.answer_type == 'contact' || message.answer_type == 'add_message_contact') {
|
|
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') {
|
|
inbox = document.getElementById('message-chat-team-space');
|
|
} else if (message.answer_type == 'approve_stages') {
|
|
var resOrderId = message.order_id;
|
|
$.jGrowl(message.msg, {
|
|
life: 4000
|
|
});
|
|
setTimeout(function () {
|
|
$("#orderBlock" + resOrderId).trigger('click');
|
|
}, 2000);
|
|
console.log('approve stages');
|
|
}
|
|
|
|
if (inbox) {
|
|
var textMessage = message.msg;
|
|
var classMessage = 'youChat';
|
|
var senderName = 'Вы';
|
|
var timeMessage = message.msg_time;
|
|
if (message.sender_id != userId) {
|
|
senderName = message.sender_name;
|
|
classMessage = '';
|
|
}
|
|
inbox.innerHTML += '<div class="col-lg-12 insetCommChat ' + classMessage + '"><div class="topCommChat">' +
|
|
'<p class="nameCommChat">' + senderName + '</p> <span>' + timeMessage + '</span></div>' +
|
|
'<p class="textCommChat">' + textMessage + '</p></div>';
|
|
}
|
|
|
|
};
|
|
|
|
this.send_order_message = function (orderId) {
|
|
var data = {
|
|
"format_type": "order_message",
|
|
"order_id": orderId
|
|
}
|
|
sock.send(JSON.stringify(data));
|
|
console.log(data);
|
|
};
|
|
|
|
this.send_stages_approve = function (data) {
|
|
sock.send(JSON.stringify(data));
|
|
console.log(data);
|
|
};
|
|
|
|
this.send_contact_message = function (userId) {
|
|
var data = {
|
|
"format_type": "add_message",
|
|
"user_id": userId
|
|
}
|
|
sock.send(JSON.stringify(data));
|
|
console.log(data);
|
|
};
|
|
|
|
this.add_team_message = function (messageData) {
|
|
console.log(messageData);
|
|
sock.send(JSON.stringify(messageData));
|
|
}
|
|
|
|
this.add_contact_message = function (messageData) {
|
|
console.log(messageData);
|
|
sock.send(JSON.stringify(messageData));
|
|
};
|
|
|
|
this.send_message = function (form) {
|
|
var elements = form.elements;
|
|
var data = {};
|
|
var i = 0;
|
|
for (var i; i < elements.length; i++) {
|
|
if (elements[i].name == 'message') {
|
|
data[elements[i].name] = elements[i].value;
|
|
}
|
|
}
|
|
sock.send(JSON.stringify(data));
|
|
var textareaMessage = document.getElementById("message");
|
|
textareaMessage.value = "";
|
|
}
|
|
|
|
}
|
|
|
|
function csrfSafeMethod(method) {
|
|
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
|
}
|
|
|
|
var socket = new SocketHandler();
|
|
var csrftoken = getCookie('csrftoken');
|
|
|
|
$(function () {
|
|
var currentHash = URI(location.href).hash();
|
|
|
|
if (currentHash.indexOf("#order") == 0) {
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
$(".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 += '<tr><td>Название</td><td>'+data.project.name +'</td>';
|
|
outTable += '<tr><td>Безопасная сделка</td><td>'+data.secure +'</td>';
|
|
if(data.project.realty) {
|
|
outTable += '<tr><td>Тип здания</td><td>' + data.project.realty.building_classification.name + '</td>';
|
|
outTable += '<tr><td>Классификация здания</td><td>' + data.project.realty.construction_type.name + '</td>';
|
|
}
|
|
$("#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();
|
|
$("#contact-info").modal('show');
|
|
});
|
|
|
|
|
|
$("#paymentfromSite").on('click',function(){
|
|
var sum = $("#stageSumPay").val();
|
|
var stages = $("#stagesIds").val();
|
|
var orderId = $("#ordermodalId").val();
|
|
$.ajax({
|
|
url: '/wallets/payfromscore/',
|
|
type: 'POST',
|
|
data: {
|
|
csrfmiddlewaretoken: csrftoken,
|
|
sum: sum,
|
|
stages_id: stages,
|
|
},
|
|
dataType: 'json',
|
|
success: function (json) {
|
|
if(json.status == 'ok'){
|
|
$("#reserve-stage-modal").modal('hide');
|
|
$("#orderBlock" + orderId).trigger('click');
|
|
}
|
|
},
|
|
error: function(e, jqxhr){
|
|
console.log(e);
|
|
}
|
|
})
|
|
});
|
|
|
|
|
|
// Вытащить сообщения для конактов
|
|
|
|
$('.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;"><a class="file-link" href="'+ v.file_url +'">' + v.file + '</a><div style="right:-10px;"></divsty></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();
|
|
var senderId = userId;
|
|
var recipentId = $(this).attr('data-recipent-id');
|
|
var _this = $(this);
|
|
$.ajax({
|
|
url: '/chat/messages_delete/',
|
|
type: 'POST',
|
|
beforeSend: function (xhr) {
|
|
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'))
|
|
},
|
|
data: {'sender_id': senderId, 'recipent_id': recipentId},
|
|
dataType: 'json',
|
|
success: function (json) {
|
|
if (json.status == 'ok') {
|
|
_this.parent().remove();
|
|
$("#message-chat-space").html("");
|
|
}
|
|
|
|
},
|
|
error: function (e) {
|
|
console.log('error');
|
|
console.log(e);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
$('#add-note-contractor').on('click', function (e) {
|
|
e.preventDefault();
|
|
$.ajax({
|
|
url: '/api/note/',
|
|
type: 'POST',
|
|
beforeSend: function (xhr) {
|
|
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'))
|
|
},
|
|
data: $("#add-form-contractor-note").serialize(),
|
|
dataType: 'json',
|
|
success: function (json) {
|
|
console.log(json);
|
|
$("#add-form-contractor-note #chat2").val("");
|
|
$('<li>' + json.text + '</li>').appendTo(".contractor-notes-block");
|
|
},
|
|
error: function (e) {
|
|
console.log('error');
|
|
console.log(e);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Добавление сообщения для заказа.
|
|
$('#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();
|
|
|
|
if (chatMessage) {
|
|
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();
|
|
var sendLinks = $("#document-send-contact a");
|
|
var sendLinkIds = "";
|
|
$.each(sendLinks, function(i, v){
|
|
sendLinkIds += $(this).attr('data-id') + ';';
|
|
});
|
|
console.log(sendLinkIds);
|
|
socket.add_contact_message({
|
|
"format_type": "add_message_contact",
|
|
"data": {
|
|
"sender_id": senderId,
|
|
"recipent_id": recipentId,
|
|
"chat_message": chatMessage,
|
|
"document_send_links": sendLinkIds,
|
|
}
|
|
});
|
|
$("#chat").val("");
|
|
$("#document-send-contact").html("");
|
|
} else {
|
|
$("#contact-chat-form .errorEmptyMessage").show();
|
|
}
|
|
|
|
});
|
|
|
|
// Добавление отзыва
|
|
$('#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").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(),
|
|
}
|
|
console.log(data.formData);
|
|
});
|
|
|
|
//Загрузка документов
|
|
$('#upload-document-order').fileupload({
|
|
url: '/chat/create/',
|
|
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 = '<a href="'+ file.url+'" class="send-doc" data-id="'+ file.id +'">' + file.name + '</a><br />';
|
|
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'); //Загрузка документов
|
|
|
|
|
|
$("#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,
|
|
beforeSend: function (xhr, settings) {
|
|
console.log(this.formData);
|
|
$('#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 htmlImg = '<a href="'+ file.url+'" class="send-doc" data-id="'+ file.id +'">' + file.name + '</a>';
|
|
var document_send = $(htmlImg).appendTo("#document-send-contact");
|
|
});
|
|
},
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|