3 Jappix - An open social platform
4 These are the user-infos JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 27/03/11
14 // Opens the user-infos popup
15 function openUserInfos(xid) {
16 // Can show shortcuts?
20 shortcuts = '<div class="shortcuts">' +
21 '<a href="#" class="message talk-images" title="' + _e("Send him/her a message") + '" onclick="closeUserInfos(); return composeInboxMessage(\'' + encodeOnclick(xid) + '\');"></a>' +
22 '<a href="#" class="chat talk-images" title="' + _e("Start a chat with him/her") + '" onclick="closeUserInfos(); return checkChatCreate(\'' + encodeOnclick(xid) + '\', \'chat\');"></a>' +
23 '<a href="#" class="command talk-images" title="' + _e("Command") + '" onclick="closeUserInfos(); return retrieveAdHoc(\'' + encodeOnclick(xid) + '\');"></a>' +
29 '<div class="top">' + _e("User profile") + '</div>' +
32 '<a href="#" class="tab-active" data-key="1">' + _e("General") + '</a>' +
33 '<a href="#" data-key="2">' + _e("Advanced") + '</a>' +
34 '<a href="#" data-key="3">' + _e("Comments") + '</a>' +
37 '<div class="content">' +
38 '<div class="lap-active one-lap info1">' +
39 '<div class="main-infos">' +
40 '<div class="avatar-container">' +
41 '<img class="avatar" src="' + './img/others/default-avatar.png' + '" alt="" />' +
44 '<h1 id="BUDDY-FN" class="reset-info">' + _e("unknown") + '</h1>' +
45 '<h2 class="buddy-xid" class="reset-info">' + _e("unknown") + '</h2>' +
46 '<h3 class="buddy-last" class="reset-info">' + _e("unknown") + '</h3>' +
51 '<div class="block-infos">' +
52 '<div class="one-line"><b>' + _e("Date of birth") + '</b><span id="BUDDY-BDAY" class="reset-info">' + _e("unknown") + '</span></div>' +
54 '<div class="one-line"><b>' + _e("E-mail") + '</b><span id="BUDDY-EMAIL-USERID" class="reset-info">' + _e("unknown") + '</span></div>' +
56 '<div class="one-line"><b>' + _e("Phone") + '</b><span id="BUDDY-TEL-NUMBER" class="reset-info">' + _e("unknown") + '</span></div>' +
58 '<div class="one-line"><b>' + _e("Website") + '</b><span id="BUDDY-URL" class="reset-info">' + _e("unknown") + '</span></div>' +
61 '<div class="block-infos">' +
62 '<div class="one-line"><b>' + _e("Client") + '</b><span id="BUDDY-CLIENT" class="reset-info">' + _e("unknown") + '</span></div>' +
64 '<div class="one-line"><b>' + _e("System") + '</b><span id="BUDDY-SYSTEM" class="reset-info">' + _e("unknown") + '</span></div>' +
66 '<div class="one-line"><b>' + _e("Local time") + '</b><span id="BUDDY-TIME" class="reset-info">' + _e("unknown") + '</span></div>' +
70 '<div class="one-lap info2">' +
71 '<div class="block-infos">' +
72 '<div class="one-line"><b>' + _e("Street") + '</b><span id="BUDDY-ADR-STREET" class="reset-info">' + _e("unknown") + '</span></div>' +
74 '<div class="one-line"><b>' + _e("City") + '</b><span id="BUDDY-ADR-LOCALITY" class="reset-info">' + _e("unknown") + '</span></div>' +
76 '<div class="one-line"><b>' + _e("Postal code") + '</b><span id="BUDDY-ADR-PCODE" class="reset-info">' + _e("unknown") + '</span></div>' +
78 '<div class="one-line"><b>' + _e("Country") + '</b><span id="BUDDY-ADR-CTRY" class="reset-info">' + _e("unknown") + '</span></div>' +
81 '<div class="block-infos">' +
82 '<div class="one-line"><b>' + _e("Biography") + '</b><span id="BUDDY-DESC" class="reset-info">' + _e("unknown") + '</span></div>' +
86 '<div class="one-lap info3">' +
87 '<textarea class="rosternotes" rows="8" cols="60"></textarea>' +
91 '<div class="bottom">' +
92 '<div class="wait wait-medium"></div>' +
94 '<a href="#" class="finish">' + _e("Close") + '</a>' +
98 createPopup('userinfos', html);
100 // Associate the events
103 // We retrieve the user's vcard
104 retrieveUserInfos(xid);
109 // Closes the user-infos popup
110 function closeUserInfos() {
111 // Send the buddy comments
115 destroyPopup('userinfos');
120 // Gets the user-infos
121 function retrieveUserInfos(xid) {
122 // We setup the waiting indicator
123 markers = 'vcard last';
125 // We put the user's XID
126 $('#userinfos .buddy-xid').text(xid);
129 getVCard(xid, 'buddy');
131 // Get the highest resource for this XID
132 var cXID = getHighestResource(xid);
135 // If the user is logged in
140 // We request the user's system infos
141 queryUserInfos(cXID, 'version')
143 // We request the user's local time
144 queryUserInfos(cXID, 'time')
146 // Add these to the markers
147 markers += ' version time';
150 // We request the user's last activity
151 queryUserInfos(pXID, 'last');
154 $('#userinfos .content').addClass(markers);
156 // We request all the user's comments
157 displayBuddyComments(xid);
160 // Builds the asked user-infos query
161 function queryUserInfos(xid, mode) {
162 // Generate a session ID
164 $('#userinfos').attr('data-' + mode, id);
167 var iq = new JSJaCIQ();
173 // Last activity query
175 iq.setQuery(NS_LAST);
176 con.send(iq, lastActivityUserInfos);
180 else if(mode == 'time') {
181 iq.appendNode('time', {'xmlns': NS_URN_TIME});
182 con.send(iq, localTimeUserInfos);
186 else if(mode == 'version') {
187 iq.setQuery(NS_VERSION);
188 con.send(iq, versionUserInfos);
192 // Checks if the waiting item can be hidden
193 function vCardBuddyInfos() {
194 $('#userinfos .content').removeClass('vcard');
198 // Displays the buddy comments
199 function displayBuddyComments(xid) {
200 // We get the value in the database
201 var value = getDB('rosternotes', xid);
205 $('#userinfos .rosternotes').val(value);
208 // Displays the user's last activity result
209 function lastActivityUserInfos(iq) {
210 // Extract the request ID
212 var path = '#userinfos[data-last=' + id + ']';
214 // End if session does not exist
218 if(iq && (iq.getType() == 'result')) {
220 var from = fullXID(getStanzaFrom(iq));
221 var seconds = $(iq.getNode()).find('query').attr('seconds');
224 if(seconds != undefined) {
225 // Initialize the parsing
227 seconds = parseInt(seconds);
231 last = _e("User currently active");
236 var date_now = new Date();
237 var time_now = date_now.getTime();
238 var date_last = new Date(date_now - (seconds * 1000));
239 var date = date_last.toLocaleString();
242 if(from.indexOf('/') == -1)
243 last = printf(_e("Last seen: %s"), date);
247 last = printf(_e("Inactive since: %s"), date);
251 $('#userinfos .buddy-last').text(last);
254 logThis('Last activity received: ' + from);
257 $('#userinfos .content').removeClass('last');
261 // Displays the user's software version result
262 function versionUserInfos(iq) {
263 // Extract the request ID
265 var path = '#userinfos[data-version=' + id + ']';
267 // End if session does not exist
271 // Extract the reply data
272 if(iq && (iq.getType() == 'result')) {
274 var xml = iq.getQuery();
275 var name = $(xml).find('name').text();
276 var version = $(xml).find('version').text();
277 var os = $(xml).find('os').text();
279 // Put the values together
281 name = name + ' ' + version;
283 // Display the values
285 $(path + ' #BUDDY-CLIENT').text(name);
287 $(path + ' #BUDDY-SYSTEM').text(os);
289 logThis('Software version received: ' + fullXID(getStanzaFrom(iq)));
292 $('#userinfos .content').removeClass('version');
296 // Displays the user's local time result
297 function localTimeUserInfos(iq) {
298 // Extract the request ID
300 var path = '#userinfos[data-time=' + id + ']';
302 // End if session does not exist
306 if(iq && (iq.getType() == 'result')) {
308 var xml = iq.getNode();
309 var tzo = $(xml).find('tzo').text();
310 var utc = $(xml).find('utc').text();
314 // Add the TZO if there's no one
315 if(tzo && utc.match(/^(.+)Z$/))
316 utc = RegExp.$1 + tzo;
318 // Get the local date string
319 var local_string = Date.hrTime(utc);
322 $(path + ' #BUDDY-TIME').text(local_string);
325 logThis('Local time received: ' + fullXID(getStanzaFrom(iq)));
328 $('#userinfos .content').removeClass('time');
332 // Hides the waiting image if needed
333 function wUserInfos() {
334 var selector = $('#userinfos .content');
336 if(!selector.hasClass('vcard') && !selector.hasClass('last') && !selector.hasClass('version') && !selector.hasClass('time'))
337 $('#userinfos .wait').hide();
340 // Sends the buddy comments
341 function sendBuddyComments() {
342 // Update the current value
343 var value = $('#userinfos .rosternotes').val();
344 var xid = $('#userinfos .buddy-xid').text();
346 // Necessary to update?
347 var old_value = getDB('rosternotes', xid);
349 if((old_value == value) || (!old_value && !value))
352 // Update the database
353 setDB('rosternotes', xid, value);
355 // Send the new buddy storage values
356 var iq = new JSJaCIQ();
358 var query = iq.setQuery(NS_PRIVATE);
359 var storage = query.appendChild(iq.buildNode('storage', {'xmlns': NS_ROSTERNOTES}));
361 // We regenerate the XML
362 for(var i = 0; i < sessionStorage.length; i++) {
363 // Get the pointer values
364 var current = sessionStorage.key(i);
366 // If the pointer is on a stored rosternote
367 if(explodeThis('_', current, 0) == 'rosternotes') {
368 var xid = explodeThis('_', current, 1);
369 var value = sessionStorage.getItem(current);
372 storage.appendChild(iq.buildNode('note', {'jid': xid, 'xmlns': NS_ROSTERNOTES}, value));
381 // Switches the user-infos tabs
382 function switchUInfos(id) {
383 $('#userinfos .content .one-lap').hide();
384 $('#userinfos .content .info' + id).show();
385 $('#userinfos .tab a').removeClass('tab-active');
386 $('#userinfos .tab a[data-key=' + id + ']').addClass('tab-active');
391 // Gets the user's informations when creating a new chat
392 function getUserInfos(hash, xid, nick, type) {
393 // This is a normal chat
394 if(type != 'private') {
395 // Display the buddy name
397 $('#' + hash + ' .top .name .bc-name').text(nick);
398 $('#page-switch .' + hash + ' .name').text(nick);
401 // Get the buddy PEP informations
405 // Display the buddy presence
406 presenceFunnel(xid, hash);
410 function launchUserInfos() {
412 $('#userinfos .tab a').click(function() {
414 if($(this).hasClass('tab-active'))
417 // Switch to the good tab
418 var key = parseInt($(this).attr('data-key'));
420 return switchUInfos(key);
423 $('#userinfos .bottom .finish').click(function() {
424 return closeUserInfos();