summaryrefslogtreecommitdiffstats
path: root/logfiles-tail-html.lsp
blob: 7f412a39a27a5d0adce777ed1a14f07444e74896 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<% local form, viewlibrary, page_info, session = ... %>
<% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %>

<script type="text/javascript">
        if (typeof jQuery == 'undefined') {
                document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
	}
</script>
				
<script type="text/javascript">
	var currentoffset = -1024
	var ID
	function Update(){
		$.ajaxSetup({cache:false});
		$.getJSON(
			'<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>',
			{filename:'<% io.write(html.html_escape(form.value.filename.value)) if form.value.grep.value ~= "" then io.write("',grep:'"..html.html_escape(form.value.grep.value)) end %>', offset:currentoffset, viewtype:'json'},
			function(data) {
				if (currentoffset != data.value.filesize.value){

					/* Before updating content, determine where we're scrolled to.  If we're within
					   25 pixels of the bottom, we'll stick to the bottom. */
					var content = $("#filecontent").get(0);
					var currentHeight = 0;
					var scrollTop = content.scrollTop;
					if (content.scrollHeight > 0)
						currentHeight = content.scrollHeight;
					else
						if (content.offsetHeight > 0)
							currentHeight = content.offsetHeight;
					if (currentHeight - scrollTop - ((content.style.pixelHeight) ? content.style.pixelHeight : content.offsetHeight) < 25)
						scrollTop = currentHeight;

					$("#filecontent").val($("#filecontent").val() + data.value.filecontent.value);

					/* Now, set the scroll. */
					if (scrollTop < currentHeight)
						content.scrollTop = scrollTop;
					else
						content.scrollTop = content.scrollHeight;

					currentoffset = data.value.filesize.value;
					$("DT:contains('File size')").next().text(currentoffset);
				};
			}
		);
		ID=window.setTimeout("Update();", 1000);
	}
	function handleerror(event, request, settings){
		$(this).append("Error requesting page " + settings.url + "<br/>Perhaps the session has timed out.");
		$("#Stop").click();
	}; 
	$(function(){
		$("#errtxt").ajaxError(handleerror);
		$("#Start").attr("disabled","disabled");
	   	<% if not form.value.filename.errtxt then %>
	   	Update();
		<% else %>
		$("#Stop").attr("disabled","disabled");
		<% end %>
	});
</script>

<% 
htmlviewfunctions.displayheader(form, page_info)
htmlviewfunctions.displayitem(form.value.filename)
htmlviewfunctions.displayitem(form.value.filesize)
if form.value.grep.value ~= "" then
	htmlviewfunctions.displayitem(form.value.grep)
end
%>
<textarea id="filecontent">
</textarea>
<p class="error" id="errtxt"></p>
<div class='item'><p class='left'>Start / Stop tailing file</p>
<div class='right'>
<input type="button" id="Start" value="Start" onClick='$("#errtxt").empty(); Update(); $("#Start").attr("disabled","disabled");$("#Stop").removeAttr("disabled");'>
<input type="button" id="Stop" value="Stop" onClick='window.clearTimeout(ID); $("#Stop").attr("disabled","disabled");$("#Start").removeAttr("disabled");'>
</div></div><!-- end .item -->