aboutsummaryrefslogtreecommitdiff
path: root/templates/longpolling.julius
blob: 35205bd04d9e49d163078a2d1659dfa11d042808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

// Uses long-polling to update a div with id=#{ident}
// The gethtml route should return a new div, with the same id.
//
// Maximum update frequency is controlled by #{startdelay}
// and #{delay}, both in milliseconds.

connfails=0;

connfailed=
  '<div id="modal" class="modal fade">' +
  '  <div class="modal-header">' +
  '    <h3>git-annex has shut down</h3>' +
  '  </div>' +
  '  <div class="modal-body">' +
  '    You can now close this browser window.' +
  '  </div>' +
  '</div>' ;

(function( $ ) {

$.LongPoll#{ident} = (function() {
	return {
		send : function() {           
			$.ajax({
				'url': '@{gethtml}',
				'dataType': 'html',
				'success': function(data, status, jqxhr) {
					$('##{ident}').replaceWith(data);
					setTimeout($.LongPoll#{ident}.send, #{show delay});
					numerrs=0;
				},
				'error': function(jqxhr, msg, e) {
					connfails=connfails+1;
					if (connfails > 3) {
						// blocked by many browsers
						window.close();
						$('#modal').replaceWith(connfailed);
						$('#modal').modal('show');
					}
					else {
						setTimeout($.LongPoll#{ident}.send, #{show delay});
					}
				},
			});
		}
	}
}());

$(document).bind('ready.app', function() {
	setTimeout($.LongPoll#{ident}.send, #{show startdelay});
});

})( jQuery );