3 Jappix - An open social platform
4 These are the options JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 17/07/11
14 // Opens the options popup
15 function optionsOpen() {
18 '<div class="top">' + _e("Edit options") + '</div>' +
21 '<a href="#" class="tab-active" data-key="1">' + _e("General") + '</a>' +
22 '<a href="#" class="pubsub-hidable" data-key="2">' + _e("Channel") + '</a>' +
23 '<a href="#" data-key="3">' + _e("Account") + '</a>' +
26 '<div class="content">' +
27 '<div id="conf1" class="lap-active one-lap forms">' +
28 '<fieldset class="privacy">' +
29 '<legend>' + _e("Privacy") + '</legend>' +
31 '<label for="geolocation" class="pep-hidable">' + _e("Geolocation") + '</label>' +
32 '<input id="geolocation" type="checkbox" class="pep-hidable" />' +
34 '<label for="archiving" class="archives-hidable pref">' + _e("Message archiving") + '</label>' +
35 '<input id="archiving" type="checkbox" class="archives-hidable pref" />' +
39 '<legend>' + _e("Application") + '</legend>' +
41 '<label for="sounds">' + _e("Sounds") + '</label>' +
42 '<input id="sounds" type="checkbox" />' +
44 '<label for="showall">' + _e("Show all friends") + '</label>' +
45 '<input id="showall" type="checkbox" />' +
47 '<label for="integratemedias">' + _e("Media integration") + '</label>' +
48 '<input id="integratemedias" type="checkbox" />' +
50 '<label class="xmpplinks-hidable">' + _e("XMPP links") + '</label>' +
51 '<a href="#" class="linked xmpp-links xmpplinks-hidable">' + _e("Open XMPP links with Jappix") + '</a>' +
55 '<div id="conf2" class="one-lap forms">' +
57 '<legend>' + _e("Channel") + '</legend>' +
59 '<label>' + _e("Empty") + '</label>' +
60 '<a href="#" class="linked empty-channel">' + _e("Empty channel") + '</a>' +
62 '<label>' + _e("Persistent") + '</label>' +
63 '<input id="persistent" type="checkbox" />' +
65 '<label>' + _e("Maximum notices") + '</label>' +
66 '<select id="maxnotices">' +
67 '<option value="1">1</option>' +
68 '<option value="100">100</option>' +
69 '<option value="1000">1000</option>' +
70 '<option value="10000">10000</option>' +
71 '<option value="100000">100000</option>' +
72 '<option value="1000000">1000000</option>' +
76 '<div class="sub-ask sub-ask-empty sub-ask-element">' +
77 '<div class="sub-ask-top">' +
78 '<div class="sub-ask-title">' + _e("Empty channel") + '</div>' +
79 '<a href="#" class="sub-ask-close">X</a>' +
82 '<div class="sub-ask-content">' +
83 '<label>' + _e("Password") + '</label>' +
84 '<input type="password" class="purge-microblog check-empty" required="" />' +
87 '<a href="#" class="sub-ask-bottom">' + _e("Empty") + ' »</a>' +
91 '<div id="conf3" class="one-lap forms">' +
93 '<legend>' + _e("Account") + '</legend>' +
95 '<label>' + _e("Password") + '</label>' +
96 '<a href="#" class="linked change-password">' + _e("Change password") + '</a>' +
98 '<label>' + _e("Delete") + '</label>' +
99 '<a href="#" class="linked delete-account">' + _e("Delete account") + '</a>' +
102 '<div class="sub-ask sub-ask-pass sub-ask-element">' +
103 '<div class="sub-ask-top">' +
104 '<div class="sub-ask-title">' + _e("Change password") + '</div>' +
105 '<a href="#" class="sub-ask-close">X</a>' +
108 '<div class="sub-ask-content">' +
109 '<label>' + _e("Old") + '</label>' +
110 '<input type="password" class="password-change old" required="" />' +
112 '<label>' + _e("New (2 times)") + '</label>' +
113 '<input type="password" class="password-change new1" required="" />' +
114 '<input type="password" class="password-change new2" required="" />' +
117 '<a href="#" class="sub-ask-bottom">' + _e("Continue") + ' »</a>' +
120 '<div class="sub-ask sub-ask-delete sub-ask-element">' +
121 '<div class="sub-ask-top">' +
122 '<div class="sub-ask-title">' + _e("Delete account") + '</div>' +
123 '<a href="#" class="sub-ask-close">X</a>' +
126 '<div class="sub-ask-content">' +
127 '<label>' + _e("Password") + '</label>' +
128 '<input type="password" class="delete-account check-password" required="" />' +
131 '<a href="#" class="sub-ask-bottom">' + _e("Delete") + ' »</a>' +
136 '<div class="bottom">' +
137 '<div class="wait wait-medium"></div>' +
139 '<a href="#" class="finish save">' + _e("Save") + '</a>' +
140 '<a href="#" class="finish cancel">' + _e("Cancel") + '</a>' +
144 createPopup('options', html);
146 // Apply the features
147 applyFeatures('options');
149 // Associate the events
155 // Closes the options popup
156 function closeOptions() {
158 destroyPopup('options');
163 // Checks whether the options are loaded or not
164 function loadedOptions() {
165 if($('.options-hidable').is(':visible'))
171 // Switches between the options tabs
172 function switchOptions(id) {
173 $('#options .one-lap').hide();
174 $('#options #conf' + id).show();
175 $('#options .tab a').removeClass('tab-active');
176 $('#options .tab a[data-key=' + id + ']').addClass('tab-active');
181 // Manages the options wait item
182 function waitOptions(id) {
183 var sOptions = $('#options .content');
185 // Remove the current item class
186 sOptions.removeClass(id);
188 // Hide the waiting items if all was received
189 if(!sOptions.hasClass('microblog') && !sOptions.hasClass('archives')) {
190 $('#options .wait').hide();
191 $('#options .finish:first').removeClass('disabled');
195 // Sends the options to the XMPP server
196 function storeOptions() {
198 var sounds = getDB('options', 'sounds');
199 var geolocation = getDB('options', 'geolocation');
200 var showall = getDB('options', 'roster-showall');
201 var integratemedias = getDB('options', 'integratemedias');
202 var status = getDB('options', 'presence-status');
204 // Create an array to be looped
205 var oType = new Array('sounds', 'geolocation', 'roster-showall', 'integratemedias', 'presence-status');
206 var oContent = new Array(sounds, geolocation, showall, integratemedias, status);
209 var iq = new JSJaCIQ();
212 var query = iq.setQuery(NS_PRIVATE);
213 var storage = query.appendChild(iq.buildNode('storage', {'xmlns': NS_OPTIONS}));
217 storage.appendChild(iq.buildNode('option', {'type': oType[i], 'xmlns': NS_OPTIONS}, oContent[i]));
219 con.send(iq, handleStoreOptions);
221 logThis('Storing options...', 3);
224 // Handles the option storing
225 function handleStoreOptions(iq) {
226 if(!iq || (iq.getType() != 'result'))
227 logThis('Options not stored.', 2);
229 logThis('Options stored.', 3);
232 // Saves the user options
233 function saveOptions() {
234 // We apply the sounds
237 if($('#sounds').filter(':checked').size())
240 setDB('options', 'sounds', sounds);
242 // We apply the geolocation
243 if($('#geolocation').filter(':checked').size()) {
244 setDB('options', 'geolocation', '1');
246 // We geolocate the user on the go
251 setDB('options', 'geolocation', '0');
253 // We delete the geolocation informations
255 removeDB('geolocation', 'now');
258 // We apply the roster show all
259 if($('#showall').filter(':checked').size()) {
260 setDB('options', 'roster-showall', '1');
261 showAllBuddies('options');
265 setDB('options', 'roster-showall', '0');
266 showOnlineBuddies('options');
269 // We apply the media integration
270 var integratemedias = '0';
272 if($('#integratemedias').filter(':checked').size())
273 integratemedias = '1';
275 setDB('options', 'integratemedias', integratemedias);
277 // We apply the message archiving
278 if(enabledArchives('pref')) {
279 var aEnabled = false;
281 if($('#archiving').filter(':checked').size())
284 configArchives(aEnabled);
287 // We apply the microblog configuration
289 var maximum = $('#maxnotices').val();
291 if($('#persistent').filter(':checked').size())
294 if(enabledPEP() && enabledPubSub())
295 setupMicroblog('', NS_URN_MBLOG, persist, maximum, '', '', false);
297 // We send the options to the database
306 // Handles the password changing
307 function handlePwdChange(iq) {
308 // Remove the general wait item
312 if(!handleErrorReply(iq)) {
317 logThis('Password changed.', 3);
321 logThis('Password not changed.', 2);
324 // Sends the new account password
325 function sendNewPassword() {
326 /* REF: http://xmpp.org/extensions/xep-0077.html#usecases-changepw */
328 var password0 = $('#options .old').val();
329 var password1 = $('#options .new1').val();
330 var password2 = $('#options .new2').val();
332 if ((password1 == password2) && (password0 == getPassword())) {
333 // We show the waiting image
337 var iq = new JSJaCIQ();
339 iq.setTo(getServer());
342 var iqQuery = iq.setQuery(NS_REGISTER);
344 iqQuery.appendChild(iq.buildNode('username', {'xmlns': NS_REGISTER}, con.username));
345 iqQuery.appendChild(iq.buildNode('password', {'xmlns': NS_REGISTER}, password1));
347 con.send(iq, handlePwdChange);
349 logThis('Password change sent.', 3);
353 $('.sub-ask-pass input').each(function() {
354 var select = $(this);
357 $(document).oneTime(10, function() {
358 select.addClass('please-complete').focus();
361 select.removeClass('please-complete');
364 if(password0 != getPassword())
365 $(document).oneTime(10, function() {
366 $('#options .old').addClass('please-complete').focus();
368 if(password1 != password2)
369 $(document).oneTime(10, function() {
370 $('#options .new1, #options .new2').addClass('please-complete').focus();
377 // Handles the account deletion request
378 function handleAccDeletion(iq) {
379 // Remove the general wait item
383 if(!handleErrorReply(iq)) {
389 logThis('Account deleted.', 3);
393 logThis('Account not deleted.', 2);
396 // Purge the user's microblog items
397 function purgeMyMicroblog() {
398 /* REF: http://xmpp.org/extensions/xep-0060.html#owner-purge */
400 var password = $('#options .check-empty').val();
402 if(password == getPassword()) {
403 // Send the IQ to remove the item (and get eventual error callback)
404 var iq = new JSJaCIQ();
407 var pubsub = iq.appendNode('pubsub', {'xmlns': NS_PUBSUB_OWNER});
408 pubsub.appendChild(iq.buildNode('purge', {'node': NS_URN_MBLOG, 'xmlns': NS_PUBSUB_OWNER}));
410 con.send(iq, handleMicroblogPurge);
413 $('#options .sub-ask').hide();
415 logThis('Microblog purge sent.', 3);
419 var selector = $('#options .check-empty');
421 if(password != getPassword())
422 $(document).oneTime(10, function() {
423 selector.addClass('please-complete').focus();
426 selector.removeClass('please-complete');
432 // Handles the microblog purge
433 function handleMicroblogPurge(iq) {
435 if(!handleErrorReply(iq)) {
436 // Remove the microblog items
437 $('.one-update.update_' + hex_md5(getXID())).remove();
439 logThis('Microblog purged.', 3);
443 logThis('Microblog not purged.', 2);
446 // Deletes the user's account
447 function deleteMyAccount() {
448 /* REF: http://xmpp.org/extensions/xep-0077.html#usecases-cancel */
450 var password = $('#options .check-password').val();
452 if(password == getPassword()) {
453 // We show the waiting image
457 var iq = new JSJaCIQ();
460 var iqQuery = iq.setQuery(NS_REGISTER);
461 iqQuery.appendChild(iq.buildNode('remove', {'xmlns': NS_REGISTER}));
463 con.send(iq, handleAccDeletion);
465 logThis('Delete account sent.', 3);
469 var selector = $('#options .check-password');
471 if(password != getPassword())
472 $(document).oneTime(10, function() {
473 selector.addClass('please-complete').focus();
476 selector.removeClass('please-complete');
482 // Loads the user options
483 function loadOptions() {
484 // Process the good stuffs, depending of the server features
485 var enabled_archives_pref = enabledArchives('pref');
486 var enabled_pubsub = enabledPubSub();
487 var enabled_pep = enabledPEP();
488 var sWait = $('#options .content');
490 // Show the waiting items if necessary
491 if(enabled_archives_pref || (enabled_pep && enabled_pubsub)) {
492 $('#options .wait').show();
493 $('#options .finish:first').addClass('disabled');
496 // We get the archiving configuration
497 if(enabled_archives_pref) {
498 sWait.addClass('archives');
502 // We get the microblog configuration
503 if(enabled_pubsub && enabled_pep) {
504 sWait.addClass('microblog');
505 getConfigMicroblog();
508 // We show the "privacy" form if something is visible into it
509 if(enabled_archives_pref || enabled_pep)
510 $('#options fieldset.privacy').show();
512 // We get the values of the forms for the sounds
513 if(getDB('options', 'sounds') == '0')
514 $('#sounds').attr('checked', false);
516 $('#sounds').attr('checked', true);
518 // We get the values of the forms for the geolocation
519 if(getDB('options', 'geolocation') == '1')
520 $('#geolocation').attr('checked', true);
522 $('#geolocation').attr('checked', false);
524 // We get the values of the forms for the roster show all
525 if(getDB('options', 'roster-showall') == '1')
526 $('#showall').attr('checked', true);
528 $('#showall').attr('checked', false);
530 // We get the values of the forms for the integratemedias
531 if(getDB('options', 'integratemedias') == '0')
532 $('#integratemedias').attr('checked', false);
534 $('#integratemedias').attr('checked', true);
538 function launchOptions() {
540 $('#options .tab a').click(function() {
542 if($(this).hasClass('tab-active'))
545 // Switch to the good tab
546 var key = parseInt($(this).attr('data-key'));
548 return switchOptions(key);
551 $('#options .linked').click(function() {
552 $('#options .sub-ask').hide();
555 $('#options .xmpp-links').click(function() {
561 $('#options .empty-channel').click(function() {
562 var selector = '#options .sub-ask-empty';
566 $(document).oneTime(10, function() {
567 $(selector + ' input').focus();
573 $('#options .change-password').click(function() {
574 var selector = '#options .sub-ask-pass';
578 $(document).oneTime(10, function() {
579 $(selector + ' input:first').focus();
585 $('#options .delete-account').click(function() {
586 var selector = '#options .sub-ask-delete';
590 $(document).oneTime(10, function() {
591 $(selector + ' input').focus();
597 $('#options .sub-ask-pass .sub-ask-bottom').click(function() {
598 return sendNewPassword();
601 $('#options .sub-ask-empty .sub-ask-bottom').click(function() {
602 return purgeMyMicroblog();
605 $('#options .sub-ask-delete .sub-ask-bottom').click(function() {
606 return deleteMyAccount();
609 $('#options .sub-ask-close').click(function() {
610 $('#options .sub-ask').hide();
615 $('#options .bottom .finish').click(function() {
616 if($(this).is('.save') && !$(this).hasClass('disabled'))
617 return saveOptions();
618 if($(this).is('.cancel'))
619 return closeOptions();
625 $('#options .sub-ask input').keyup(function(e) {
626 if(e.keyCode == 13) {
628 if($(this).is('.purge-microblog'))
629 return purgeMyMicroblog();
632 else if($(this).is('.password-change'))
633 return sendNewPassword();
636 else if($(this).is('.delete-account'))
637 return deleteMyAccount();