mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/IZYIM-Manufacturer.git
synced 2026-08-27 00:03:58 +00:00
137 lines
4.3 KiB
JavaScript
137 lines
4.3 KiB
JavaScript
var Script = function() {
|
|
|
|
$(document).ready(function(e) {
|
|
$(".menu-toggler").trigger('click');
|
|
|
|
|
|
$('#tree_1').on("changed.jstree", function(e, data) {
|
|
$("#kasi-kosong").empty();
|
|
$("#kasi-kosong").html('<div id="get_user_id" data-id="' + data.selected + '" style="display:none"></div>');
|
|
$("#general_content").empty();
|
|
startRefresh(data.selected);
|
|
});
|
|
|
|
$('body').on('click', '.message .name', function(e) {
|
|
e.preventDefault(); // prevent click event
|
|
|
|
var name = $(this).text(); // get clicked user's full name
|
|
input.val('@' + name + ':'); // set it into the input field
|
|
App.scrollTo(input); // scroll to input if needed
|
|
});
|
|
|
|
var cont = $('#chats');
|
|
var list = $('.chats', cont);
|
|
var form = $('.chat-form', cont);
|
|
var input = $('input', form);
|
|
var btn = $('.btn', form);
|
|
input.keypress(function(e) {
|
|
if (e.which == 13) {
|
|
|
|
var user_id = $('#get_user_id').data('id');
|
|
var text = input.val();
|
|
if (text.length == 0) {
|
|
return;
|
|
}
|
|
sendChat(text, user_id);
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
function sendChat(text, user_id) {
|
|
var dataStringg = 'user_id=' + user_id + '&text=' + text;
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/send-help",
|
|
data: dataStringg,
|
|
success: function(data) {
|
|
var cont = $('#chats');
|
|
var form = $('.chat-form', cont);
|
|
var input = $('input', form);
|
|
input.val('');
|
|
var trimmed = $.trim(data);
|
|
$("#general_content").append(trimmed);
|
|
var getLastPostPos = function() {
|
|
var height = 0;
|
|
cont.find("li.out, li.in").each(function() {
|
|
height = height + $("#general_content").outerHeight();
|
|
});
|
|
|
|
return height;
|
|
}
|
|
|
|
cont.find('.scroller').slimScroll({
|
|
scrollTo: getLastPostPos()
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function startRefresh(from_id) {
|
|
var id = 0;
|
|
if ($('#general_content').is(':empty')) {
|
|
var dataStringg = 'id=' + id + '&from_id=' + from_id;
|
|
} else {
|
|
id = $("li").last().data('id');
|
|
var from_id = $('#get_user_id').data('id');
|
|
var last_date = $('.date:last').data('id');
|
|
var dataStringg = 'id=' + id + '&last_date=' + last_date + '&from_id=' + from_id;
|
|
}
|
|
if ((from_id === undefined || from_id === null)) {} else {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/get-help",
|
|
data: dataStringg,
|
|
beforeSend: function() {
|
|
$(".unread").remove();
|
|
},
|
|
success: function(data) {
|
|
var trimmed = $.trim(data);
|
|
var cont = $('#chats');
|
|
|
|
$("#general_content").append(trimmed);
|
|
var getLastPostPos = function() {
|
|
var height = 0;
|
|
cont.find("li.out, li.in").each(function() {
|
|
height = height + $("#general_content").outerHeight();
|
|
});
|
|
|
|
return height;
|
|
}
|
|
|
|
cont.find('.scroller').slimScroll({
|
|
scrollTo: getLastPostPos()
|
|
});
|
|
setTimeout(startRefresh, 3500);
|
|
}
|
|
});
|
|
|
|
};
|
|
};
|
|
|
|
// function getSide() {
|
|
// $.ajax({
|
|
// type: "POST",
|
|
// url: "/get-side",
|
|
// success: function(data) {
|
|
// var trimmed = $.trim(data);
|
|
// if ( ! $("#tree_lists li").length ){
|
|
// $('#tree_1').jstree(true).settings.core.data = data;
|
|
// $('#tree_1').jstree(true).redraw(true);
|
|
// }else{
|
|
// $('#tree_1').jstree(true).settings.core.data = data;
|
|
// $('#tree_1').jstree(true).refresh();
|
|
// }
|
|
|
|
|
|
// setTimeout(getSide, 3500);
|
|
// }
|
|
// });
|
|
|
|
};
|
|
$(function() {
|
|
startRefresh();
|
|
// getSide();
|
|
});
|
|
|
|
}(); |