File: /home/imensosw/.trash/resources.1/js/nodeClient.js
var socket = io.connect(socketPosrt);
$(document).on('click','.chat_submit',function() {
var msg = $( "#message" ).val();
if(msg=="")
{
return false;
}
socket.emit( 'chat message','test 2');
// Ajax call for saving datas
$.ajax({
url: url_path+"api/sendMessage",
type: "POST",
data: {_token:crf_token,message: msg , product_id : $("#productIdHidden").val() },
success: function(data)
{
htm='<div class="chat-bubble self-end">';
// htm+='<div class="chatp_img circle"> <img src="'+image+'" alt="profile name" /> </div>';
htm+='<div class="chatmsg box_shadow">'+msg+'</div>';
htm+='<div class="when_come">'+data.current_time+'</div>';
htm+='</div>';
$('.chat_box').append(htm);
$('#message').val('');
$('.chat-display').scrollTop($(".chat-display")[0].scrollHeight);
socket.emit( 'message', {chat_id:data.chat['id'],customer_id:send_by,current_time:data.current_time,message:msg,name: send_name,sendby:send_by,image:image,product_id:product_id } );
},
dataType:'json',
});
return false;
});
function notifyTyping() {
socket.emit('notifyUser', {sendby:send_by,name:send_name,product_id:product_id});
}
// Call the function
socket.on( 'message1', function( data ) {
alert(data.message);
// $('#messages').append(data.message);
});
socket.on('notifyUser', function(data){
if(nameList!="" && isExist(nameList,data.id) && product_id==data.product_id)
{
$('#notifyUser').text(data.name + ' is typing ...');
}
setTimeout(function(){ $('#notifyUser').text(''); }, 3000);
});
socket.on( 'message', function( data ) {
$(".notification_no_record").css("display", "none");
if(nameList!="" && isExist(nameList,data.id) && customer_id==data.customer_id && product_id==data.product_id)
{
htm='<div class="chat-bubble opposite-end">';
htm+='<div class="chatp_img circle"> <img src="'+data.image+'" alt="profile name" /> </div>';
htm+='<div class="chatmsg box_shadow">'+data.message+'</div>';
htm+='<div class="when_come">'+data.current_time+'</div>';
htm+='<div class="chat-unm mobile_hide">'+data.name+'</div>';
htm+='</div>';
$(".chat_box").append( htm );
$('.chat-display').scrollTop($(".chat-display")[0].scrollHeight);
chat_update(data.chat_id,customer_id);
}
else if($('.notification_'+data.product_id).length && customer_id==data.customer_id && product_id!=data.product_id)
{
$('.notification_'+data.product_id).removeClass('hidden');
var old_not=$('.notification_'+data.product_id).find('a').html();
if(old_not=="")
{
old_not=0;
}
old_not=Number(old_not)+1;
$('.notification_'+data.product_id).find('a').html(old_not);
}
else if($('.chat-notification').find('.circular').length && customer_id=="" && data.customer_id==send_by)
{
if($('.chat-notification').find('.circular').hasClass('hidden'))
{
$('.chat-notification').find('.circular').removeClass('hidden');
}
$('.chat-notification').find('.circular').find('a').show();
var old_not=$('.chat-notification').find('.circular').find('a').html();
if(old_not=="")
{
old_not=0;
}
old_not=Number(old_not)+1;
$('.chat-notification').find('.circular').find('a').html(old_not);
htm='<div class="min_height250"><div class="item" >'+data.message+'<div><small>Send By <strong>'+data.name+'</strong></small></div></div></div>';
$('.chat-notification').find('.menu').append(htm);
}
});
/*if(loggedin!="")
{
socket.emit( 'loginout', {id:send_by,status:'login'});
}*/
$(document).on('click','.logout',function(){
socket.emit( 'loginout', {id:send_by,status:'logout'});
window.location.href=url_path+"logout";
});
function chat_update(chat_id)
{
$.ajax({
url: url_path+"chat/incomingChatUpdate",
type: "POST",
data: {_token:crf_token,id: chat_id },
success: function(data) {
}
});
}