mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-16 21:34:25 +03:00
162 lines
5 KiB
JavaScript
162 lines
5 KiB
JavaScript
var ls = ls || {};
|
|
|
|
/**
|
|
* Функционал личных сообщений
|
|
*/
|
|
ls.talk = (function ($) {
|
|
|
|
/**
|
|
* Добавляет пользователя к переписке
|
|
*/
|
|
this.addToTalk = function(idTalk){
|
|
var sUsers = $('#talk_speaker_add').val();
|
|
if(!sUsers) return false;
|
|
$('#talk_speaker_add').val('');
|
|
|
|
ls.ajax(aRouter['talk']+'ajaxaddtalkuser/', {users: sUsers, idTalk: idTalk}, function(result) {
|
|
if (result.bStateError) {
|
|
ls.msg.error(null, result.sMsg);
|
|
} else {
|
|
$.each(result.aUsers, function(index, item) {
|
|
if(item.bStateError){
|
|
ls.msg.notice(null, item.sMsg);
|
|
} else {
|
|
if($('#speaker_list').length == 0) {
|
|
$('#speaker_list_block').append($('<ul class="list" id="speaker_list"></ul>'));
|
|
}
|
|
$('#speaker_list').append($('<li id="speaker_item_'+item.sUserId+'_area"><a href="'+item.sUserLink+'" class="user">'+item.sUserLogin+'</a> - <a href="#" id="speaker_item_'+item.sUserId+'" class="delete">'+ls.lang.get('delete')+'</a></li>'));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Удаляет пользователя из переписки
|
|
*/
|
|
this.removeFromTalk = function(link, idTalk) {
|
|
link = $(link);
|
|
|
|
$('#'+link.attr('id')+'_area').fadeOut(500,function(){
|
|
$(this).remove();
|
|
});
|
|
idTarget = link.attr('id').replace('speaker_item_','');
|
|
|
|
ls.ajax(aRouter['talk']+'ajaxdeletetalkuser/', {idTarget: idTarget, idTalk: idTalk}, function(result) {
|
|
if (!result) {
|
|
ls.msg.error('Error','Please try again later');
|
|
link.parent('li').show();
|
|
}
|
|
if (result.bStateError) {
|
|
ls.msg.error(null, result.sMsg);
|
|
link.parent('li').show();
|
|
}
|
|
});
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Добавляет пользователя в черный список
|
|
*/
|
|
this.addToBlackList = function() {
|
|
var sUsers = $('#talk_blacklist_add').val();
|
|
if(!sUsers) return false;
|
|
$('#talk_blacklist_add').val('');
|
|
|
|
ls.ajax(aRouter['talk']+'ajaxaddtoblacklist/', {users: sUsers}, function(result) {
|
|
if (result.bStateError) {
|
|
ls.msg.error(null, result.sMsg);
|
|
} else {
|
|
$.each(result.aUsers, function(index, item) {
|
|
if(item.bStateError){
|
|
ls.msg.notice(null, item.sMsg);
|
|
} else {
|
|
if($('#black_list').length == 0) {
|
|
$('#black_list_block').append($('<ul class="list" id="black_list"></ul>'));
|
|
}
|
|
$('#black_list').append($('<li id="blacklist_item_'+item.sUserId+'_area"><a href="#" class="user">'+item.sUserLogin+'</a> - <a href="#" id="blacklist_item_'+item.sUserId+'" class="delete">'+ls.lang.get('delete')+'</a></li>'));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Удаляет пользователя из черного списка
|
|
*/
|
|
this.removeFromBlackList = function(link) {
|
|
link = $(link);
|
|
|
|
$('#'+link.attr('id')+'_area').fadeOut(500,function(){
|
|
$(this).remove();
|
|
});
|
|
var idTarget = link.attr('id').replace('blacklist_item_','');
|
|
|
|
ls.ajax(aRouter['talk']+'ajaxdeletefromblacklist/', {idTarget: idTarget}, function(result) {
|
|
if (!result) {
|
|
ls.msg.error('Error','Please try again later');
|
|
link.parent('li').show();
|
|
}
|
|
if (result.bStateError) {
|
|
ls.msg.error(null, result.sMsg);
|
|
link.parent('li').show();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Добавляет или удаляет друга из списка получателей
|
|
*/
|
|
this.toggleRecipient = function(login, add) {
|
|
var to = $.map($('#talk_users').val().split(','), function(item, index){
|
|
item = $.trim(item);
|
|
return item != '' ? item : null;
|
|
});
|
|
if (add) { to.push(login); to = $.richArray.unique(to); } else { to = $.richArray.without(to, login); }
|
|
$('#talk_users').val(to.join(', '));
|
|
}
|
|
|
|
return this;
|
|
}).call(ls.talk || {},jQuery);
|
|
|
|
|
|
jQuery(document).ready(function($){
|
|
// Добавляем или удаляем друга из списка получателей
|
|
$('#friends input:checkbox').change(function(){
|
|
ls.talk.toggleRecipient($('#'+$(this).attr('id')+'_label').text(), $(this).attr('checked'));
|
|
});
|
|
|
|
// Добавляем всех друзей в список получателей
|
|
$('#friend_check_all').click(function(){
|
|
$('#friends input:checkbox').each(function(index, item){
|
|
ls.talk.toggleRecipient($('#'+$(item).attr('id')+'_label').text(), true);
|
|
$(item).attr('checked', true);
|
|
});
|
|
return false;
|
|
});
|
|
|
|
// Удаляем всех друзей из списка получателей
|
|
$('#friend_uncheck_all').click(function(){
|
|
$('#friends input:checkbox').each(function(index, item){
|
|
ls.talk.toggleRecipient($('#'+$(item).attr('id')+'_label').text(), false);
|
|
$(item).attr('checked', false);
|
|
});
|
|
return false;
|
|
});
|
|
|
|
// Удаляем пользователя из черного списка
|
|
$("#black_list_block").delegate("a.delete", "click", function(){
|
|
ls.talk.removeFromBlackList(this);
|
|
return false;
|
|
});
|
|
|
|
// Удаляем пользователя из переписки
|
|
$("#speaker_list_block").delegate("a.delete", "click", function(){
|
|
ls.talk.removeFromTalk(this, $('#talk_id').val());
|
|
return false;
|
|
});
|
|
}); |