From: Darren Date: Thu, 13 Sep 2012 18:55:15 +0000 (+0100) Subject: Messagebar implemented; Gateway-reconnect X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f8ce99b4c9b9ba41c02a16edf23e6f760425f277;p=KiwiIRC.git Messagebar implemented; Gateway-reconnect --- diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index 2f23856..0739de6 100644 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -7,6 +7,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { /** Instance of kiwi.model.PanelList */ this.panels = null; + /** kiwi.view.Application */ + this.view; + + /** kiwi.view.StatusMessage */ + this.message; + /* Address for the kiwi server */ this.kiwi_server = null; @@ -89,6 +95,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { this.topicbar = new kiwi.view.TopicBar({el: $('#topic')[0]}); + this.message = new kiwi.view.StatusMessage({el: $('#status_message')[0]}); + this.panels.server.view.show(); @@ -120,6 +128,25 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { }); + (function () { + var gw_stat = 0; + + gw.on('disconnect', function (event) { + that.message.text('You have been disconnected. Attempting to reconnect..'); + gw_stat = 1; + }); + gw.on('reconnecting', function (event) { + that.message.text('You have been disconnected. Attempting to reconnect again in ' + (event.delay/1000) + ' seconds..'); + }); + gw.on('connect', function (event) { + if (gw_stat !== 1) return; + + that.message.text('It\'s OK, you\'re connected again :)', {timeout: 5000}); + gw_stat = 0; + }); + })(); + + gw.on('onjoin', function (event) { var c, members, user; c = that.panels.getByName(event.channel); diff --git a/client_backbone/dev/model_gateway.js b/client_backbone/dev/model_gateway.js index d19147c..98335a7 100644 --- a/client_backbone/dev/model_gateway.js +++ b/client_backbone/dev/model_gateway.js @@ -92,6 +92,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('connect', function () { this.emit('irc connect', that.get('nick'), host, port, ssl, password, callback); + that.trigger('connect', {}); console.log("kiwi.gateway.socket.on('connect')"); }); @@ -102,7 +103,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('message', this.parse); this.socket.on('disconnect', function () { - this.emit("disconnect", {}); + that.trigger("disconnect", {}); console.log("kiwi.gateway.socket.on('disconnect')"); }); @@ -112,7 +113,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('reconnecting', function (reconnectionDelay, reconnectionAttempts) { console.log("kiwi.gateway.socket.on('reconnecting')"); - this.emit("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts}); + that.trigger("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts}); }); this.socket.on('reconnect_failed', function () { diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 1e7d301..a363d1d 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -589,8 +589,50 @@ kiwi.view.ControlBox = Backbone.View.extend({ +kiwi.view.StatusMessage = Backbone.View.extend({ + /* Timer for hiding the message */ + tmr: null, + + initialize: function () { + this.$el.hide(); + }, + + text: function (text, opt) { + // Defaults + opt = opt || {}; + opt.type = opt.type || ''; + + this.$el.text(text).attr('class', opt.type); + this.$el.slideDown(kiwi.app.view.doLayout); + + if (opt.timeout) this.doTimeout(opt.timeout); + }, + + html: function (html, opt) { + // Defaults + opt = opt || {}; + opt.type = opt.type || ''; + + this.$el.html(text).attr('class', opt.type); + this.$el.slideDown(kiwi.app.view.doLayout); + + if (opt.timeout) this.doTimeout(opt.timeout); + }, + + hide: function () { + this.$el.slideUp(kiwi.app.view.doLayout); + }, + + doTimeout: function (length) { + if (this.tmr) clearTimeout(this.tmr); + var that = this; + this.tmr = setTimeout(function () { that.hide(); }, length); + } +}); + + + -// This *may* be needed in future kiwi.view.Application = Backbone.View.extend({ initialize: function () { $(window).resize(this.doLayout); diff --git a/client_backbone/index.html b/client_backbone/index.html index 547ad30..e2fc0b5 100644 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -16,6 +16,8 @@
+ +
diff --git a/client_backbone/style.css b/client_backbone/style.css index 76acb74..e21288a 100644 --- a/client_backbone/style.css +++ b/client_backbone/style.css @@ -72,6 +72,14 @@ body { #toolbar .panellist li img.icon { left:5px; top:2px; height:auto; width:auto; } +#status_message { + background: #FEEFB3; color: #9F6000; + border-bottom: 1px solid; + padding: 0.9em; + text-align: center; font-size:1.1em; +} +#status_message.err { color:#D8000C; background:#FFBABA; } + .panel_container { overflow-y:scroll; height:100%; }