Skip to content

Commit

Permalink
Merge pull request #91 from dzautner/live-update-static-box
Browse files Browse the repository at this point in the history
Added live update to static info box
  • Loading branch information
penberg committed Sep 24, 2014
2 parents e908ea1 + 00c589b commit 9cb7802
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion osv/Boxes/StaticInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ OSv.Boxes = OSv.Boxes || {};
OSv.Boxes.StaticInfo = (function() {

function StaticInfo() {

this.interval = setInterval(this.refresh.bind(this), OSv.Settings.DataFetchingRate)
}

StaticInfo.prototype = new OSv.Boxes.StaticBox();

StaticInfo.prototype.refresh = function () {
var container = $(this.selector);
this.fetchData().then(function (data) {
data.forEach(function (obj) {
container.find("[data-key='"+obj.key+"']").html(obj.value);
})
});
};

StaticInfo.prototype.clear = function() {
clearInterval(this.interval);
$(this.selector).remove();
};

StaticInfo.prototype.getData = function() {
var OS = OSv.API.OS;
return $.when(
Expand Down
2 changes: 1 addition & 1 deletion osv/templates/boxes/StaticBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{#each this }}
<tr>
<td>{{key}} </td>
<td>{{value}} </td>
<td data-key="{{key}}">{{value}} </td>
</tr>
{{/each}}
</table>
Expand Down

0 comments on commit 9cb7802

Please sign in to comment.