/* Jappix - An open social platform These are the welcome tool functions for Jappix ------------------------------------------------- License: AGPL Author: Valérian Saliou */ // Bundle var Welcome = (function () { /** * Alias of this * @private */ var self = {}; /* Variables */ self.is_done = false; /** * Opens the welcome tools * @public * @return {undefined} */ self.open = function() { try { // Share message var share_msg = Common.printf(Common._e("Using Jappix, an open social platform. I am %s!"), Common.getXID()); // Popup HTML content var html = '
' + Common._e("Welcome!") + '
' + '
' + '' + Common._e("Options") + '' + '' + Common._e("Friends") + '' + '' + Common._e("Share") + '' + '
' + '
' + '
' + '
' + '

' + Common._e("Welcome on Jappix, your own social cloud!") + '

' + '

' + Common._e("Before you start using it, you will have to change some settings, search for friends and complete your profile.") + '

' + '
' + '' + '' + Common._e("Sounds") + '' + '' + Common._e("Enable notification sounds") + '' + '' + '' + '' + '' + '' + Common._e("Geolocation") + '' + '' + Common._e("Share your position on the globe") + '' + '' + '' + '' + '' + '' + Common._e("XMPP links") + '' + '' + Common._e("Open XMPP links with Jappix") + '' + '' + '' + '' + '' + '' + Common._e("Message archiving") + '' + '' + Common._e("Store a history of your chats") + '' + '' + '' + '' + '' + '' + Common._e("Offline friends") + '' + '' + Common._e("Don\'t hide offline friends") + '' + '' + '' + '' + '
' + '
' + '
' + '

' + Common._e("Friends") + '

' + '

' + Common._e("Use this tool to find your friends on the server you are using right now, or add them later.") + '

' + '
' + '
' + '
' + '
' + '
' + '

' + Common._e("Share") + '

' + '

' + Common._e("Good job! Now, you can share Jappix with your friends!") + '

' + '

' + Common._e("When you will press the save button, the profile editor will be opened. Happy socializing!") + '

' + '
' + '' + '' + '' + '' + '
' + '
' + '
' + '
' + '' + '' + Common._e("Save") + '' + '
'; // Create the popup Popup.create('welcome', html); // Unavoidable popup $('#welcome').addClass('unavoidable'); // Apply the features Features.apply('welcome'); // Associate the events self.instance(); Console.log('Welcome assistant opened.'); } catch(e) { Console.error('Welcome.open', e); } }; /** * Closes the welcome tools * @public * @return {boolean} */ self.close = function() { try { // Destroy the popup Popup.destroy('welcome'); } catch(e) { Console.error('Welcome.close', e); } finally { return false; } }; /** * Switches the welcome tabs * @public * @param {string} id * @return {boolean} */ self.switchTab = function(id) { try { // Path to var welcome = '#welcome '; var content = welcome + '.content .'; var tab = welcome + '.tab '; var wait = $(welcome + '.wait'); $(content + 'one-lap').hide(); $(content + 'welcome' + id).show(); $(tab + 'a').removeClass('tab-active'); $(tab + 'a[data-step="' + id + '"]').addClass('tab-active').removeClass('tab-missing'); // Update the "save" button if all is okay if(!Common.exists(tab + '.tab-missing')) { var finish = welcome + '.finish.'; $(finish + 'save').show(); $(finish + 'next').hide(); } // If this is ID 2: vJUD search if(id == 2) { wait.show(); DataForm.go(HOST_VJUD, 'search', '', '', 'welcome'); } else { wait.hide(); } } catch(e) { Console.error('Welcome.switchTab', e); } finally { return false; } }; /** * Sends the welcome options * @public * @param {object} array * @return {undefined} */ self.send = function(array) { try { // Sends the options var iq = new JSJaCIQ(); iq.setType('set'); var query = iq.setQuery(NS_PRIVATE); var storage = query.appendChild(iq.buildNode('storage', {'xmlns': NS_OPTIONS})); // Value array var tags = ['sounds', 'geolocation', '', '', 'roster-showall']; // Build the XML with the array for(var i in array) { var value = array[i]; var tag = tags[i]; if((i != 2) && (i != 3) && tag && value) { storage.appendChild(iq.buildNode('option', {'type': tag, 'xmlns': NS_OPTIONS}, value)); DataStore.setDB(Connection.desktop_hash, 'options', tag, value); } } con.send(iq); // If geolocation is enabled if(array[1] == '1') { PEP.geolocate(); } } catch(e) { Console.error('Welcome.send', e); } }; /** * Saves the welcome options * @public * @return {boolean} */ self.save = function() { try { // Get the new options var array = []; $('#welcome a.box').each(function() { var current = '0'; if($(this).hasClass('enabled')) { current = '1'; } array.push(current); }); // If XMPP links is enabled if(array[2] == '1') { Utils.xmppLinksHandler(); } // If offline buddies showing is enabled if(array[4] == '1') { Interface.showAllBuddies('welcome'); } // If archiving is supported by the server if(Features.enabledMAM()) { // If archiving is enabled if(array[3] == '1') { MAM.setConfig('roster'); } } // Send the new options self.send(array); // Close the welcome tool self.close(); // Open the profile editor vCard.open(); // Unavoidable popup $('#vcard').addClass('unavoidable'); self.is_done = true; } catch(e) { Console.error('Welcome.save', e); } finally { return false; } }; /** * Goes to the next welcome step * @public * @return {boolean} */ self.next = function() { try { // Check the next step to go to var next = 1; var missing = '#welcome .tab a.tab-missing'; if(Common.exists(missing)) { next = parseInt($(missing + ':first').attr('data-step')); } // Switch to the next step self.switchTab(next); } catch(e) { Console.error('Welcome.next', e); } finally { return false; } }; /** * Plugin launcher * @public * @return {undefined} */ self.instance = function() { try { // Click events $('#welcome .tab a').click(function() { var this_sel = $(this); // Switch to the good tab var key = parseInt(this_sel.attr('data-step')); return self.switchTab(key); }); $('#welcome a.box:not(.share)').click(function() { var this_sel = $(this); if(this_sel.hasClass('enabled')) { this_sel.removeClass('enabled').attr('title', Common._e("Click to enable")); } else { this_sel.addClass('enabled').attr('title', Common._e("Click to disable")); } return false; }); $('#welcome .bottom .finish').click(function() { var this_sel = $(this); if(this_sel.is('.next')) { return self.next(); } if(this_sel.is('.save')) { return self.save(); } return false; }); } catch(e) { Console.error('Welcome.instance', e); } }; /** * Return class scope */ return self; })();