';
});
},
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 += '
' +
'
' + senderName + '
' + v.created + '' +
'
' + v.text + '
';
});
}
});
$.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 += '
' + v.text + '';
});
$(".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("");
$('' + json.text + '').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) {
$("#chat-order-add .errorEmptyMessage").hide();
chatMessage += '
' + $("#document-send-order").html();
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();
chatMessage += '
' + $("#document-send-contact").html();
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();
}
});
// Добавление отзыва
$('#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 = '
' + file.name + '
';
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 = '
' + file.name + '';
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');
});