]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/welcome.js
Merge pull request #48 from Leberwurscht/master
[friendica-addons.git] / jappixmini / jappix / js / welcome.js
1 /*
2
3 Jappix - An open social platform
4 These are the welcome tool functions for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 16/01/12
11
12 */
13
14 // Opens the welcome tools
15 function openWelcome() {        
16         // Share message
17         var share_msg = printf(_e("Using Jappix, an open social platform. I am %s!"), getXID());
18         
19         // Popup HTML content
20         var html = 
21         '<div class="top">' + _e("Welcome!") + '</div>' + 
22         
23         '<div class="tab">' + 
24                 '<a href="#" class="tab-active" data-step="1">' + _e("Options") + '</a>' + 
25                 '<a href="#" class="tab-missing" data-step="2">' + _e("Friends") + '</a>' + 
26                 '<a href="#" class="tab-missing" data-step="3">' + _e("Share") + '</a>' + 
27         '</div>' + 
28         
29         '<div class="content">' + 
30                 '<div class="lap-active one-lap welcome1">' + 
31                         '<div class="infos">' + 
32                                 '<p class="infos-title">' + _e("Welcome on Jappix, your own social cloud!") + '</p>' + 
33                                 '<p>' + _e("Before you start using it, you will have to change some settings, search for friends and complete your profile.") + '</p>' + 
34                         '</div>' + 
35                         
36                         '<a href="#" class="box enabled" title="' + _e("Click to disable") + '">' + 
37                                 '<span class="option">' + _e("Sounds") + '</span>' + 
38                                 '<span class="description">' + _e("Enable notification sounds") + '</span>' + 
39                                 '<span class="image sound talk-images"></span>' + 
40                                 '<span class="tick talk-images"></span>' + 
41                         '</a>' + 
42                         
43                         '<a href="#" class="box enabled pep-hidable" title="' + _e("Click to disable") + '">' + 
44                                 '<span class="option">' + _e("Geolocation") + '</span>' + 
45                                 '<span class="description">' + _e("Share your position on the globe") + '</span>' + 
46                                 '<span class="image geolocation talk-images"></span>' + 
47                                 '<span class="tick talk-images"></span>' + 
48                         '</a>' + 
49                         
50                         '<a href="#" class="box xmpplinks-hidable" title="' + _e("Click to enable") + '">' + 
51                                 '<span class="option">' + _e("XMPP links") + '</span>' + 
52                                 '<span class="description">' + _e("Open XMPP links with Jappix") + '</span>' + 
53                                 '<span class="image xmpp talk-images"></span>' + 
54                                 '<span class="tick talk-images"></span>' + 
55                         '</a>' + 
56                         
57                         '<a href="#" class="box enabled archives-hidable pref" title="' + _e("Click to enable") + '">' + 
58                                 '<span class="option">' + _e("Message archiving") + '</span>' + 
59                                 '<span class="description">' + _e("Store a history of your chats") + '</span>' + 
60                                 '<span class="image archives talk-images"></span>' + 
61                                 '<span class="tick talk-images"></span>' + 
62                         '</a>' + 
63                         
64                         '<a href="#" class="box" title="' + _e("Click to enable") + '">' + 
65                                 '<span class="option">' + _e("Offline friends") + '</span>' + 
66                                 '<span class="description">' + _e("Don\'t hide offline friends") + '</span>' + 
67                                 '<span class="image offline talk-images"></span>' + 
68                                 '<span class="tick talk-images"></span>' + 
69                         '</a>' + 
70                 '</div>' + 
71                 
72                 '<div class="one-lap welcome2">' + 
73                         '<div class="infos">' + 
74                                 '<p class="infos-title">' + _e("Friends") + '</p>' + 
75                                 '<p>' + _e("Use this tool to find your friends on the server you are using right now, or add them later.") + '</p>' + 
76                         '</div>' + 
77                         
78                         '<div class="results welcome-results"></div>' + 
79                 '</div>' + 
80                 
81                 '<div class="one-lap welcome3">' + 
82                         '<div class="infos">' + 
83                                 '<p class="infos-title">' + _e("Share") + '</p>' + 
84                                 '<p>' + _e("Great work! Now, you can share Jappix with your friends!") + '</p>' + 
85                                 '<p>' + _e("When you will press the save button, the profile editor will be opened. Happy socializing!") + '</p>' + 
86                         '</div>' + 
87                         
88                         '<a class="box share first" href="http://www.facebook.com/sharer/sharer.php?u=' + encodeQuotes(generateURL(JAPPIX_LOCATION)) + '" target="_blank">' + 
89                                 '<span class="logo facebook welcome-images"></span>' + 
90                                 '<span class="name">Facebook</span>' + 
91                                 '<span class="description">' + printf(_e("Share Jappix on %s"), 'Facebook') + '</span>' + 
92                                 '<span class="go talk-images"></span>' + 
93                         '</a>' + 
94                         
95                         '<a class="box share" href="http://twitter.com/intent/tweet?text=' + encodeQuotes(share_msg) + '&amp;url=' + encodeQuotes(generateURL(JAPPIX_LOCATION)) + '" target="_blank">' + 
96                                 '<span class="logo twitter welcome-images"></span>' + 
97                                 '<span class="name">Twitter</span>' + 
98                                 '<span class="description">' + printf(_e("Share Jappix on %s"), 'Twitter') + '</span>' + 
99                                 '<span class="go talk-images"></span>' + 
100                         '</a>' + 
101                         
102                         '<a class="box share" href="http://www.google.com/buzz/post?message=' + encodeQuotes(share_msg) + '&amp;url=' + encodeQuotes(generateURL(JAPPIX_LOCATION)) + '" target="_blank">' + 
103                                 '<span class="logo buzz welcome-images"></span>' + 
104                                 '<span class="name">Google Buzz</span>' + 
105                                 '<span class="description">' + printf(_e("Share Jappix on %s"), 'Google Buzz') + '</span>' + 
106                                 '<span class="go talk-images"></span>' + 
107                         '</a>' + 
108                         
109                         '<a class="box share" href="http://identi.ca/index.php?action=newnotice&amp;status_textarea=' + encodeQuotes(share_msg) + ' ' + encodeQuotes(generateURL(JAPPIX_LOCATION)) + '" target="_blank">' + 
110                                 '<span class="logo identica welcome-images"></span>' + 
111                                 '<span class="name">Identi.ca</span>' + 
112                                 '<span class="description">' + printf(_e("Share Jappix on %s"), 'Identi.ca') + '</span>' + 
113                                 '<span class="go talk-images"></span>' + 
114                         '</a>' + 
115                 '</div>' + 
116         '</div>' + 
117         
118         '<div class="bottom">' + 
119                 '<div class="wait wait-medium"></div>' + 
120                 
121                 '<a href="#" class="finish next">' + _e("Next") + ' ยป</a>' + 
122                 '<a href="#" class="finish save">' + _e("Save") + '</a>' + 
123         '</div>';
124         
125         // Create the popup
126         createPopup('welcome', html);
127         
128         // Apply the features
129         applyFeatures('welcome');
130         
131         // Associate the events
132         launchWelcome();
133         
134         logThis('Welcome assistant opened.');
135 }
136
137 // Closes the welcome tools
138 function closeWelcome() {
139         // Destroy the popup
140         destroyPopup('welcome');
141         
142         return false;
143 }
144
145 // Switches the welcome tabs
146 function switchWelcome(id) {
147         // Path to
148         var welcome = '#welcome ';
149         var content = welcome + '.content .';
150         var tab = welcome + '.tab ';
151         var wait = $(welcome + '.wait');
152         
153         $(content + 'one-lap').hide();
154         $(content + 'welcome' + id).show();
155         $(tab + 'a').removeClass('tab-active');
156         $(tab + 'a[data-step=' + id + ']').addClass('tab-active').removeClass('tab-missing');
157         
158         // Update the "save" button if all is okay
159         if(!exists(tab + '.tab-missing')) {
160                 var finish = welcome + '.finish.';
161                 $(finish + 'save').show();
162                 $(finish + 'next').hide();
163         }
164         
165         // If this is ID 2: vJUD search
166         if(id == 2) {
167                 wait.show();
168                 dataForm(HOST_VJUD, 'search', '', '', 'welcome');
169         }
170         
171         else
172                 wait.hide();
173         
174         return false;
175 }
176
177 // Sends the welcome options
178 function sendWelcome(array) {
179         // Sends the options
180         var iq = new JSJaCIQ();
181         iq.setType('set');
182         
183         var query = iq.setQuery(NS_PRIVATE);
184         var storage = query.appendChild(iq.buildNode('storage', {'xmlns': NS_OPTIONS}));
185         
186         // Value array
187         var tags = new Array('sounds', 'geolocation', '', '', 'roster-showall');
188         
189         // Build the XML with the array
190         for(i in array) {
191                 var value = array[i];
192                 var tag = tags[i];
193                 
194                 if((i != 2) && (i != 3) && tag && value) {
195                         storage.appendChild(iq.buildNode('option', {'type': tag, 'xmlns': NS_OPTIONS}, value));
196                         setDB('options', tag, value);
197                 }
198         }
199         
200         con.send(iq);
201         
202         // If geolocation is enabled
203         if(array[1] == '1')
204                 geolocate();
205 }
206
207 // Saves the welcome options
208 var END_WELCOME = false;
209
210 function saveWelcome() {
211         // Get the new options
212         var array = new Array();
213         
214         $('#welcome a.box').each(function() {
215                 var current = '0';
216                 
217                 if($(this).hasClass('enabled'))
218                         current = '1';
219                 
220                 array.push(current);
221         });
222         
223         // If XMPP links is enabled
224         if(array[2] == '1')
225                 xmppLinksHandler();
226         
227         // If offline buddies showing is enabled
228         if(array[4] == '1')
229                 showAllBuddies('welcome');
230         
231         // If archiving is supported by the server
232         if(enabledArchives('pref')) {
233                 var aEnabled = false;
234                 
235                 // If archiving is enabled
236                 if(array[3] == '1')
237                         aEnabled = true;
238                 
239                 // Send the archives configuration
240                 configArchives(aEnabled);
241         }
242         
243         // Send the new options
244         sendWelcome(array);
245         
246         // Close the welcome tool
247         closeWelcome();
248         
249         // Open the profile editor
250         openVCard();
251         
252         END_WELCOME = true;
253         
254         return false;
255 }
256
257 // Goes to the next welcome step
258 function nextWelcome() {
259         // Check the next step to go to
260         var next = 1;
261         var missing = '#welcome .tab a.tab-missing';
262         
263         if(exists(missing))
264                 next = parseInt($(missing + ':first').attr('data-step'));
265         
266         // Switch to the next step
267         switchWelcome(next);
268         
269         return false;
270 }
271
272 // Plugin launcher
273 function launchWelcome() {
274         // Click events
275         $('#welcome .tab a').click(function() {
276                 // Switch to the good tab
277                 var key = parseInt($(this).attr('data-step'));
278                 
279                 return switchWelcome(key);
280         });
281         
282         $('#welcome a.box:not(.share)').click(function() {
283                 if($(this).hasClass('enabled'))
284                         $(this).removeClass('enabled').attr('title', _e("Click to enable"));
285                 else
286                         $(this).addClass('enabled').attr('title', _e("Click to disable"));
287                 
288                 return false;
289         });
290         
291         $('#welcome .bottom .finish').click(function() {
292                 if($(this).is('.next'))
293                         return nextWelcome();
294                 if($(this).is('.save'))
295                         return saveWelcome();
296                 
297                 return false;
298         });
299 }