Make update interval depend on the age of the Sone.
[Sone.git] / src / main / resources / templates / include / viewSone.html
1 <script language="javascript">
2
3         function getStatus(soneId) {
4                 $.getJSON("ajax/getSoneStatus.ajax", {"sone": soneId}, function(data, textStatus) {
5                         updateStatus(soneId, data.status, data.modified, data.lastUpdated);
6                         /* seconds! */
7                         updateInterval = 60;
8                         if (data.age < 600) {
9                                 updateInterval = 5;
10                         } else if (data.age < 86400) {
11                                 updateInterval = 30;
12                         }
13                         setTimeout(function() {
14                                 getStatus(soneId);
15                         }, updateInterval * 1000);
16                 });
17         }
18
19         function updateStatus(soneId, status, modified, lastUpdated) {
20                 $("#sone .sone#" + soneId).
21                         toggleClass("unknown", status == "unknown").
22                         toggleClass("idle", status == "idle").
23                         toggleClass("inserting", status == "inserting").
24                         toggleClass("downloading", status == "downloading").
25                         toggleClass("modified", modified);
26                 $("#sone .sone#" + soneId + " .last-update span.time").text(lastUpdated);
27         }
28
29         registeredSones = {};
30
31         $(document).ready(function() {
32                 $("#sone .sone").each(function() {
33                         soneId = $(this).attr("id");
34                         if (registeredSones[soneId]) {
35                                 return;
36                         }
37                         registeredSones[soneId] = true;
38                         (function(soneId) {
39                                 setTimeout(function() {
40                                         getStatus(soneId);
41                                 }, 5000);
42                         })(soneId);
43                 });
44         });
45 </script>
46
47 <div id="<% sone.id|html>" class="sone <% sone.status|html><%if sone.modified> modified<%/if>">
48         <div class="unknown-marker" title="<%= View.Sone.Status.Unknown|l10n|html>">?</div>
49         <div class="modified-marker" title="<%= View.Sone.Status.Modified|l10n|html>">!</div>
50         <div class="download-marker" title="<%= View.Sone.Status.Downloading|l10n|html>">⬊</div>
51         <div class="insert-marker" title="<%= View.Sone.Status.Inserting|l10n|html>">⬈</div>
52         <div class="idle-marker" title="<%= View.Sone.Status.Idle|l10n|html>">✔</div>
53         <div class="last-update"><%= View.Sone.Label.LastUpdate|l10n|html> <span class="time"><% sone.time|date format="MMM d, yyyy, HH:mm:ss"></span></div>
54         <div class="profile-link"><a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a></div>
55         <div class="short-request-uri"><% sone.requestUri|substring start=4 length=43|html></div>
56         <%ifnull ! currentSone>
57                 <%if ! sone.current>
58                         <%if sone.friend>
59                                 <form class="unfollow" action="unfollowSone.html" method="post">
60                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
61                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
62                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
63                                         <button type="submit"><%= View.Sone.Button.UnfollowSone|l10n|html></button>
64                                 </form>
65                         <%else>
66                                 <form class="follow" action="followSone.html" method="post">
67                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
68                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
69                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
70                                         <button type="submit"><%= View.Sone.Button.FollowSone|l10n|html></button>
71                                 </form>
72                         <%/if>
73                         <%if sone.blocked>
74                                 <form class="unblock" action="unblockSone.html" method="post">
75                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
76                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
77                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
78                                         <button type="submit"><%= View.Sone.Button.UnblockSone|l10n|html></button>
79                                 </form>
80                         <%else>
81                                 <form class="block" action="blockSone.html" method="post">
82                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
83                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
84                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
85                                         <button type="submit"><%= View.Sone.Button.BlockSone|l10n|html></button>
86                                 </form>
87                         <%/if>
88                 <%/if>
89         <%/if>
90         <div class="spacer">&nbsp;</div>
91 </div>