diff options
| author | ioguix | 2010-05-31 23:06:42 +0000 |
|---|---|---|
| committer | ioguix | 2010-05-31 23:06:42 +0000 |
| commit | 6d2d790391a18067d7a28698facdf94c6e519d07 (patch) | |
| tree | faf636fd27a5e09a440b942e9e372f690c6c4ad4 /js | |
| parent | e3bc0f821fb22049f95d818de6b2c54180b8c507 (diff) | |
Better handling connection error and waiting in locks page behaviour on ajax request
* re-add error message on page
* add a loading icon when a query is running
* cancel ajax request when clicking on stop
* preload image (start icon don't show up on error without it)
Diffstat (limited to 'js')
| -rw-r--r-- | js/locks.js | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/js/locks.js b/js/locks.js index 81310e64..e069f1e9 100644 --- a/js/locks.js +++ b/js/locks.js @@ -1,20 +1,33 @@ $(document).ready(function() { - var timeid = null; + var timeid = query = null; var controlLink = $('#control'); + var errmsg = $('<p class="errmsg">'+Database.errmsg+'</p>') + .insertBefore(controlLink) + .hide(); + var loading = $('<img class="loading" alt="[loading]" src="'+ Database.load_icon +'" />') + .insertAfter(controlLink) + .hide(); function refreshLocksTable() { if (Database.ajax_time_refresh > 0) { - $.ajax({ + loading.show(); + query = $.ajax({ type: 'GET', dataType: 'html', url: 'database.php?action=refresh_locks&' + Database.server, - timeout: Database.ajax_timeout - 100, cache: false, contentType: 'application/x-www-form-urlencoded', success: function(html) { $('#locks_block').html(html); timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh) + }, + error: function() { + controlLink.click(); + errmsg.show(); + }, + complete: function () { + loading.hide(); } }); } @@ -22,17 +35,29 @@ $(document).ready(function() { controlLink.toggle( function() { + $(errmsg).hide(); timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh); controlLink.html('<img src="'+ Database.str_stop.icon +'" alt="" /> ' - + Database.str_stop.text); + + Database.str_stop.text + ' ' + ); }, function() { + $(errmsg).hide(); + $(loading).hide(); window.clearInterval(timeid); + query.abort(); controlLink.html('<img src="'+ Database.str_start.icon +'" alt="" /> ' + Database.str_start.text ); } ); + /* preload images */ + $('#control img').hide() + .attr('src', Database.str_start.icon) + .attr('src', Database.str_stop.icon) + .show(); + + /* start refreshing */ controlLink.click(); }); |
