/*
Jappix - An open social platform
These are the Roster Item Exchange JS script for Jappix
-------------------------------------------------
License: AGPL
Author: Vanaryon
Last revision: 23/06/11
*/
// Opens the welcome tools
function openRosterX(data) {
// Popup HTML content
var html =
'
';
// Create the popup
createPopup('rosterx', html);
// Associate the events
launchRosterX();
// Parse the data
parseRosterX(data);
logThis('Roster Item Exchange popup opened.');
}
// Closes the welcome tools
function closeRosterX() {
// Destroy the popup
destroyPopup('rosterx');
return false;
}
// Parses a rosterx query
function parseRosterX(data) {
// Main selector
var x = $(data).find('x[xmlns=' + NS_ROSTERX + ']:first');
// Parse data
x.find('item').each(function() {
// Generate group XML
var group = '';
$(this).find('group').each(function() {
group += '' + $(this).text().htmlEnc() + '';
});
if(group)
group = '' + group + '';
// Display it!
displayRosterX($(this).attr('jid'), $(this).attr('name'), group, $(this).attr('action'));
});
// Click to check/uncheck
$('#rosterx .oneresult').click(function(evt) {
// No need to apply when click on input
if($(evt.target).is('input[type=checkbox]'))
return;
// Input selector
var checkbox = $(this).find('input[type=checkbox]');
// Check or uncheck?
if(checkbox.filter(':checked').size())
checkbox.removeAttr('checked');
else
checkbox.attr('checked', true);
});
}
// Displays a rosterx item
function displayRosterX(xid, nick, group, action) {
// End if no XID
if(!xid)
return false;
// Set up a default action if no one
if(!action || (action != 'modify') || (action != 'delete'))
action = 'add';
// Override "undefined" for nickname
if(!nick)
nick = '';
// Display it
$('#rosterx .results').append(
'