/* Jappix - An open social platform These are the mucadmin JS scripts for Jappix ------------------------------------------------- License: AGPL Authors: Valérian Saliou, Maranda Last revision: 03/03/11 */ // Opens the MUC admin popup function openMucAdmin(xid, aff) { // Popup HTML content var html_full = '
' + _e("MUC administration") + '
' + '
' + '
' + '
' + _e("You administrate this room") + '
' + '
' + xid + '
' + '
' + '
' + '
' + '
' + '' + _e("Subject") + '' + '' + '' + '
' + '
' + '
' + '
' + '' + _e("Configuration") + '' + '
' + '
' + '
' + '
' + '
' + '' + _e("Authorizations") + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '
' + '
' + '' + _e("Others") + '' + '' + '' + _e("Yes, let's do it!") + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + _e("Save") + '' + '' + _e("Cancel") + '' + '
'; var html_partial = '
' + _e("MUC administration") + '
' + '
' + '
' + '
' + _e("You administrate this room") + '
' + '
' + xid + '
' + '
' + '
' + '
' + '
' + '' + _e("Authorizations") + '' + '' + '' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + _e("Save") + '' + '' + _e("Cancel") + '' + '
'; // Create the popup if(aff == 'owner') createPopup('mucadmin', html_full); if(aff == 'admin') createPopup('mucadmin', html_partial); // Associate the events launchMucAdmin(); // We get the affiliated user's privileges if(aff == 'owner') { queryMucAdmin(xid, 'member'); queryMucAdmin(xid, 'owner'); queryMucAdmin(xid, 'admin'); queryMucAdmin(xid, 'outcast'); // We query the room to edit dataForm(xid, 'muc', '', '', 'mucadmin'); } else if(aff == 'admin') { queryMucAdmin(xid, 'member'); queryMucAdmin(xid, 'outcast'); } } // Closes the MUC admin popup function closeMucAdmin() { // Destroy the popup destroyPopup('mucadmin'); return false; } // Removes a MUC admin input function removeInputMucAdmin(element) { var path = $(element).parent(); // We first hide the container of the input path.hide(); // Then, we add a special class to the input path.find('input').addClass('aut-dustbin'); return false; } // Adds a MUC admin input function addInputMucAdmin(xid, affiliation) { var hash = hex_md5(xid + affiliation); // Add the HTML code $('#mucadmin .aut-' + affiliation + ' .aut-add').after( '
' + '' + '[-]' + '
' ); // Click event $('#mucadmin .' + hash + ' .aut-remove').click(function() { return removeInputMucAdmin(this); }); // Focus on the input we added if(!xid) $(document).oneTime(10, function() { $('#mucadmin .' + hash + ' input').focus(); }); return false; } // Handles the MUC admin form function handleMucAdminAuth(iq) { // We got the authorizations results $(iq.getQuery()).find('item').each(function() { // We parse the received xml var xid = $(this).attr('jid'); var affiliation = $(this).attr('affiliation'); // We create one input for one XID addInputMucAdmin(xid, affiliation); }); // Hide the wait icon $('#mucadmin .wait').hide(); logThis('MUC admin items received: ' + fullXID(getStanzaFrom(iq))); } // Queries the MUC admin form function queryMucAdmin(xid, type) { // Show the wait icon $('#mucadmin .wait').show(); // New IQ var iq = new JSJaCIQ(); iq.setTo(xid); iq.setType('get'); var iqQuery = iq.setQuery(NS_MUC_ADMIN); iqQuery.appendChild(iq.buildNode('item', {'affiliation': type, 'xmlns': NS_MUC_ADMIN})); con.send(iq, handleMucAdminAuth); } // Sends the new chat-room topic function sendMucAdminTopic(xid) { // We get the new topic var topic = $('.mucadmin-topic textarea').val(); // We send the new topic if not blank if(topic) { var m = new JSJaCMessage(); m.setTo(xid); m.setType('groupchat'); m.setSubject(topic); con.send(m); logThis('MUC admin topic sent: ' + topic, 3); } } // Sends the MUC admin auth form function sendMucAdminAuth(xid) { // We define the values array var types = new Array('member', 'owner', 'admin', 'outcast'); for(i in types) { // We get the current type var tType = types[i]; // We loop for all the elements $('.mucadmin-aut .aut-' + tType + ' input').each(function() { // We set the iq headers var iq = new JSJaCIQ(); iq.setTo(xid); iq.setType('set'); var iqQuery = iq.setQuery(NS_MUC_ADMIN); // We get the needed values var value = $(this).val(); // If there's a value if(value) var item = iqQuery.appendChild(iq.buildNode('item', {'jid': value, 'xmlns': NS_MUC_ADMIN})); // It the user had removed the XID if($(this).hasClass('aut-dustbin') && value) item.setAttribute('affiliation', 'none'); // If the value is not blank and okay else if(value) item.setAttribute('affiliation', tType); // We send the iq ! con.send(iq, handleErrorReply); }); } logThis('MUC admin authorizations form sent: ' + xid, 3); } // Checks if the MUC room was destroyed function handleDestroyMucAdminIQ(iq) { if(!handleErrorReply(iq)) { // We close the groupchat var room = fullXID(getStanzaFrom(iq)); var hash = hex_md5(room); quitThisChat(room, hash, 'groupchat'); // We close the muc admin popup closeMucAdmin(); // We tell the user that all is okay openThisInfo(5); // We remove the user's favorite if(existDB('favorites', room)) removeThisFavorite(room, explodeThis('@', room, 0)); logThis('MUC admin destroyed: ' + room, 3); } // We hide the wait icon $('#mucadmin .wait').hide(); } // Destroys a MUC room function destroyMucAdminIQ(xid) { // We ask the server to delete the room var iq = new JSJaCIQ(); iq.setTo(xid); iq.setType('set'); var iqQuery = iq.setQuery(NS_MUC_OWNER); iqQuery.appendChild(iq.buildNode('destroy', {'xmlns': NS_MUC_OWNER})); con.send(iq, handleDestroyMucAdminIQ); logThis('MUC admin destroy sent: ' + xid, 3); return false; } // Performs the MUC room destroy functions function destroyMucAdmin() { // We get the XID of the current room var xid = $('#mucadmin .mucadmin-head-jid').text(); // We show the wait icon $('#mucadmin .wait').show(); // We send the iq destroyMucAdminIQ(xid); } // Sends all the MUC admin stuffs function sendMucAdmin() { // We get the XID of the current room var xid = $('#mucadmin .mucadmin-head-jid').text(); // We change the room topic sendMucAdminTopic(xid); // We send the needed queries sendDataForm('x', 'submit', 'submit', $('#mucadmin .mucadmin-results').attr('data-session'), xid, '', '', 'mucadmin'); sendMucAdminAuth(xid); } // Saves the MUC admin elements function saveMucAdmin() { // We send the new options sendMucAdmin(); // And we quit the popup return closeMucAdmin(); } // Plugin launcher function launchMucAdmin() { // Click events $('#mucadmin .bottom .finish').click(function() { if($(this).is('.cancel')) return closeMucAdmin(); if($(this).is('.save')) return saveMucAdmin(); }); }