Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add status update refresh timer

  • Loading branch information...
commit be75ea169bea0984c654625a21aed6468543de9a 1 parent c4f3949
@sosedoff sosedoff authored
View
4 app/assets/javascripts/application.js
@@ -7,3 +7,7 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+
+$(document).ready(function() {
+ StatusTimer.start();
+});
View
26 app/assets/javascripts/status_timer.js
@@ -0,0 +1,26 @@
+var StatusTimer = new function() {
+ this.element_id = "refresh_timer";
+ this.refresh_timer = 60;
+ this.current_timer = 0;
+
+ /* Start timer execution */
+ this.start = function() {
+ this.current_timer = this.refresh_timer;
+ this.refresh();
+ }
+
+ /* Refresh timer count and view */
+ this.refresh = function() {
+ if (this.current_timer <= 0) {
+ window.location.reload();
+ return;
+ }
+
+ this.current_timer--;
+ $("#" + this.element_id).text(this.current_timer);
+
+ setTimeout(function() {
+ StatusTimer.refresh();
+ }, 1000);
+ }
+};
View
4 app/views/status/show.html.erb
@@ -4,6 +4,10 @@
</h1>
</div>
+<div class="refresh-timer">
+ This page will automatically refresh in <span id="refresh_timer">0</span> seconds
+</div>
+
<div id="container">
<div id="pings">
<table>
Please sign in to comment.
Something went wrong with that request. Please try again.