3 Jappix - An open social platform
4 These are the Roster Item Exchange JS script for Jappix
6 -------------------------------------------------
10 Last revision: 23/06/11
14 // Opens the welcome tools
15 function openRosterX(data) {
18 '<div class="top">' + _e("Suggested friends") + '</div>' +
20 '<div class="content">' +
21 '<div class="rosterx-head">' +
22 '<a href="#" class="uncheck">' + _e("Uncheck all") + '</a>' +
23 '<a href="#" class="check">' + _e("Check all") + '</a>' +
26 '<div class="results"></div>' +
29 '<div class="bottom">' +
30 '<a href="#" class="finish save">' + _e("Save") + '</a>' +
31 '<a href="#" class="finish cancel">' + _e("Cancel") + '</a>' +
35 createPopup('rosterx', html);
37 // Associate the events
43 logThis('Roster Item Exchange popup opened.');
46 // Closes the welcome tools
47 function closeRosterX() {
49 destroyPopup('rosterx');
54 // Parses a rosterx query
55 function parseRosterX(data) {
57 var x = $(data).find('x[xmlns=' + NS_ROSTERX + ']:first');
60 x.find('item').each(function() {
64 $(this).find('group').each(function() {
65 group += '<group>' + $(this).text().htmlEnc() + '</group>';
69 group = '<groups>' + group + '</groups>';
72 displayRosterX($(this).attr('jid'), $(this).attr('name'), group, $(this).attr('action'));
75 // Click to check/uncheck
76 $('#rosterx .oneresult').click(function(evt) {
77 // No need to apply when click on input
78 if($(evt.target).is('input[type=checkbox]'))
82 var checkbox = $(this).find('input[type=checkbox]');
85 if(checkbox.filter(':checked').size())
86 checkbox.removeAttr('checked');
88 checkbox.attr('checked', true);
92 // Displays a rosterx item
93 function displayRosterX(xid, nick, group, action) {
98 // Set up a default action if no one
99 if(!action || (action != 'modify') || (action != 'delete'))
102 // Override "undefined" for nickname
107 $('#rosterx .results').append(
108 '<div class="oneresult">' +
109 '<input type="checkbox" checked="" data-name="' + encodeQuotes(nick) + '" data-xid="' + encodeQuotes(xid) + '" data-action="' + encodeQuotes(action) + '" data-group="' + encodeQuotes(group) + '" />' +
110 '<span class="name">' + nick.htmlEnc() + '</span>' +
111 '<span class="xid">' + xid.htmlEnc() + '</span>' +
112 '<span class="action ' + action + ' talk-images"></span>' +
117 // Saves the rosterx settings
118 function saveRosterX() {
120 $('#rosterx .results input[type=checkbox]').filter(':checked').each(function() {
121 // Read the attributes
122 var nick = $(this).attr('data-name');
123 var xid = $(this).attr('data-xid');
124 var action = $(this).attr('data-action');
125 var group = $(this).attr('data-group');
131 $(group).find('group').each(function() {
132 group_arr.push($(this).text().revertHtmlEnc());
136 // Process the asked action
137 var roster_item = $('#buddy-list .' + hex_md5(xid));
142 if(!exists(roster_item)) {
143 sendSubscribe(xid, 'subscribe');
144 sendRoster(xid, '', nick, group_arr);
151 if(exists(roster_item))
152 sendRoster(xid, '', nick, group_arr);
158 if(exists(roster_item))
159 sendRoster(xid, 'remove');
170 function launchRosterX() {
172 $('#rosterx .bottom .finish').click(function() {
173 if($(this).is('.save'))
174 return saveRosterX();
175 if($(this).is('.cancel'))
176 return closeRosterX();
179 $('#rosterx .rosterx-head a').click(function() {
180 if($(this).is('.check'))
181 $('#rosterx .results input[type=checkbox]').attr('checked', true);
182 else if($(this).is('.uncheck'))
183 $('#rosterx .results input[type=checkbox]').removeAttr('checked');