Messagebar implemented; Gateway-reconnect
authorDarren <darren@darrenwhitlen.com>
Thu, 13 Sep 2012 18:55:15 +0000 (19:55 +0100)
committerDarren <darren@darrenwhitlen.com>
Thu, 13 Sep 2012 18:55:15 +0000 (19:55 +0100)
client_backbone/dev/model_application.js
client_backbone/dev/model_gateway.js
client_backbone/dev/view.js
client_backbone/index.html
client_backbone/style.css

index 2f238562a465983daccd0d7c30a3a18de22d3a9b..0739de6ccd6916fe42becfd5d8b8df8c9dd3a4f3 100644 (file)
@@ -7,6 +7,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
     /** Instance of kiwi.model.PanelList */\r
     this.panels = null;\r
 \r
+    /** kiwi.view.Application */\r
+    this.view;\r
+\r
+    /** kiwi.view.StatusMessage */\r
+    this.message;\r
+\r
     /* Address for the kiwi server */\r
     this.kiwi_server = null;\r
 \r
@@ -89,6 +95,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \r
         this.topicbar = new kiwi.view.TopicBar({el: $('#topic')[0]});\r
 \r
+        this.message = new kiwi.view.StatusMessage({el: $('#status_message')[0]});\r
+\r
         \r
         this.panels.server.view.show();\r
 \r
@@ -120,6 +128,25 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         });\r
 \r
 \r
+        (function () {\r
+            var gw_stat = 0;\r
+\r
+            gw.on('disconnect', function (event) {\r
+                that.message.text('You have been disconnected. Attempting to reconnect..');\r
+                gw_stat = 1;\r
+            });\r
+            gw.on('reconnecting', function (event) {\r
+                that.message.text('You have been disconnected. Attempting to reconnect again in ' + (event.delay/1000) + ' seconds..');\r
+            });\r
+            gw.on('connect', function (event) {\r
+                if (gw_stat !== 1) return;\r
+\r
+                that.message.text('It\'s OK, you\'re connected again :)', {timeout: 5000});\r
+                gw_stat = 0;\r
+            });\r
+        })();\r
+\r
+\r
         gw.on('onjoin', function (event) {\r
             var c, members, user;\r
             c = that.panels.getByName(event.channel);\r
index d19147c3462c6667e9a887c9ea0c2c2be1e28203..98335a7b6102a9b77a692d2421875ae1015d1919 100644 (file)
@@ -92,6 +92,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () {
 \r
         this.socket.on('connect', function () {\r
             this.emit('irc connect', that.get('nick'), host, port, ssl, password, callback);\r
+            that.trigger('connect', {});\r
             console.log("kiwi.gateway.socket.on('connect')");\r
         });\r
 \r
@@ -102,7 +103,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () {
         this.socket.on('message', this.parse);\r
 \r
         this.socket.on('disconnect', function () {\r
-            this.emit("disconnect", {});\r
+            that.trigger("disconnect", {});\r
             console.log("kiwi.gateway.socket.on('disconnect')");\r
         });\r
 \r
@@ -112,7 +113,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () {
 \r
         this.socket.on('reconnecting', function (reconnectionDelay, reconnectionAttempts) {\r
             console.log("kiwi.gateway.socket.on('reconnecting')");\r
-            this.emit("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts});\r
+            that.trigger("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts});\r
         });\r
 \r
         this.socket.on('reconnect_failed', function () {\r
index 1e7d30173142dd572b09627dade06dffcff0ae94..a363d1d3bb7718df88aebc8a39d6f5e88721ce22 100644 (file)
@@ -589,8 +589,50 @@ kiwi.view.ControlBox = Backbone.View.extend({
 \r
 \r
 \r
+kiwi.view.StatusMessage = Backbone.View.extend({\r
+    /* Timer for hiding the message */\r
+    tmr: null,\r
+\r
+    initialize: function () {\r
+        this.$el.hide();\r
+    },\r
+\r
+    text: function (text, opt) {\r
+        // Defaults\r
+        opt = opt || {};\r
+        opt.type = opt.type || '';\r
+\r
+        this.$el.text(text).attr('class', opt.type);\r
+        this.$el.slideDown(kiwi.app.view.doLayout);\r
+\r
+        if (opt.timeout) this.doTimeout(opt.timeout);\r
+    },\r
+\r
+    html: function (html, opt) {\r
+        // Defaults\r
+        opt = opt || {};\r
+        opt.type = opt.type || '';\r
+\r
+        this.$el.html(text).attr('class', opt.type);\r
+        this.$el.slideDown(kiwi.app.view.doLayout);\r
+\r
+        if (opt.timeout) this.doTimeout(opt.timeout);\r
+    },\r
+\r
+    hide: function () {\r
+        this.$el.slideUp(kiwi.app.view.doLayout);\r
+    },\r
+\r
+    doTimeout: function (length) {\r
+        if (this.tmr) clearTimeout(this.tmr);\r
+        var that = this;\r
+        this.tmr = setTimeout(function () { that.hide(); }, length);\r
+    }\r
+});\r
+\r
+\r
+\r
 \r
-// This *may* be needed in future\r
 kiwi.view.Application = Backbone.View.extend({\r
     initialize: function () {\r
         $(window).resize(this.doLayout);\r
index 547ad30a5cfd38df48be33e69e9877c2bf7c515f..e2fc0b51b740950439f0cf57d4b5bc12baca610f 100644 (file)
@@ -16,6 +16,8 @@
             <div id="topic">
                 <input type="text" />
             </div>
+
+            <div id="status_message"></div>
         </div>
 
         <div id="panels">
index 76acb7418f60f348cfaa246f45380343142a4634..e21288a8b279065fad216f665aafc611a7d8306c 100644 (file)
@@ -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%; }