parent
64cc28d64e
commit
c6b7066816
6 changed files with 6 additions and 367 deletions
@ -1,320 +0,0 @@ |
|||||||
$(function () { |
|
||||||
var currentChatUser = { |
|
||||||
{ |
|
||||||
request.user.pk |
|
||||||
} |
|
||||||
} |
|
||||||
; |
|
||||||
var socket = new SocketHandler(); |
|
||||||
var form = document.getElementById('message_form'); |
|
||||||
var csrftoken = getCookie('csrftoken'); |
|
||||||
|
|
||||||
$("#reserve-button").on("click", function (e) { |
|
||||||
e.preventDefault(); |
|
||||||
var orderId = $(this).attr('data-order-id'); |
|
||||||
$.ajax({ |
|
||||||
url: '/api/stages/', |
|
||||||
type: 'GET', |
|
||||||
data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, |
|
||||||
dataType: 'json', |
|
||||||
success: function (json) { |
|
||||||
console.log(json.results); |
|
||||||
} |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
function getStages(orderId, senderId, recipentId) { |
|
||||||
|
|
||||||
$.ajax({ |
|
||||||
url: '/api/stages/', |
|
||||||
type: 'GET', |
|
||||||
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 = ""; |
|
||||||
|
|
||||||
var htmlInboxStage = '<p class="textStepss">Какое кол-во этапов подразумевает работа? ' + |
|
||||||
'<input type="text" id="countStage" value="' + stageCountVal + '"size="3"/></p>'; |
|
||||||
|
|
||||||
if (stageCount == 0) { |
|
||||||
htmlInboxStage += '<div class="numberStepp box-sizing" id="stage1">' + |
|
||||||
'<p>Этап <span class="stage-span-id">1</span></p><form class="new-stages-form" id="stage-form">' + |
|
||||||
'<label for="">Название</label><input class="form-control" name="name" type="text" />' + |
|
||||||
'<label for="">Цена</label><input class="form-control" name="cost" type="text" />' + |
|
||||||
'<input class="form-control orderStagesInput" name="order" type="hidden" value="' + orderId + '"/>' + |
|
||||||
'<label for="">Срок</label><input class="form-control" name="term" type="text" />' + |
|
||||||
'<label for="">Результат</label><input class="form-control" name="result" type="text" />' + |
|
||||||
'<label for="">Позиция</label><input class="form-control" name="pos" value="1" type="text" />' + |
|
||||||
'</form></div>'; |
|
||||||
} |
|
||||||
var statusNotAgreed = true; |
|
||||||
$.each(json.results, function (i, v) { |
|
||||||
if (v.status == "not_agreed") { |
|
||||||
htmlInbox += '<div class="numberStepp box-sizing">' + |
|
||||||
'<p>Этап</p><form class="update-stages-form" data-stage-id="' + v.id + '" id="stage-form-' + v.pos + '">' + |
|
||||||
'<label for="">Название</label><input class="form-control" type="text" name="name" value="' + v.name + '" />' + |
|
||||||
'<label for="">Цена</label><input class="form-control" type="text" name="cost" value="' + v.cost + '" />' + |
|
||||||
'<input class="form-control orderStagesInput" type="hidden" name="order" value="' + v.order + '"/>' + |
|
||||||
'<label for="">Срок</label><input class="form-control" type="text" name="term" value="' + v.term + '" />' + |
|
||||||
'<label for="">Результат</label><input class="form-control" type="text" name="result" value="' + v.result + '" />' + |
|
||||||
'</form></div>'; |
|
||||||
} else { |
|
||||||
statusNotAgreed = false; |
|
||||||
htmlInboxStage = ""; |
|
||||||
htmlInbox += '<div class="numberStepp box-sizing"><div class="insetNumStepp">' + |
|
||||||
'<p class="titleNumStepp"><span>Этап ' + v.pos + '</span>' + v.name + '</p>' + |
|
||||||
'<p class="textNumStepp">Результаты этапа:' + v.result + '</p><div>' + |
|
||||||
'<p>до Дата</p><span>' + v.cost + '<i class="fa fa-rub"></i></span></div></div></div>'; |
|
||||||
|
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
if (statusNotAgreed) { |
|
||||||
htmlInbox += '<div class="box-sizing disTab" style="text-align:center;"><div class="checkbox"><input type="checkbox" style="opacity:1">Перейти в режим безопасной сделки' + |
|
||||||
'</div></div><div class="textAreaBlock2 box-sizing disTab">' + |
|
||||||
'<a href="#" data-sender-id="' + senderId + '" data-recipent-id="' + recipentId + '" data-order-id="' + orderId + '" id="addStagesForm">отправить на согласование</a> </div>'; |
|
||||||
} |
|
||||||
htmlInbox = htmlInboxStage + htmlInbox; |
|
||||||
$("#order-stages").html(htmlInbox); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
setTimeout(function () { |
|
||||||
$(".user-block").first().trigger('click'); |
|
||||||
}, 10); |
|
||||||
|
|
||||||
setTimeout(function () { |
|
||||||
$(".order-block").first().trigger('click'); |
|
||||||
}, 100); |
|
||||||
|
|
||||||
$("#order-stages").on('click', "#addStagesForm", function (e) { |
|
||||||
e.preventDefault(); |
|
||||||
$(".new-stages-form").each(function (i, v) { |
|
||||||
|
|
||||||
$.ajax({ |
|
||||||
url: '/api/stages/', |
|
||||||
type: 'POST', |
|
||||||
beforeSend: function (xhr) { |
|
||||||
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) |
|
||||||
}, |
|
||||||
data: $(this).serialize(), |
|
||||||
dataType: 'json', |
|
||||||
success: function (json) { |
|
||||||
console.log(json); |
|
||||||
}, |
|
||||||
error: function (e) { |
|
||||||
console.log(e); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
}); |
|
||||||
|
|
||||||
$(".update-stages-form").each(function (i, v) { |
|
||||||
var currentStageId = parseInt($(this).attr('data-stage-id')); |
|
||||||
$.ajax({ |
|
||||||
url: '/api/stages/' + currentStageId + '/', |
|
||||||
type: 'PUT', |
|
||||||
beforeSend: function (xhr) { |
|
||||||
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) |
|
||||||
}, |
|
||||||
data: $(this).serialize(), |
|
||||||
dataType: 'json', |
|
||||||
success: function (json) { |
|
||||||
console.log(json); |
|
||||||
}, |
|
||||||
error: function (e) { |
|
||||||
console.log('error'); |
|
||||||
console.log(e); |
|
||||||
} |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
|
|
||||||
var currentOrderId = $(this).attr('data-order-id'); |
|
||||||
var currentRecipentId = $(this).attr('data-recipent-id'); |
|
||||||
|
|
||||||
getStages(currentOrderId, userId, currentRecipentId); |
|
||||||
|
|
||||||
socket.send_stages_approve({ |
|
||||||
"format_type": "approve_stages", |
|
||||||
"data": { |
|
||||||
"sender_id": userId, |
|
||||||
"recipent_id": currentRecipentId, |
|
||||||
"order_id": currentOrderId, |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
|
|
||||||
}); |
|
||||||
|
|
||||||
$('#order-stages-tab').on('change', '#countStage', function () { |
|
||||||
var countStage = parseInt($(this).val()); |
|
||||||
var currentCountStage = $(".numberStepp").length; |
|
||||||
|
|
||||||
if (countStage > currentCountStage) { |
|
||||||
for (var jj = currentCountStage; jj < countStage; jj++) { |
|
||||||
var pos = jj + 1; |
|
||||||
var lastFormStage = $(".numberStepp").last(); |
|
||||||
var orderId = lastFormStage.find('.orderStagesInput').val(); |
|
||||||
var addFormTemplate = '<div class="numberStepp box-sizing" id="stage1">' + |
|
||||||
'<p>Этап <span class="stage-span-id">' + pos + '</span></p><form class="new-stages-form" id="stage-form">' + |
|
||||||
'<label for="">Название</label><input class="form-control" name="name" type="text" />' + |
|
||||||
'<label for="">Цена</label><input class="form-control" name="cost" type="text" />' + |
|
||||||
'<input class="form-control orderStagesInput" name="order" type="hidden" value="' + orderId + '" />' + |
|
||||||
'<label for="">Срок</label><input class="form-control" name="term" type="text" />' + |
|
||||||
'<label for="">Результат</label><input class="form-control" name="result" type="text" />' + |
|
||||||
'<label for="">Позиция</label><input class="form-control" name="pos" value="' + pos + '" type="text" />' |
|
||||||
'</form></div>'; |
|
||||||
|
|
||||||
lastFormStage.after(addFormTemplate); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} else if (countStage < currentCountStage) { |
|
||||||
var ii = currentCountStage; |
|
||||||
$($(".numberStepp").get().reverse()).each(function () { |
|
||||||
var currenFormName = ($(this).find('form').attr('class')); |
|
||||||
if (ii > countStage) { |
|
||||||
$(this).remove(); |
|
||||||
} |
|
||||||
ii--; |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
$('.order-block').on('click', function () { |
|
||||||
$("#chat-order-add").css("display", "block"); |
|
||||||
$("#formsetStage").css("display", "block"); |
|
||||||
|
|
||||||
$('.order-block').each(function () { |
|
||||||
$(this).removeClass('orAct'); |
|
||||||
}); |
|
||||||
|
|
||||||
$(this).addClass('orAct'); |
|
||||||
var orderId = $(this).attr('data-id'); |
|
||||||
var recipentId = $(this).attr('data-recipent-id'); |
|
||||||
$("#chat-order-add #orderId").val(orderId); |
|
||||||
$("#projectReviewId").val(orderId); |
|
||||||
$("#reserve-button").attr('data-order-id', orderId); |
|
||||||
$("#targetContractorId").val(recipentId); |
|
||||||
$("#chat-order-add #recipentId").val(recipentId); |
|
||||||
$(".orderStagesInput").val(orderId); |
|
||||||
var inbox = document.getElementById('message-chat-order-space'); |
|
||||||
inbox.innerHTML = ''; |
|
||||||
$.ajax({ |
|
||||||
url: '/api/message', |
|
||||||
type: 'GET', |
|
||||||
data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, |
|
||||||
dataType: 'json', |
|
||||||
success: function (json) { |
|
||||||
$.each(json.results, function (i, v) { |
|
||||||
var senderName = 'Вы'; |
|
||||||
var className = 'youChat'; |
|
||||||
|
|
||||||
if (v.sender.id !== currentChatUser) { |
|
||||||
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>'; |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
getStages(orderId, userId, recipentId); |
|
||||||
}); |
|
||||||
|
|
||||||
// Вытащить сообщения для конактов
|
|
||||||
$('.user-block').on('click', function () { |
|
||||||
var userId = $(this).attr('data-id'); |
|
||||||
$("#contact-chat-form #recipentId").val(userId); |
|
||||||
$("#add-form-contractor-note #recipentNoteContractor").val(userId); |
|
||||||
|
|
||||||
$('.user-block').each(function () { |
|
||||||
$(this).removeClass('mesAct'); |
|
||||||
}); |
|
||||||
|
|
||||||
$(this).addClass('mesAct'); |
|
||||||
var inbox = document.getElementById('message-chat-space'); |
|
||||||
inbox.innerHTML = ''; |
|
||||||
$.ajax({ |
|
||||||
url: '/api/message', |
|
||||||
type: 'GET', |
|
||||||
data: { |
|
||||||
csrfmiddlewaretoken: csrftoken, |
|
||||||
'operand': 'in', |
|
||||||
'sender_id': currentChatUser, |
|
||||||
'recipent_id': userId |
|
||||||
}, |
|
||||||
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 += '<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>'; |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
}); |
|
||||||
|
|
||||||
$('#contact-chat-add-message').on('click', function (e) { |
|
||||||
e.preventDefault(); |
|
||||||
var chatMessage = $("#chat").val(); |
|
||||||
var recipentId = $("#recipentId").val(); |
|
||||||
var senderId = $("#senderId").val(); |
|
||||||
|
|
||||||
socket.add_contact_message({ |
|
||||||
"format_type": "add_message_contact", |
|
||||||
"data": { |
|
||||||
"sender_id": senderId, |
|
||||||
"recipent_id": recipentId, |
|
||||||
"chat_message": chatMessage, |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
$("#chat").val(""); |
|
||||||
}); |
|
||||||
|
|
||||||
$('#order-review-add').on('click', function () { |
|
||||||
alert('add review'); |
|
||||||
}); |
|
||||||
|
|
||||||
$('#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(); |
|
||||||
|
|
||||||
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(""); |
|
||||||
}); |
|
||||||
|
|
||||||
}); |
|
||||||
var userId = '{{ request.user.pk }}'; |
|
||||||
Loading…
Reference in new issue