@ -237,6 +237,69 @@
var socket = new SocketHandler();
var form = document.getElementById('message_form');
var csrftoken = getCookie('csrftoken');
function getStages(orderId){
$.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" name = "order" type = "text" value = "'+ orderId +'" class = "orderStagesInput" / > />' +
'< label for = "" > Срок< / label > < input class = "form-control" name = "term" type = "text" / > ' +
'< label for = "" > Результат< / label > < input class = "form-control" name = "result" 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" 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" 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 > до 16.03.2015< / 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-order-id = "' + orderId + '" id = "addStagesForm" > отправить на согласование< / a > < / div > ';
}
htmlInbox = htmlInboxStage + htmlInbox;
$("#order-stages").html(htmlInbox);
}
});
}
setTimeout(function(){
$(".user-block").first().trigger('click');
}, 10);
@ -245,7 +308,8 @@
$(".order-block").first().trigger('click');
}, 100);
$("#order-stages").on('click', "#addStagesForm", function(){
$("#order-stages").on('click', "#addStagesForm", function(e){
e.preventDefault();
$(".new-stages-form").each(function(i,v){
console.log($(this).serialize());
@ -259,6 +323,7 @@
dataType: 'json',
success: function (json) {
console.log(json);
},
error: function(e){
console.log('error');
@ -267,6 +332,30 @@
});
});
$(".update-stages-form").each(function(i,v){
$.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);
},
})
});
var currentOrderId = $(this).attr('data-order-id');
currentOrderId = parseInt(currentOrderId);
getStages(currentOrderId);
});
$('#order-stages-tab').on('change', '#countStage', function(){
@ -317,65 +406,67 @@
}
});
$.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" name = "order" type = "text" value = "'+ orderId +'" class = "orderStagesInput" / > />' +
'< label for = "" > Срок< / label > < input class = "form-control" name = "term" type = "text" / > ' +
'< label for = "" > Результат< / label > < input class = "form-control" name = "result" 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" id = "stage-form-'+ v.pos +'" > ' +
'< label for = "" > Название< / label > < input class = "form-control" type = "text" value = "'+ v.name +'" / > ' +
'< label for = "" > Цена< / label > < input class = "form-control" type = "text" value = "'+ v.cost +'" / > ' +
'< input class = "form-control" type = "hidden" value = "'+ v.order +'" / > ' +
'< label for = "" > Срок< / label > < input class = "form-control" type = "text" value = "'+ v.term +'" / > ' +
'< label for = "" > Результат< / label > < input class = "form-control" type = "text" 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 > до 16.03.2015< / 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 = "javascript:void()" id = "addStagesForm" > отправить на согласование< / a > < / div > ';
}
htmlInbox = htmlInboxStage + htmlInbox;
$("#order-stages").html(htmlInbox);
}
});
getStages(orderId);
{# $.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" name = "order" type = "hidden" value = "'+ orderId +'" class = "orderStagesInput" / > />' +#}
{# '< label for = "" > Срок< / label > < input class = "form-control" name = "term" type = "text" / > ' +#}
{# '< label for = "" > Результат< / label > < input class = "form-control" name = "result" 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" id = "stage-form-'+ v.pos +'" > ' +#}
{# '< label for = "" > Название< / label > < input class = "form-control" type = "text" value = "'+ v.name +'" / > ' +#}
{# '< label for = "" > Цена< / label > < input class = "form-control" type = "text" value = "'+ v.cost +'" / > ' +#}
{# '< input class = "form-control" type = "hidden" value = "'+ v.order +'" / > ' +#}
{# '< label for = "" > Срок< / label > < input class = "form-control" type = "text" value = "'+ v.term +'" / > ' +#}
{# '< label for = "" > Результат< / label > < input class = "form-control" type = "text" 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 > до 16.03.2015< / 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 = "javascript:void()" data-order-id = "'+ orderId +'" id = "addStagesForm" > отправить на согласование< / a > < / div > ';#}
{# }#}
{# htmlInbox = htmlInboxStage + htmlInbox;#}
{# $("#order-stages").html(htmlInbox);#}
{# }#}
{# });#}
});
@ -452,6 +543,10 @@
});
var userId = '{{ request.user.pk }}';
var SocketHandler = function () {
var url = 'ws://127.0.0.1:8888/chat/' + userId + '/';