#ARC-18 Fix upload documents for customer

remotes/origin/PR-39
Mukhtar 10 years ago
parent 7b58f50e17
commit c52d296305
  1. 11
      api/views.py
  2. 66
      assets/js/chat.js
  3. 21
      chat/migrations/0008_documents_created.py
  4. 20
      chat/migrations/0009_auto_20160829_1120.py
  5. 1
      chat/models.py
  6. 2
      chat/serializers.py
  7. 60
      chat/templates/chat_customer.html
  8. 1
      chat/views.py

@ -64,6 +64,17 @@ class DocumentViewSet(ModelViewSet):
# filter_class = DocumentsFilterSet
# permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def get_queryset(self):
queryset = Documents.objects.all()
search_param = self.request.query_params.get('operand', None)
recipent_id = self.request.query_params.get('recipent_id', None)
sender_id = self.request.query_params.get('sender_id', None)
if search_param:
# import code; code.interact(local=dict(globals(), **locals()))
if search_param == 'in':
queryset = queryset.filter(Q(sender__in=[sender_id,recipent_id]),Q(recipent__in=[sender_id,recipent_id])).order_by('created')
return queryset
class ProjectViewSet(ModelViewSet):
queryset = Project.objects.all()

@ -101,12 +101,9 @@ function csrfSafeMethod(method) {
var socket = new SocketHandler();
var csrftoken = getCookie('csrftoken');
$(function () {
var currentHash = URI(location.href).hash();
console.log(currentHash);
if (currentHash.indexOf("#order") == 0) {
if (currentHash.indexOf("#order") == 0) {
var ordHashId = currentHash.replace("#order", "");
setTimeout(function () {
$("#orderBlock" + ordHashId).trigger('click');
@ -177,7 +174,6 @@ $(function () {
});
});
// Добавление сообщения для заказа.
$('#order-chat-add-message').on('click', function (e) {
e.preventDefault();
@ -255,18 +251,17 @@ $(function () {
});
});
$("#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(),
}
});
//Загрузка документов
$('#upload-document-order').fileupload({
url: '/chat/create/',
formData: {
sender: $("#chat-order-add #senderId").val(),
recipent: $("#chat-order-add #recipentId").val(),
order: $("#chat-order-add #orderId").val(),
},
crossDomain: false,
beforeSend: function (xhr, settings) {
$('#progress .progress-bar').css(
@ -297,6 +292,51 @@ $(function () {
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 = '<p>' + file.name + '</p>';
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');

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-29 01:00
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('chat', '0007_auto_20160826_1458'),
]
operations = [
migrations.AddField(
model_name='documents',
name='created',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-29 08:20
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('chat', '0008_documents_created'),
]
operations = [
migrations.AlterField(
model_name='documents',
name='created',
field=models.DateTimeField(auto_now_add=True),
),
]

@ -45,6 +45,7 @@ class Documents(models.Model):
team = models.ForeignKey(Team, related_name='documents', null=True, blank=True)
sender = models.ForeignKey(User, related_name='sender_documents')
recipent = models.ForeignKey(User, related_name='recipent_documents', null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.file.url

@ -4,6 +4,7 @@ from rest_framework.serializers import ModelSerializer
from .models import Message, Notes, Documents
from users.serializers import UserSerializer
class DocumentsSerializer(ModelSerializer):
class Meta:
@ -18,6 +19,7 @@ class DocumentsSerializer(ModelSerializer):
)
class MessageSerializer(ModelSerializer):
sender = UserSerializer()
recipent = UserSerializer()

@ -65,25 +65,32 @@
<div id="message-chat-space">
</div>
<form id="contact-chat-form">
<input type="hidden" value="{{ request.user.pk }}" name="senderId" id="senderId"/>
<input type="hidden" value="" name="recipentId" id="recipentId">
<input type="hidden" value="{{ request.user.pk }}" name="senderId" id="senderContactId"/>
<input type="hidden" name="recipentId" id="recipentContactId">
<textarea id="chat" name="chat_message" class="box-sizing"></textarea>
<div class="bunChat">
<div class="setChat box-sizing">
<p>Прикрепить файл</p>
<span>
Не более 10 файлов с общим объемом 500мб
</span>
<div class="setChat box-sizing upload">
<input type="file" name="file" id="upload-document-contact">
<p>Прикрепить файл</p>
</div>
<a id="contact-chat-add-message" href="#">отправить</a>
<div id="document-send-contact"></div>
<a id="contact-chat-add-message" href="#">отправить</a>
</div>
</form>
</div>
<div class="col-lg-3 wrChat1">
<div class="col-lg-12 documentsChat">
<p>Входящие документы</p>
<ul id="documentSpace">
</ul>
{# <a href="javascript:void(0)">#}
{# Распечатать с помощью ресурса#}
{# </a>#}
</div>
<div class="textAreaBlock2 box-sizing disTab">
<ul class="contractor-notes-block">
</ul>
@ -619,7 +626,7 @@
// Вытащить сообщения для конактов
$('.user-block').on('click', function () {
var userId = $(this).attr('data-id');
$("#contact-chat-form #recipentId").val(userId);
$("#contact-chat-form #recipentContactId").val(userId);
$("#add-form-contractor-note #recipentNoteContractor").val(userId);
$('.user-block').each(function () {
@ -628,7 +635,33 @@
$(this).addClass('mesAct');
var inbox = document.getElementById('message-chat-space');
var docList = document.getElementById('documentSpace');
inbox.innerHTML = '';
docList.innerHTML = '';
$.ajax({
url:'/api/documents',
type: 'GET',
data:{
csrfmiddlewaretoken: csrftoken,
'operand': 'in',
'sender_id': currentChatUser,
'recipent_id': userId
},
dataType: 'json',
success: function (json){
console.log(json);
$.each(json.results, function (i, v) {
docList.innerHTML += '<li style="word-break: break-all;">'+ v.file+'<div></div></li>';
});
},
error: function(e){
console.log(e);
}
});
$.ajax({
url: '/api/message',
type: 'GET',
@ -659,8 +692,8 @@
$('#contact-chat-add-message').on('click', function (e) {
e.preventDefault();
var chatMessage = $("#chat").val();
var recipentId = $("#recipentId").val();
var senderId = $("#senderId").val();
var recipentId = $("#recipentContactId").val();
var senderId = $("#senderContactId").val();
socket.add_contact_message({
"format_type": "add_message_contact",
@ -672,6 +705,7 @@
});
$("#chat").val("");
$("#document-send-contact").html("");
});

@ -19,7 +19,6 @@ class DocumentCreateView(CreateView):
fields = '__all__'
def form_valid(self, form):
# import code; code.interact(local=dict(globals(), **locals()))
self.object = form.save()
files = [serialize(self.object)]
data = {'files': files}

Loading…
Cancel
Save