Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set affiliation now works, UI kind of broken though.

  • Loading branch information...
commit 6092043480d6f14ad092eca296e29711899a3472 1 parent 8bb6049
Johan Berggren authored
Showing with 66 additions and 31 deletions.
  1. +13 −3 src/css/pubsubbox.css
  2. +6 −0 src/index.html
  3. +47 −28 src/js/pubsubbox.js
View
16 src/css/pubsubbox.css
@@ -24,11 +24,11 @@
width: 130px;
height: 50px;
background-color: whiteSmoke;
- background-color: #f6f6f6;
+ background-color: #f1f1f1;
margin-bottom: 10px;
padding: 5px;
min-height: 20px;
- border: 1px solid #EEE;
+ border: 1px solid #e3e3e3;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
@@ -44,4 +44,14 @@
div.scroll {
height: 150px;
overflow: auto;
-}
+}
+
+.center {
+ margin-left: auto;
+ margin-right: auto;
+ width:100px;
+}
+
+.vcenter {
+ margin-top: 30%;
+}
View
6 src/index.html
@@ -140,6 +140,12 @@ <h1 class="left" id="fullname"></h1><span class="label success right hidden" id=
</div>
</div>
+<div id="spinner" class="hide center vcenter">
+ &nbsp;&nbsp;&nbsp;&nbsp;<img src="img/spinner.gif" />
+ <br>
+ connecting
+</div>
+
</div>
View
75 src/js/pubsubbox.js
@@ -32,7 +32,8 @@ var XMPP = {
*/
connection: null,
my_jid: null,
-
+ PUBSUBSERVICE: 'pubsub.example.com',
+
nodes: {},
log: function(msg) {
@@ -59,8 +60,10 @@ var XMPP = {
var splitName = name.split(" ");
var name1 = splitName[0] || '';
var name2 = splitName[1] || '';
- $('#roster').append('<div class="drag well2 left" style="margin-left:10px;"><span class="right" style="margin-top:7px">' + name1 + '<br>' + name2 + '</span><span class="' + id + '-canvas"' + '</span></div>');
- var vCardIQ = $iq({to: jid, type: 'get'}).c('vCard', {xmlns: 'vcard-temp'});
+ //$('#roster').append('<div class="drag well2 left" style="margin-left:10px;"><span class="right" style="margin-top:7px">' + name1 + '<br>' + name2 + '</span><span class="' + id + '-canvas"' + '</span></div>');
+ $('#roster').append('<div class="drag well2 left" style="margin-left:10px;"><span class="right" style="margin-top:7px">' + jid + '</span><span class="' + id + '-canvas"' + '</span></div>');
+ var vCardIQ = $iq({to: jid, type: 'get'})
+ .c('vCard', {xmlns: 'vcard-temp'});
XMPP.connection.sendIQ(vCardIQ, XMPP.on_vcard, XMPP.on_vcard_error);
});
},
@@ -108,26 +111,21 @@ var XMPP = {
return;
},
- on_pubsub_item: function(iq) {
- $(iq).find('item').each(function() {
- if ($(this).attr('node') != "/home") {
- $('#pubsub').append('<div class="well2 drop left" style="margin-left:5px;"><strong>' + $(this).attr('node') + '</strong><br><br></div>');
- }
- });
- $(".drop").droppable({
- drop: function(event, ui) {
- $("<span class='label notice'>" + ui.draggable.text() + "</span><br>").appendTo(this);
- }
- })
- },
+ add_to_whitelist: function(nodeID, jid) {
+ var iq = $iq({to:XMPP.PUBSUBSERVICE, type:'set'})
+ .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
+ .c('affiliations', {node:nodeID})
+ .c('affiliation', {jid:jid, affiliation:'member' });
+ XMPP.connection.sendIQ(iq, XMPP.on_foo);
+ },
- on_pubsub_item2: function(iq) {
+ on_pubsub_item: function(iq) {
$(iq).find('item').each(function() {
if ($(this).attr('node') != "/home") {
XMPP.nodes[$(this).attr('node')] = $(this).attr('name');
}
});
- var affiliationIQ = $iq({to: 'pubsub.red.local', type: 'get'})
+ var affiliationIQ = $iq({to: XMPP.PUBSUBSERVICE, type: 'get'})
.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
.c('affiliations');
XMPP.connection.sendIQ(affiliationIQ, XMPP.on_affiliation, XMPP.on_error);
@@ -137,19 +135,30 @@ var XMPP = {
$(iq).find('affiliation').each(function() {
if ($(this).attr('affiliation') === "owner") {
if (XMPP.nodes[$(this).attr('node')]) {
- $('#pubsub').append('<div class="well2 drop left" style="margin-left:5px;"><strong>' + XMPP.nodes[$(this).attr('node')] + '</strong><br><br></div>');
+ $('#pubsub').append('<div class="well2 drop left" id="' + $(this).attr('node') + '"style="margin-left:5px;"><strong>' + XMPP.nodes[$(this).attr('node')] + '</strong><br><br></div>');
+ $(".drop").droppable({
+ drop: function(event, ui) {
+ $("<span class='label notice'>" + ui.draggable.text() + "</span><br>").appendTo(this);
+ var nodeID = $(this).attr('id');
+ XMPP.add_to_whitelist(nodeID, ui.draggable.text());
+ // ADD jid to whitelist
+ }
+ })
}
}
});
},
-
on_error: function(iq) {
alert("error");
},
on_create_node: function(iq) {
+ },
+
+ on_foo: function(iq) {
}
+
};
$(document).bind('connect', function(ev, data) {
@@ -159,6 +168,10 @@ $(document).bind('connect', function(ev, data) {
console.log(body);
};
+ conn.xmlOutput = function (body) {
+ console.log(body);
+ };
+
XMPP.my_jid = data.jid;
conn.connect(data.jid, data.password, function(status) {
if (status === Strophe.Status.CONNECTED) {
@@ -171,20 +184,20 @@ $(document).bind('connect', function(ev, data) {
});
$(document).bind('connected', function () {
+ $('#spinner').hide();
$('#main-screen').toggle("fast");
$('#label-online').toggle("fast");
var rosterIQ = $iq({type: 'get'})
.c('query', {xmlns: 'jabber:iq:roster'});
- var pubSubIQ = $iq({to: 'pubsub.red.local', type: 'get'})
+ var pubSubIQ = $iq({to: XMPP.PUBSUBSERVICE, type: 'get'})
.c('query', {xmlns: 'http://jabber.org/protocol/disco#items'});
- var affiliationIQ = $iq({to: 'pubsub.red.local', type: 'get'})
+ var affiliationIQ = $iq({to: XMPP.PUBSUBSERVICE, type: 'get'})
.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
.c('affiliations');
var vCardIQ = $iq({type: 'get'})
.c('query', {xmlns: 'vcard-temp'});
XMPP.connection.sendIQ(rosterIQ, XMPP.on_roster);
- XMPP.connection.sendIQ(pubSubIQ, XMPP.on_pubsub_item2, XMPP.on_error);
- //XMPP.connection.sendIQ(affiliationIQ, XMPP.on_affiliation, XMPP.on_error);
+ XMPP.connection.sendIQ(pubSubIQ, XMPP.on_pubsub_item, XMPP.on_error);
XMPP.connection.sendIQ(vCardIQ, XMPP.on_my_vcard, XMPP.on_error);
});
@@ -199,7 +212,7 @@ $(document).bind('drop', function(event, ui) {
});
$(document).bind('create_node_with_config', function(event, data) {
- var iq = $iq({to:'jbn@red.local', type:'set'})
+ var iq = $iq({to:XMPP.PUBSUBSERVICE, type:'set'})
.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
.c('create')
.up()
@@ -213,11 +226,17 @@ $(document).bind('create_node_with_config', function(event, data) {
.up().up()
.c('field', {"var": 'pubsub#title'})
.c('value').t(data.node);
+ $("#pubsub").prepend('<div class="well2 drop left" style="margin-left:5px;"><strong>' + data.node + '</strong><br><br></div>')
+ $(".drop").droppable({
+ drop: function(event, ui) {
+ $("<span class='label notice'>" + ui.draggable.text() + "</span><br>").appendTo(this);
+ }
+ })
XMPP.connection.sendIQ(iq, XMPP.on_create_node);
-})
+});
$(document).bind('create_node', function(event, data) {
- var iq = $iq({to:'pubsub.red.local', type:'set'});
+ var iq = $iq({to:XMPP.PUBSUBSERVICE, type:'set'});
iq.c('pubsub', {xmlns:'http://jabber.org/protocol/pubsub'}).c('create', {node:data.node});
$("#pubsub").prepend('<div class="well2 drop left" style="margin-left:5px;"><strong>' + data.node + '</strong><br><br></div>')
XMPP.connection.sendIQ(iq, XMPP.on_create_node);
@@ -226,7 +245,6 @@ $(document).bind('create_node', function(event, data) {
$("<span class='label notice'>" + ui.draggable.text() + "</span><br>").appendTo(this);
}
})
-
})
$(document).ready(function() {
@@ -239,7 +257,8 @@ $(document).ready(function() {
jid: $('#jid').val().toLowerCase(),
password: $('#password').val()
});
- $('#login-screen').fadeOut();
+ $('#login-screen').hide();
+ $('#spinner').show();
});
$('#create-node-button').click(function () {
Please sign in to comment.
Something went wrong with that request. Please try again.