comparison mod_admin_web/admin_web/www_files/js/main.js @ 319:ba2e78661ea8

mod_admin_web: Make module global. Host to administrate is now chooseable
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 21 Jan 2011 04:10:40 +0100
parents 4f78f5020aa9
children 54d4445cc5c6
comparison
equal deleted inserted replaced
318:84caab2bc02c 319:ba2e78661ea8
1 var BOSH_SERVICE = '/http-bind/'; 1 var BOSH_SERVICE = '/http-bind/';
2 var show_log = true; 2 var show_log = false;
3 3
4 Strophe.addNamespace('C2SSTREAM', 'http://prosody.im/streams/c2s'); 4 Strophe.addNamespace('C2SSTREAM', 'http://prosody.im/streams/c2s');
5 Strophe.addNamespace('S2SSTREAM', 'http://prosody.im/streams/s2s'); 5 Strophe.addNamespace('S2SSTREAM', 'http://prosody.im/streams/s2s');
6 Strophe.addNamespace('ADMINSUB', 'http://prosody.im/adminsub'); 6 Strophe.addNamespace('ADMINSUB', 'http://prosody.im/adminsub');
7 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps'); 7 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
8 8
9 var localJID = null; 9 var localJID = null;
10 var connection = null; 10 var connection = null;
11 11
12 var adminsubHost = '%ADMINSUBHOST%'; 12 var adminsubHost = null;
13 13
14 function log(msg) { 14 function log(msg) {
15 var entry = $('<div></div>').append(document.createTextNode(msg)); 15 var entry = $('<div></div>').append(document.createTextNode(msg));
16 $('#log').append(entry); 16 $('#log').append(entry);
17 } 17 }
103 if (connection) { 103 if (connection) {
104 connection.disconnect(); 104 connection.disconnect();
105 } 105 }
106 } else if (status == Strophe.Status.CONNECTED) { 106 } else if (status == Strophe.Status.CONNECTED) {
107 log('Strophe is connected.'); 107 log('Strophe is connected.');
108 showDisconnect(); 108 connection.sendIQ($iq({to: connection.domain, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
109 connection.addHandler(_cbAdminSub, Strophe.NS.ADMINSUB + '#event', 'message'); 109 .c('adminfor'), function(e) {
110 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB}) 110 var items;
111 .c('subscribe', {node: Strophe.NS.C2SSTREAM})); 111 items = e.getElementsByTagName('item');
112 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB}) 112 if (items.length == 0) {
113 .c('subscribe', {node: Strophe.NS.S2SSTREAM})); 113 alert("You are not an administrator");
114 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB}) 114 connection.disconnect();
115 .c('items', {node: Strophe.NS.S2SSTREAM}), _cbNewS2S); 115 return false;
116 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB}) 116 }
117 .c('items', {node: Strophe.NS.C2SSTREAM}), _cbNewC2S); 117 for (i = 0; i < items.length; i++) {
118 Adhoc.checkFeatures('#adhoc', connection.domain); 118 $('#host').append('<option>' + $(items[i]).text() + '</option>');
119 }
120 showDisconnect();
121 adminsubHost = $(items[0]).text();
122 Adhoc.checkFeatures('#adhoc', adminsubHost);
123 connection.addHandler(_cbAdminSub, Strophe.NS.ADMINSUB + '#event', 'message');
124 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
125 .c('subscribe', {node: Strophe.NS.C2SSTREAM}));
126 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
127 .c('subscribe', {node: Strophe.NS.S2SSTREAM}));
128 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
129 .c('items', {node: Strophe.NS.S2SSTREAM}), _cbNewS2S);
130 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
131 .c('items', {node: Strophe.NS.C2SSTREAM}), _cbNewC2S);
132 });
119 } 133 }
120 } 134 }
121 135
122 function showConnect() { 136 function showConnect() {
123 var jid = $('#jid'); 137 var jid = $('#jid');
126 140
127 button.value = 'connect'; 141 button.value = 'connect';
128 pass.show(); 142 pass.show();
129 jid.show(); 143 jid.show();
130 $('#menu').hide(); 144 $('#menu').hide();
131 $('#adhoc').hide(); 145 $('#main').hide();
132 $('#s2sList').hide();
133 $('#c2sList').hide();
134 $('#cred label').show(); 146 $('#cred label').show();
135 $('#cred br').show(); 147 $('#cred br').show();
136 $('#s2sin').empty(); 148 $('#s2sin').empty();
137 $('#s2sout').empty(); 149 $('#s2sout').empty();
138 $('#c2s').empty(); 150 $('#c2s').empty();
151 $('#host').empty();
139 } 152 }
140 153
141 function showDisconnect() { 154 function showDisconnect() {
142 var jid = $('#jid'); 155 var jid = $('#jid');
143 var pass = $('#pass'); 156 var pass = $('#pass');
145 158
146 button.value = 'disconnect'; 159 button.value = 'disconnect';
147 pass.hide(); 160 pass.hide();
148 jid.hide(); 161 jid.hide();
149 $('#menu').show(); 162 $('#menu').show();
163 $('#main').show();
150 $('#adhoc').show(); 164 $('#adhoc').show();
165 $('#s2sList').hide();
166 $('#c2sList').hide();
151 $('#cred label').hide(); 167 $('#cred label').hide();
152 $('#cred br').hide(); 168 $('#cred br').hide();
153 } 169 }
154 170
155 $(document).ready(function () { 171 $(document).ready(function () {
170 var pass = $('#pass'); 186 var pass = $('#pass');
171 localJID = jid.get(0).value; 187 localJID = jid.get(0).value;
172 188
173 if (button.value == 'connect') { 189 if (button.value == 'connect') {
174 $('#log').empty(); 190 $('#log').empty();
175 connection.connect(localJID, 191 connection.connect(localJID, pass.get(0).value, onConnect);
176 pass.get(0).value,
177 onConnect);
178 } else { 192 } else {
179 connection.disconnect(); 193 connection.disconnect();
180 } 194 }
181 event.preventDefault(); 195 event.preventDefault();
182 }); 196 });
183 197
184 $('#adhocMenu').click(function (event) { 198 $('#adhocMenu').click(function (event) {
185 $('#s2sList').slideUp(); 199 $('#s2sList').slideUp();
186 $('#c2sList').slideUp(); 200 $('#c2sList').slideUp();
187 $('#adhoc').slideDown(); 201 $('#adhoc').slideDown();
188 event.preventDefault(); 202 event.preventDefault();
189 }); 203 });
190 204
191 $('#serverMenu').click(function (event) { 205 $('#serverMenu').click(function (event) {
192 $('#adhoc').slideUp(); 206 $('#adhoc').slideUp();
193 $('#c2sList').slideUp(); 207 $('#c2sList').slideUp();
194 $('#s2sList').slideDown(); 208 $('#s2sList').slideDown();
195 event.preventDefault(); 209 event.preventDefault();
196 }); 210 });
197 211
198 $('#clientMenu').click(function (event) { 212 $('#clientMenu').click(function (event) {
199 $('#adhoc').slideUp(); 213 $('#adhoc').slideUp();
200 $('#s2sList').slideUp(); 214 $('#s2sList').slideUp();
201 $('#c2sList').slideDown(); 215 $('#c2sList').slideDown();
202 event.preventDefault(); 216 event.preventDefault();
203 }); 217 });
204 218
219 $('#host').bind('change', function (event) {
220 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
221 .c('unsubscribe', {node: Strophe.NS.C2SSTREAM}));
222 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
223 .c('unsubscribe', {node: Strophe.NS.S2SSTREAM}));
224 adminsubHost = $(this).val();
225 Adhoc.checkFeatures('#adhoc', adminsubHost);
226 $('#s2sin').empty();
227 $('#s2sout').empty();
228 $('#c2s').empty();
229 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
230 .c('subscribe', {node: Strophe.NS.C2SSTREAM}));
231 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
232 .c('subscribe', {node: Strophe.NS.S2SSTREAM}));
233 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
234 .c('items', {node: Strophe.NS.S2SSTREAM}), _cbNewS2S);
235 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
236 .c('items', {node: Strophe.NS.C2SSTREAM}), _cbNewC2S);
237 });
205 }); 238 });
206 239
207 window.onunload = window.onbeforeunload = function() { 240 window.onunload = window.onbeforeunload = function() {
208 if (connection) { 241 if (connection) {
209 connection.disconnect(); 242 connection.disconnect();