chat.js
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function getModalInfo(btn, space, space_type) {
var url = btn.data('url');
$.ajax({
method: 'get',
url: url,
data: {'space': space, 'space_type': space_type},
success: function (response) {
$("#chat-modal-info").html(response);
$("#chat-modal-info").modal('show');
$.material.init();
$('#chat-modal-info').on('shown.bs.modal', function () {
$(".messages-container").each(function () {
var height = $(this)[0].scrollHeight;
$(this).animate({scrollTop: height}, 0);
});
});
}
});
}
function getForm(field) {
var url = field.find('h4').data('url');
$.ajax({
url: url,
success: function (data) {
$('#chat-modal-form').html(data);
setChatFormSubmit();
$('#chat-modal-form').modal('show');
}
});
}
function setChatFormSubmit() {
var frm = $('#chat-form');
frm.submit(function () {
var formData = new FormData($(this)[0]);
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: formData,
dataType: "json",
async: false,
success: function (data) {
$('.messages-list').append(data.view);
$(".messages-container").each(function () {
var height = $(this)[0].scrollHeight;
$(this).animate({scrollTop: height}, 0);
});
$('#chat-modal-form').modal('hide');
alertify.success(data.message);
},
error: function(data) {
$("#chat-modal-form").html(data.responseText);
setChatFormSubmit();
},
cache: false,
contentType: false,
processData: false
});
return false;
});
}