diff --git a/chat.js b/chat.js
index 83042ecaf..46e749c24 100644
--- a/chat.js
+++ b/chat.js
@@ -143,13 +143,6 @@ var xmppchat = (function (jarnxmpp, $, console) {
return xmppchat.ChatPartners.getTotal();
};
- ob.Presence.sendPresence = function (type) {
- if (type === undefined) {
- type = this.getOwnStatus() || 'online';
- }
- xmppchat.connection.send($pres({'type':type}));
- };
-
ob.Taskbuffer = (function ($) {
// Executes tasks one after another (i.e next task is started only when
// the previous one has been completed).
@@ -568,7 +561,7 @@ xmppchat.RosterClass = (function (stropheRoster, _, $, console) {
},
addResource: function (bare_jid, resource) {
- var item = this.getItem(bare_jid);
+ var item = this.getItem(bare_jid),
resources;
if (item) {
resources = item.get('resources');
@@ -641,7 +634,9 @@ xmppchat.RosterClass = (function (stropheRoster, _, $, console) {
ptype = $(presence).attr('type'),
status = '';
- if (ob.isSelf(bare_jid)) { return true; }
+ if (ob.isSelf(bare_jid)) {
+ return true;
+ }
if (ptype === 'subscribe') {
// FIXME: User wants to subscribe to us. Always approve and
@@ -716,6 +711,81 @@ xmppchat.RosterView= (function (roster, _, $, console) {
return view;
});
+xmppchat.XMPPStatus = Backbone.Model.extend({
+
+ sendPresence: function (type) {
+ if (type === undefined) {
+ type = this.getOwnStatus() || 'online';
+ }
+ xmppchat.connection.send($pres({'type':type}));
+ },
+
+ getOwnStatus: function () {
+ return store.get(xmppchat.connection.bare_jid+'-xmpp-status');
+ },
+
+ setOwnStatus: function (value) {
+ this.sendPresence(value);
+ store.set(xmppchat.connection.bare_jid+'-xmpp-status', value);
+ }
+});
+
+xmppchat.XMPPStatusView = Backbone.View.extend({
+ el: "span#xmpp-status-holder",
+
+ events: {
+ "click #fancy-xmpp-status-select": "toggleOptions",
+ "click .dropdown dd ul li a": "setOwnStatus"
+ },
+
+ toggleOptions: function (ev) {
+ ev.preventDefault();
+ $(ev.target).parent().siblings('dd').find('ul').toggle('fast');
+ },
+
+ setOwnStatus: function (ev) {
+ ev.preventDefault();
+ var $el = $(ev.target).find('span'),
+ value = $el.text();
+ $(this.el).find(".dropdown dt a").html('I am ' + value).attr('class', value);
+ $(this.el).find(".dropdown dd ul").hide();
+ $(this.el).find("#source").val($($el).find("span.value").html());
+ this.model.setOwnStatus(value);
+ },
+
+ choose_template: _.template('
' +
+ '- '+
+ '' +
+ 'I am <%= chat_status %> <%= chat_status %>' +
+ '
' +
+ ''),
+
+ option_template: _.template(
+ '
' +
+ '' +
+ '<%= text %>' +
+ '<%= value %>' +
+ '' +
+ ''),
+
+ initialize: function () {
+ var $select = $(this.el).find('select#select-xmpp-status'),
+ chat_status = this.model.getOwnStatus() || 'offline',
+ options = $('option', $select),
+ that = this;
+
+ $(this.el).html(this.choose_template({'chat_status': chat_status}));
+
+ // iterate through all the