Commit 71f4cdb9 authored by JC Brand's avatar JC Brand

Initial work towards decoupling contact adding

New conf variable in converse.js to indicate how contacts are added (either via
XHR or directly).
parent 76676dc3
...@@ -234,7 +234,7 @@ a.subscribe-to-user { ...@@ -234,7 +234,7 @@ a.subscribe-to-user {
font-weight: bold; font-weight: bold;
} }
dl.add-xmpp-contact { dl.add-converse-contact {
margin: 0 0 0 0.5em; margin: 0 0 0 0.5em;
padding-top: 3px; padding-top: 3px;
z-index: 21; z-index: 21;
...@@ -246,7 +246,7 @@ dt#xmpp-contact-search { ...@@ -246,7 +246,7 @@ dt#xmpp-contact-search {
} }
.fancy-dropdown a.choose-xmpp-status, .fancy-dropdown a.choose-xmpp-status,
.fancy-dropdown a.add-xmpp-contact { .fancy-dropdown a.toggle-xmpp-contact-form {
text-shadow: 0 1px 0 rgba(250, 250, 250, 1); text-shadow: 0 1px 0 rgba(250, 250, 250, 1);
padding-left: 1.5em; padding-left: 1.5em;
width: 140px; width: 140px;
...@@ -283,7 +283,7 @@ form.search-xmpp-contact { ...@@ -283,7 +283,7 @@ form.search-xmpp-contact {
} }
form.search-xmpp-contact input { form.search-xmpp-contact input {
width: 9em; width: 8em;
} }
.oc-chat-head { .oc-chat-head {
...@@ -596,20 +596,14 @@ form.sendXMPPMessage { ...@@ -596,20 +596,14 @@ form.sendXMPPMessage {
height: 54px; height: 54px;
} }
form#set-custom-xmpp-status { #set-custom-xmpp-status {
float: left; float: left;
padding: 0;
background: none;
} }
#set-custom-xmpp-status button { #set-custom-xmpp-status button {
padding: 1px 2px 1px 1px; padding: 1px 2px 1px 1px;
} }
input.custom-xmpp-status {
width: 138px;
}
/* status dropdown styles */ /* status dropdown styles */
dl.dropdown { dl.dropdown {
margin-right: 0.5em; margin-right: 0.5em;
...@@ -622,6 +616,10 @@ div.xmpp-status { ...@@ -622,6 +616,10 @@ div.xmpp-status {
padding: 3px; padding: 3px;
} }
input.custom-xmpp-status {
height: 18px;
}
.fancy-dropdown { .fancy-dropdown {
border:1px solid #ddd; border:1px solid #ddd;
height: 22px; height: 22px;
......
...@@ -573,9 +573,10 @@ ...@@ -573,9 +573,10 @@
className: 'oc-chat-content', className: 'oc-chat-content',
id: 'users', id: 'users',
events: { events: {
'click a.add-xmpp-contact': 'toggleContactForm', 'click a.toggle-xmpp-contact-form': 'toggleContactForm',
'submit form.add-xmpp-contact': 'addContactFromForm',
'submit form.search-xmpp-contact': 'searchContacts', 'submit form.search-xmpp-contact': 'searchContacts',
'click a.subscribe-to-user': 'subscribeToContact' 'click a.subscribe-to-user': 'addContactFromList'
}, },
tab_template: _.template('<li><a class="s current" href="#users">Contacts</a></li>'), tab_template: _.template('<li><a class="s current" href="#users">Contacts</a></li>'),
...@@ -590,23 +591,38 @@ ...@@ -590,23 +591,38 @@
'</select>'+ '</select>'+
'</span>'+ '</span>'+
'</form>'+ '</form>'+
'<dl class="add-xmpp-contact dropdown">' + '<dl class="add-converse-contact dropdown">' +
'<dt id="xmpp-contact-search" class="fancy-dropdown">' + '<dt id="xmpp-contact-search" class="fancy-dropdown">' +
'<a class="add-xmpp-contact" href="#" title="Click to search for new users to add as chat contacts">Add a contact</a>' + '<a class="toggle-xmpp-contact-form" href="#" title="Click to add new chat contacts">Add a contact</a>' +
'</dt>' + '</dt>' +
'<dd class="search-xmpp" style="display:none"><ul>' + '<dd class="search-xmpp" style="display:none"><ul>' +
'</ul></dd>' +
'</dl>'
),
add_contact_template: _.template(
'<form class="add-xmpp-contact">' +
'<input type="text" name="identifier" class="username" placeholder="Contact name"/>' +
'<button type="submit">Add</button>' +
'</form>'),
search_contact_template: _.template(
'<form class="search-xmpp-contact">' + '<form class="search-xmpp-contact">' +
'<input type="text" name="identifier" class="username" placeholder="Contact name"/>' + '<input type="text" name="identifier" class="username" placeholder="Contact name"/>' +
'<button type="submit">Search</button>' + '<button type="submit">Search</button>' +
'<ul id="found-users"></ul>' + '<ul id="found-users"></ul>' +
'</form>' + '</form>'),
'</ul></dd>' +
'</dl>'
),
render: function () { render: function () {
var markup;
this.$parent.find('#controlbox-tabs').append(this.tab_template()); this.$parent.find('#controlbox-tabs').append(this.tab_template());
this.$parent.find('#controlbox-panes').append(this.$el.html(this.template())); this.$parent.find('#controlbox-panes').append(this.$el.html(this.template()));
if (xmppchat.xhr_user_search) {
markup = this.search_contact_template();
} else {
markup = this.add_contact_template();
}
this.$el.find('#xmpp-contact-search').siblings('.search-xmpp').append(markup);
return this; return this;
}, },
...@@ -636,16 +652,26 @@ ...@@ -636,16 +652,26 @@
}); });
}, },
subscribeToContact: function (ev) { addContactFromForm: function (ev) {
ev.preventDefault();
this.addContact($(ev.target).find('input').val());
$('.search-xmpp').hide();
},
addContactFromList: function (ev) {
ev.preventDefault(); ev.preventDefault();
var $target = $(ev.target), var $target = $(ev.target),
jid = $target.attr('data-recipient'), jid = $target.attr('data-recipient'),
name = $target.text(); name = $target.text();
this.addContact(jid, name);
$target.parent().remove();
$('.search-xmpp').hide();
},
addContact: function (jid, name) {
xmppchat.connection.roster.add(jid, name, [], function (iq) { xmppchat.connection.roster.add(jid, name, [], function (iq) {
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname);
}); });
$target.parent().remove();
$('.search-xmpp').hide();
} }
}); });
...@@ -1910,11 +1936,12 @@ ...@@ -1910,11 +1936,12 @@
$('.conn-feedback').text(message); $('.conn-feedback').text(message);
} }
xmppchat.initialize = function () { xmppchat.initialize = function (data) {
var chatdata = $('div#collective-xmpp-chat-data'); this.prebind = data.attr('prebind');
this.fullname = chatdata.attr('fullname'); this.fullname = data.attr('fullname');
this.prebind = chatdata.attr('prebind'); this.xhr_user_search = data.attr('xhr_user_search');
this.auto_subscribe = chatdata.attr('auto_subscribe') === "True" || false; this.auto_subscribe = data.attr('auto_subscribe') === "True" || false;
this.chatboxes = new this.ChatBoxes(); this.chatboxes = new this.ChatBoxes();
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes}); this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
$('a.toggle-online-users').bind( $('a.toggle-online-users').bind(
...@@ -1978,7 +2005,9 @@ ...@@ -1978,7 +2005,9 @@
// Event handlers // Event handlers
// -------------- // --------------
$(document).ready($.proxy(function () { $(document).ready($.proxy(function () {
this.initialize(); // TODO: This code is Plone specific and needs to be factored out
var data = $('div#collective-xmpp-chat-data');
this.initialize(data);
$(document).bind('jarnxmpp.connecting', $.proxy(function (ev, conn) { $(document).bind('jarnxmpp.connecting', $.proxy(function (ev, conn) {
this.giveFeedback('Connecting to chat...'); this.giveFeedback('Connecting to chat...');
}, this)); }, this));
......
...@@ -400,8 +400,20 @@ ...@@ -400,8 +400,20 @@
}, xmppchat)); }, xmppchat));
}, xmppchat)); }, xmppchat));
describe("A Chatbox", $.proxy(function () { describe("The 'Add Contact' widget", $.proxy(function () {
it("opens up an add form when you click on it", $.proxy(function () {
var panel = this.chatboxesview.views.controlbox.contactspanel;
spyOn(panel, 'toggleContactForm').andCallThrough();
panel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
panel.$el.find('a.toggle-xmpp-contact-form').click();
expect(panel.toggleContactForm).toHaveBeenCalled();
// XXX: Awaiting more tests, close it again for now...
panel.$el.find('a.toggle-xmpp-contact-form').click();
}, xmppchat));
}, xmppchat));
describe("A Chatbox", $.proxy(function () {
it("is created when you click on a roster item", $.proxy(function () { it("is created when you click on a roster item", $.proxy(function () {
var i, $el, click, jid, view; var i, $el, click, jid, view;
// showControlBox was called earlier, so the controlbox is // showControlBox was called earlier, so the controlbox is
...@@ -585,10 +597,8 @@ ...@@ -585,10 +597,8 @@
}, xmppchat)); }, xmppchat));
}, xmppchat)); }, xmppchat));
}, xmppchat)); }, xmppchat));
}, xmppchat)); }, xmppchat));
}, xmppchat)); }, xmppchat));
})); }));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment