//
// function csrfSafeMethod(method) {
// // these HTTP methods do not require CSRF protection
// return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
// }
//
// var SocketHandler = function () {
// var userId = {{ request.user.pk }};
// var url = 'ws://127.0.0.1:8888/chat/' + userId + '/';
// var sock = new WebSocket(url);
// var intervalId;
// sock.onopen = function () {
// console.log("Start connect");
// intervalId = setInterval(function () {
// sock.send('{"dummy": 1}');
// }, 150000);
// };
// 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') {
// inbox = document.getElementById('message-chat-space');
// } 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');
// }
// console.log(message.answer_type);
// console.log(message.msg);
//
// inbox.innerHTML += '
' +
// '
' + message.msg + '
';
// };
//
// 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 () {
// var currentChatUser = {{ request.user.pk }};
// var socket = new SocketHandler();
// var form = document.getElementById('message_form');
// var csrftoken = getCookie('csrftoken');
//
// setTimeout(function(){
// $(".user-block").first().trigger('click');
// }, 10);
//
// setTimeout(function(){
// $(".order-block").first().trigger('click');
// }, 100);
//
// setTimeout(function(){
// $(".team-order-block").first().trigger('click');
// }, 1000);
//
//
// var url = '/work_sell/basic/';
// $('#upload-document-team').fileupload({
// url: url,
// 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 = $("#documentSendIds").val();
// currentValue += file.id + ';';
// $("#documentSendIds").val(currentValue);
// var htmlImg = ''+ file.name+'
';
// var document_send = $(htmlImg).appendTo("#document-send");
// });
// },
// 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');
//
//
// $("#approve-stages").on('click', function(){
// $(".stage-block-approve").each(function(){
// var stageId = $(this).attr('data-id');
// });
// });
//
// $(".team-chat-user").on('click',function(e){
// e.stopPropagation();
// var recipentId = $(this).attr('data-id');
// $("#team-chat-form #recipentId").val(recipentId);
// });
//
// $(".team-order-block").on('click', function(){
//
// $('.team-order-block').each(function () {
// $(this).removeClass('orAct');
// });
// $(this).addClass('orAct');
//
// var teamId = $(this).attr('data-team-id');
// var orderId = $(this).attr('data-order-id');
// $("#team-chat-form #teamId").val(teamId);
// $("#team-chat-form #orderId").val(orderId);
//
// var inbox = document.getElementById('message-chat-team-space');
// inbox.innerHTML = '';
//
// $.ajax({
// url: '/api/message',
// type: 'GET',
// data: {csrfmiddlewaretoken: csrftoken, 'team': teamId,'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 += '' +
// '
' + senderName + '
' + v.created + '' +
// '
' + v.text + '
';
// });
// }
// });
//
// });
//
// // Вытащить сообщения для чата заказа
// $('.order-block').on('click', function () {
// $('.order-block').each(function () {
// $(this).removeClass('orAct');
// });
// $(this).addClass('orAct');
//
// var orderId = $(this).attr('data-id');
// var recipentId = $(this).attr('data-recipent-id');
// $("#chat-contractor-order #orderId").val(orderId);
// $("#add-form-order-note #orderNote").val(orderId);
//
// $("#chat-contractor-order #recipentOrderId").val(recipentId);
// $("#add-form-order-note #recipentNote").val(recipentId);
//
// 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 += '' +
// '
' + senderName + '
' + v.created + '' +
// '
' + v.text + '
';
// });
// }
// });
//
// $.ajax({
// url: '/api/note/',
// type: 'GET',
// data: {csrfmiddlewaretoken: csrftoken, 'order': orderId},
// dataType: 'json',
// success: function (json) {
// console.log(json.results);
// var noteHtmlInbox = '';
// $.each(json.results, function (i, v) {
// noteHtmlInbox += ''+ v.text +'';
//
// });
// $(".notes-block").html(noteHtmlInbox);
// }
// });
//
// $.ajax({
// url: '/api/stages/',
// type: 'GET',
// data: {csrfmiddlewaretoken: csrftoken, 'order': orderId},
// dataType: 'json',
// success: function (json) {
// console.log(json.results);
// var htmlInbox = "";
// var stagesReservedHtml = "";
// if (json.results.length > 0) {
//
// $.each(json.results, function (i, v) {
// if(v.is_paid){
// stagesReservedHtml += 'Сумма за этап '+ i +'.Зарезервирована.';
// }else{
// stagesReservedHtml += 'Сумма за этап '+ i +'.Не зарезервирована.';
// }
// htmlInbox += '' +
// '
Этап ' + v.pos + '' + v.name + '
' +
// '
Результаты этапа:' + v.result + '
' +
// '
'+ v.status+'
' + v.cost + ' ';
// });
// htmlInbox += '';
//
// }
// $("#order-stages").html(htmlInbox);
// $(".stages-paid").html(stagesReservedHtml);
//
// }
// });
//
// });
//
// $('#add-note-button').on('click', function(){
// $.ajax({
// url: '/api/note/',
// type: 'POST',
// beforeSend: function (xhr) {
// xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'))
// },
// data:$("#add-form-order-note").serialize(),
// dataType: 'json',
// success: function (json) {
// console.log(json);
// $("#add-form-order-note #chat2").val("");
//
// },
// error: function(e){
// console.log('error');
// console.log(e);
// }
// });
// });
//
// // Вытащить сообщения для конактов
// $('.user-block').on('click', function () {
// var userId = $(this).attr('data-id');
// $("#contact-chat-form #recipentId").val(userId);
// 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) {
// console.log(v.sender.id);
// var senderName = 'Вы';
// var className = 'youChat';
// if (v.sender.id == userId) {
// senderName = v.sender.username;
// className = '';
// }
// inbox.innerHTML += '' +
// '
' + senderName + '
' + v.created + '' +
// '
' + v.text + '
';
// });
// }
// });
//
// });
//
// //Добавить сообщение для исполнителей в группе
// $("#add-team-chat-message").on('click', function(){
// var chatMessage = $("#team-chat-form #chatText").val();
// var recipentId = $("#team-chat-form #recipentId").val();
// var senderId = $("#team-chat-form #senderId").val();
// var teamId = $("#team-chat-form #teamId").val();
// var orderId = $("#team-chat-form #orderId").val();
//
// var documentSendIds = $("#documentSendIds").val();
// console.log(documentSendIds);
// var teamDocumentIds = documentSendIds.split(';');
// teamDocumentIds.pop();
// console.log(teamDocumentIds);
// socket.add_team_message({
// "format_type": "add_message_team",
// "data": {
// "sender_id": senderId,
// "recipent_id": recipentId,
// "chat_message": chatMessage,
// "team_id": teamId,
// "order_id": orderId,
// }
// });
//
//
//
// $("#team-chat-form #chatText").val("");
// });
//
// // Добавить сообщение для контакта
// $('#contact-chat-add-message').on('click', function () {
// 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,
// }
// });
//
// var inbox = $('#message-chat-space').html();
// $('#message-chat-space').html(inbox + '' +
// '
' + chatMessage + '
');
//
// $("#chat").val("");
// });
//
// $('#order-chat-add-message').on('click', function () {
// var chatMessage = $("#chat-contractor-order #chat").val();
// var recipentId = $("#chat-contractor-order #recipentOrderId").val();
// var senderId = $("#chat-contractor-order #senderOrderId").val();
// var orderId = $("#chat-contractor-order #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-contractor-order #chat").val("");
//
// });
//
// });
//
//
//$(function () {
// var currentChatUser = {{ request.user.pk }};
// var socket = new SocketHandler();
// var form = document.getElementById('message_form');
// var csrftoken = getCookie('csrftoken');
// setTimeout(function(){
// $(".user-block").first().trigger('click');
// }, 10);
//
// setTimeout(function(){
// $(".order-block").first().trigger('click');
// }, 100);
//
// $("#order-stages").on('click', "#addStagesForm", function(){
// $(".new-stages-form").each(function(i,v){
// console.log($(this).serialize());
// alert($(this).serialize());
//
// $.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('error');
// console.log(e);
// }
// });
//
// });
// });
//
// $('#order-stages-tab').on('change', '#countStage', function(){
// var countStage = parseInt($(this).val());
// var updateFormStages = $(".update-stages-form");
//
// alert(updateFormStages.length);
// alert(typeof updateFormStages.length);
// var limitCount = countStage + 1;
// for (var i = 2; i < limitCount; i++) {
// var stageCopy = $("#stage1").clone().attr("id", "stage" + i).addClass("stages_form");
// $("#stage1").after(stageCopy);
// }
// });
//
// $('.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);
// $("#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 += '' +
// '
' + senderName + '
' + v.created + '' +
// '
' + v.text + '
';
// });
// }
// });
//
// $.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 = 'Какое кол-во этапов подразумевает работа? ' +
// '
';
//
// if (stageCount == 0){
// htmlInboxStage += '';
// }
// var statusNotAgreed = true;
// $.each(json.results, function (i, v) {
// if (v.status == "not_agreed") {
// htmlInbox += '';
// } else {
// statusNotAgreed = false;
// htmlInboxStage = "";
// htmlInbox += '' +
// '
Этап ' + v.pos + '' + v.name + '
' +
// '
Результаты этапа:' + v.result + '
' +
// '
до 16.03.2015
' + v.cost + ' ';
//
// }
// });
//
// if (statusNotAgreed) {
// htmlInbox += '';
// }
// htmlInbox = htmlInboxStage + htmlInbox;
// $("#order-stages").html(htmlInbox);
// }
// });
//
//
// });
//
// // Вытащить сообщения для конактов
// $('.user-block').on('click', function () {
// var userId = $(this).attr('data-id');
// $("#contact-chat-form #recipentId").val(userId);
// 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 += '' +
// '
' + senderName + '
' + v.created + '' +
// '
' + v.text + '
';
// });
// }
// });
//
// });
//
// $('#contact-chat-add-message').on('click', function () {
// 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-chat-add-message').on('click', function () {
// 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 }}';
//
// var SocketHandler = function () {
// var url = 'ws://127.0.0.1:8888/chat/' + userId + '/';
// var sock = new WebSocket(url);
// var intervalId;
// sock.onopen = function () {
// console.log("Start connect");
// intervalId = setInterval(function () {
// sock.send('{"dummy": 1}');
// }, 150);
// };
// sock.onmessage = function (event) {
// console.log(event.data);
// var message = JSON.parse(event.data);
// var inbox;
// if (message.answer_type == 'contact') {
// inbox = document.getElementById('message-chat-space');
// } else if (message.answer_type == 'order' || message.answer_type == 'add_order') {
// inbox = document.getElementById('message-chat-order-space')
// }
// inbox.innerHTML += '' +
// '
' + message.msg + '
';
//
// };
//
// 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_contact_message = function (userId) {
// var data = {
// "format_type": "add_message",
// "user_id": userId
// }
// sock.send(JSON.stringify(data));
// console.log(data);
// };
//
// 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 = "";
//
// }
// }
//