3 Jappix - An open social platform
4 These are the mucadmin JS scripts for Jappix
6 -------------------------------------------------
9 Authors: Vanaryon, Maranda
10 Last revision: 03/03/11
14 // Opens the MUC admin popup
15 function openMucAdmin(xid, aff) {
18 '<div class="top">' + _e("MUC administration") + '</div>' +
20 '<div class="content">' +
21 '<div class="head mucadmin-head">' +
22 '<div class="head-text mucadmin-head-text">' + _e("You administrate this room") + '</div>' +
24 '<div class="mucadmin-head-jid">' + xid + '</div>' +
27 '<div class="mucadmin-forms">' +
28 '<div class="mucadmin-topic">' +
30 '<legend>' + _e("Subject") + '</legend>' +
32 '<label for="topic-text">' + _e("Enter new subject") + '</label>' +
33 '<textarea id="topic-text" name="room-topic" rows="8" cols="60" ></textarea>' +
37 '<div class="mucadmin-conf">' +
39 '<legend>' + _e("Configuration") + '</legend>' +
41 '<div class="results mucadmin-results"></div>' +
45 '<div class="mucadmin-aut">' +
47 '<legend>' + _e("Authorizations") + '</legend>' +
49 '<label>' + _e("Member list") + '</label>' +
50 '<div class="aut-member aut-group">' +
51 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'member\');">' + _e("Add an input") + '</a>' +
54 '<label>' + _e("Owner list") + '</label>' +
55 '<div class="aut-owner aut-group">' +
56 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'owner\');">' + _e("Add an input") + '</a>' +
59 '<label>' + _e("Administrator list") + '</label>' +
60 '<div class="aut-admin aut-group">' +
61 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'admin\');">' + _e("Add an input") + '</a>' +
64 '<label>' + _e("Outcast list") + '</label>' +
65 '<div class="aut-outcast aut-group">' +
66 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'outcast\');">' + _e("Add an input") + '</a>' +
71 '<div class="mucadmin-others">' +
73 '<legend>' + _e("Others") + '</legend>' +
75 '<label>' + _e("Destroy this MUC") + '</label>' +
76 '<a href="#" onclick="return destroyMucAdmin();">' + _e("Yes, let's do it!") + '</a>' +
82 '<div class="bottom">' +
83 '<div class="wait wait-medium"></div>' +
85 '<a href="#" class="finish save">' + _e("Save") + '</a>' +
86 '<a href="#" class="finish cancel">' + _e("Cancel") + '</a>' +
90 '<div class="top">' + _e("MUC administration") + '</div>' +
92 '<div class="content">' +
93 '<div class="head mucadmin-head">' +
94 '<div class="head-text mucadmin-head-text">' + _e("You administrate this room") + '</div>' +
96 '<div class="mucadmin-head-jid">' + xid + '</div>' +
99 '<div class="mucadmin-forms">' +
100 '<div class="mucadmin-aut">' +
102 '<legend>' + _e("Authorizations") + '</legend>' +
104 '<label>' + _e("Member list") + '</label>' +
105 '<div class="aut-member aut-group">' +
106 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'member\');">' + _e("Add an input") + '</a>' +
109 '<label>' + _e("Outcast list") + '</label>' +
110 '<div class="aut-outcast aut-group">' +
111 '<a href="#" class="aut-add" onclick="return addInputMucAdmin(\'\', \'outcast\');">' + _e("Add an input") + '</a>' +
118 '<div class="bottom">' +
119 '<div class="wait wait-medium"></div>' +
121 '<a href="#" class="finish save">' + _e("Save") + '</a>' +
122 '<a href="#" class="finish cancel">' + _e("Cancel") + '</a>' +
127 createPopup('mucadmin', html_full);
129 createPopup('mucadmin', html_partial);
131 // Associate the events
134 // We get the affiliated user's privileges
136 queryMucAdmin(xid, 'member');
137 queryMucAdmin(xid, 'owner');
138 queryMucAdmin(xid, 'admin');
139 queryMucAdmin(xid, 'outcast');
140 // We query the room to edit
141 dataForm(xid, 'muc', '', '', 'mucadmin');
142 } else if(aff == 'admin') {
143 queryMucAdmin(xid, 'member');
144 queryMucAdmin(xid, 'outcast');
148 // Closes the MUC admin popup
149 function closeMucAdmin() {
151 destroyPopup('mucadmin');
156 // Removes a MUC admin input
157 function removeInputMucAdmin(element) {
158 var path = $(element).parent();
160 // We first hide the container of the input
163 // Then, we add a special class to the input
164 path.find('input').addClass('aut-dustbin');
169 // Adds a MUC admin input
170 function addInputMucAdmin(xid, affiliation) {
171 var hash = hex_md5(xid + affiliation);
174 $('#mucadmin .aut-' + affiliation + ' .aut-add').after(
175 '<div class="one-aut ' + hash + '">' +
176 '<input id="aut-' + affiliation + '" name="' + affiliation + '" type="text" class="mucadmin-i" value="' + xid + '" />' +
177 '<a href="#" class="aut-remove">[-]</a>' +
182 $('#mucadmin .' + hash + ' .aut-remove').click(function() {
183 return removeInputMucAdmin(this);
186 // Focus on the input we added
188 $(document).oneTime(10, function() {
189 $('#mucadmin .' + hash + ' input').focus();
195 // Handles the MUC admin form
196 function handleMucAdminAuth(iq) {
197 // We got the authorizations results
198 $(iq.getQuery()).find('item').each(function() {
199 // We parse the received xml
200 var xid = $(this).attr('jid');
201 var affiliation = $(this).attr('affiliation');
203 // We create one input for one XID
204 addInputMucAdmin(xid, affiliation);
207 // Hide the wait icon
208 $('#mucadmin .wait').hide();
210 logThis('MUC admin items received: ' + fullXID(getStanzaFrom(iq)));
213 // Queries the MUC admin form
214 function queryMucAdmin(xid, type) {
215 // Show the wait icon
216 $('#mucadmin .wait').show();
219 var iq = new JSJaCIQ();
224 var iqQuery = iq.setQuery(NS_MUC_ADMIN);
225 iqQuery.appendChild(iq.buildNode('item', {'affiliation': type, 'xmlns': NS_MUC_ADMIN}));
227 con.send(iq, handleMucAdminAuth);
230 // Sends the new chat-room topic
231 function sendMucAdminTopic(xid) {
232 // We get the new topic
233 var topic = $('.mucadmin-topic textarea').val();
235 // We send the new topic if not blank
237 var m = new JSJaCMessage();
239 m.setType('groupchat');
243 logThis('MUC admin topic sent: ' + topic, 3);
247 // Sends the MUC admin auth form
248 function sendMucAdminAuth(xid) {
249 // We define the values array
250 var types = new Array('member', 'owner', 'admin', 'outcast');
253 // We get the current type
254 var tType = types[i];
256 // We loop for all the elements
257 $('.mucadmin-aut .aut-' + tType + ' input').each(function() {
258 // We set the iq headers
259 var iq = new JSJaCIQ();
263 var iqQuery = iq.setQuery(NS_MUC_ADMIN);
265 // We get the needed values
266 var value = $(this).val();
268 // If there's a value
270 var item = iqQuery.appendChild(iq.buildNode('item', {'jid': value, 'xmlns': NS_MUC_ADMIN}));
272 // It the user had removed the XID
273 if($(this).hasClass('aut-dustbin') && value)
274 item.setAttribute('affiliation', 'none');
276 // If the value is not blank and okay
278 item.setAttribute('affiliation', tType);
281 con.send(iq, handleErrorReply);
285 logThis('MUC admin authorizations form sent: ' + xid, 3);
288 // Checks if the MUC room was destroyed
289 function handleDestroyMucAdminIQ(iq) {
290 if(!handleErrorReply(iq)) {
291 // We close the groupchat
292 var room = fullXID(getStanzaFrom(iq));
293 var hash = hex_md5(room);
294 quitThisChat(room, hash, 'groupchat');
296 // We close the muc admin popup
299 // We tell the user that all is okay
302 // We remove the user's favorite
303 if(existDB('favorites', room))
304 removeThisFavorite(room, explodeThis('@', room, 0));
306 logThis('MUC admin destroyed: ' + room, 3);
309 // We hide the wait icon
310 $('#mucadmin .wait').hide();
313 // Destroys a MUC room
314 function destroyMucAdminIQ(xid) {
315 // We ask the server to delete the room
316 var iq = new JSJaCIQ();
320 var iqQuery = iq.setQuery(NS_MUC_OWNER);
321 iqQuery.appendChild(iq.buildNode('destroy', {'xmlns': NS_MUC_OWNER}));
323 con.send(iq, handleDestroyMucAdminIQ);
325 logThis('MUC admin destroy sent: ' + xid, 3);
330 // Performs the MUC room destroy functions
331 function destroyMucAdmin() {
332 // We get the XID of the current room
333 var xid = $('#mucadmin .mucadmin-head-jid').text();
335 // We show the wait icon
336 $('#mucadmin .wait').show();
339 destroyMucAdminIQ(xid);
342 // Sends all the MUC admin stuffs
343 function sendMucAdmin() {
344 // We get the XID of the current room
345 var xid = $('#mucadmin .mucadmin-head-jid').text();
347 // We change the room topic
348 sendMucAdminTopic(xid);
350 // We send the needed queries
351 sendDataForm('x', 'submit', 'submit', $('#mucadmin .mucadmin-results').attr('data-session'), xid, '', '', 'mucadmin');
352 sendMucAdminAuth(xid);
355 // Saves the MUC admin elements
356 function saveMucAdmin() {
357 // We send the new options
360 // And we quit the popup
361 return closeMucAdmin();
365 function launchMucAdmin() {
367 $('#mucadmin .bottom .finish').click(function() {
368 if($(this).is('.cancel'))
369 return closeMucAdmin();
370 if($(this).is('.save'))
371 return saveMucAdmin();