Skip to content

Commit

Permalink
Add 'spinner' when loading data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Atzen committed Feb 18, 2011
1 parent 4310161 commit ef618bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<%= link_to 'Sort by name', nil, :onclick => 'viewModel.sortByName(); return false;' %> |
<%= link_to 'Sort by email', nil, :onclick => 'viewModel.sortByEmail(); return false;' %>

<span data-bind="visible: loading()"><em>Loading</em></span>

<table>
<thead>
<tr>
Expand Down Expand Up @@ -71,7 +73,8 @@
var viewModel = {
users: ko.observableArray(users),
userFilters: ko.observableArray([]),
time: ko.observable(new Date())
time: ko.observable(new Date()),
loading: ko.observable(false)
};

viewModel.sortByName = function() {
Expand Down Expand Up @@ -118,6 +121,7 @@
};

function loadUsers() {
viewModel.loading(true);
$.getJSON('/users.json', function(data) {
var userIds = viewModel.userIds();
var users = $.grep(data, function(elem) {
Expand All @@ -126,6 +130,7 @@
$.each(users, function(index, user) {
viewModel.users.push(user);
});
viewModel.loading(false);
});
};

Expand Down

0 comments on commit ef618bb

Please sign in to comment.