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
|
<% local form, viewlibrary, page_info = ... %>
<% require("viewfunctions") %>
<script type="text/javascript" src="/js/jquery-latest.js"></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) %>',
{name:'<% 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},
function(data) {
data.value.filecontent.value = data.value.filecontent.value.split("\n").join("<br>\n");
/* 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").append(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(){
$("#Start").attr("disabled","disabled");
<% if not form.value.filename.errtxt then %>
Update();
<% else %>
$("#Stop").attr("disabled","disabled");
<% end %>
});
</script>
<H1>Tail File</H1>
<DL>
<%
displayitem(form.value.filename)
displayitem(form.value.filesize)
if form.value.grep.value ~= "" then
displayitem(form.value.grep)
end
%>
</DL>
<textarea id="filecontent">
</textarea>
<DL>
<DT>Start / Stop tailing file</DT>
<DD>
<input TYPE="button" ID="Start" VALUE="Start" onClick='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");'>
</DD>
</DL>
|