1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-08 01:14:24 +03:00
ifhub.club/templates/skin/developer-jquery/js/talk.js

162 lines
5 KiB
JavaScript
Raw Normal View History

2011-05-03 16:19:47 +03:00
var ls = ls || {};
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
/**
* Функционал личных сообщений
*/
ls.talk = (function ($) {
/**
* Добавляет пользователя к переписке
*/
this.addToTalk = function(idTalk){
var sUsers = $('#talk_speaker_add').val();
2011-04-01 10:49:36 +03:00
if(!sUsers) return false;
$('#talk_speaker_add').val('');
2011-05-03 16:19:47 +03:00
ls.ajax(aRouter['talk']+'ajaxaddtalkuser/', {users: sUsers, idTalk: idTalk}, function(result) {
2011-04-01 10:49:36 +03:00
if (result.bStateError) {
2011-05-03 16:19:47 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
} else {
$.each(result.aUsers, function(index, item) {
if(item.bStateError){
2011-05-03 16:19:47 +03:00
ls.msg.notice(null, item.sMsg);
2011-04-01 10:49:36 +03:00
} else {
if($('#speaker_list').length == 0) {
$('#speaker_list_block').append($('<ul class="list" id="speaker_list"></ul>'));
}
2011-08-23 17:19:32 +03:00
$('#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>'));
2011-04-01 10:49:36 +03:00
}
});
}
});
return false;
2011-05-03 16:19:47 +03:00
};
/**
* Удаляет пользователя из переписки
*/
this.removeFromTalk = function(link, idTalk) {
2011-04-01 10:49:36 +03:00
link = $(link);
2011-05-03 16:19:47 +03:00
$('#'+link.attr('id')+'_area').fadeOut(500,function(){
$(this).remove();
});
2011-04-01 10:49:36 +03:00
idTarget = link.attr('id').replace('speaker_item_','');
2011-05-03 16:19:47 +03:00
ls.ajax(aRouter['talk']+'ajaxdeletetalkuser/', {idTarget: idTarget, idTalk: idTalk}, function(result) {
2011-04-01 10:49:36 +03:00
if (!result) {
2011-05-03 16:19:47 +03:00
ls.msg.error('Error','Please try again later');
2011-04-01 10:49:36 +03:00
link.parent('li').show();
}
if (result.bStateError) {
2011-05-03 16:19:47 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
link.parent('li').show();
}
});
2011-05-03 16:19:47 +03:00
2011-04-01 10:49:36 +03:00
return false;
2011-05-03 16:19:47 +03:00
}
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
/**
* Добавляет пользователя в черный список
*/
this.addToBlackList = function() {
var sUsers = $('#talk_blacklist_add').val();
2011-04-01 10:49:36 +03:00
if(!sUsers) return false;
$('#talk_blacklist_add').val('');
2011-05-03 16:19:47 +03:00
ls.ajax(aRouter['talk']+'ajaxaddtoblacklist/', {users: sUsers}, function(result) {
2011-04-01 10:49:36 +03:00
if (result.bStateError) {
2011-05-03 16:19:47 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
} else {
$.each(result.aUsers, function(index, item) {
if(item.bStateError){
2011-05-03 16:19:47 +03:00
ls.msg.notice(null, item.sMsg);
2011-04-01 10:49:36 +03:00
} else {
if($('#black_list').length == 0) {
$('#black_list_block').append($('<ul class="list" id="black_list"></ul>'));
}
2011-08-23 17:19:32 +03:00
$('#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>'));
2011-04-01 10:49:36 +03:00
}
});
}
});
return false;
2011-05-03 16:19:47 +03:00
}
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
/**
* Удаляет пользователя из черного списка
*/
this.removeFromBlackList = function(link) {
2011-04-01 10:49:36 +03:00
link = $(link);
2011-05-03 16:19:47 +03:00
$('#'+link.attr('id')+'_area').fadeOut(500,function(){
$(this).remove();
});
var idTarget = link.attr('id').replace('blacklist_item_','');
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
ls.ajax(aRouter['talk']+'ajaxdeletefromblacklist/', {idTarget: idTarget}, function(result) {
2011-04-01 10:49:36 +03:00
if (!result) {
2011-05-03 16:19:47 +03:00
ls.msg.error('Error','Please try again later');
2011-04-01 10:49:36 +03:00
link.parent('li').show();
}
if (result.bStateError) {
2011-05-03 16:19:47 +03:00
ls.msg.error(null, result.sMsg);
2011-04-01 10:49:36 +03:00
link.parent('li').show();
}
});
return false;
2011-05-03 16:19:47 +03:00
}
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
/**
* Добавляет или удаляет друга из списка получателей
*/
this.toggleRecipient = function(login, add) {
var to = $.map($('#talk_users').val().split(','), function(item, index){
item = $.trim(item);
2011-04-01 10:49:36 +03:00
return item != '' ? item : null;
});
if (add) { to.push(login); to = $.richArray.unique(to); } else { to = $.richArray.without(to, login); }
$('#talk_users').val(to.join(', '));
2011-05-03 16:19:47 +03:00
}
return this;
}).call(ls.talk || {},jQuery);
2011-04-01 10:49:36 +03:00
2011-05-03 16:19:47 +03:00
jQuery(document).ready(function($){
2011-04-01 12:54:47 +03:00
// Добавляем или удаляем друга из списка получателей
2011-04-01 10:49:36 +03:00
$('#friends input:checkbox').change(function(){
2011-05-03 16:19:47 +03:00
ls.talk.toggleRecipient($('#'+$(this).attr('id')+'_label').text(), $(this).attr('checked'));
2011-04-01 10:49:36 +03:00
});
2011-04-01 12:54:47 +03:00
// Добавляем всех друзей в список получателей
2011-04-01 10:49:36 +03:00
$('#friend_check_all').click(function(){
$('#friends input:checkbox').each(function(index, item){
2011-05-03 16:19:47 +03:00
ls.talk.toggleRecipient($('#'+$(item).attr('id')+'_label').text(), true);
2011-04-01 10:49:36 +03:00
$(item).attr('checked', true);
});
2011-05-03 16:19:47 +03:00
return false;
2011-04-01 10:49:36 +03:00
});
2011-04-01 12:54:47 +03:00
// Удаляем всех друзей из списка получателей
2011-04-01 10:49:36 +03:00
$('#friend_uncheck_all').click(function(){
$('#friends input:checkbox').each(function(index, item){
2011-05-03 16:19:47 +03:00
ls.talk.toggleRecipient($('#'+$(item).attr('id')+'_label').text(), false);
2011-04-01 10:49:36 +03:00
$(item).attr('checked', false);
});
2011-05-03 16:19:47 +03:00
return false;
2011-04-01 10:49:36 +03:00
});
2011-04-01 12:54:47 +03:00
// Удаляем пользователя из черного списка
2011-04-01 10:49:36 +03:00
$("#black_list_block").delegate("a.delete", "click", function(){
2011-05-03 16:19:47 +03:00
ls.talk.removeFromBlackList(this);
return false;
2011-04-01 10:49:36 +03:00
});
2011-04-01 12:54:47 +03:00
// Удаляем пользователя из переписки
2011-04-01 10:49:36 +03:00
$("#speaker_list_block").delegate("a.delete", "click", function(){
2011-05-03 16:19:47 +03:00
ls.talk.removeFromTalk(this, $('#talk_id').val());
return false;
2011-04-01 10:49:36 +03:00
});
});