Only register each Sone once!
[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                         setTimeout(function() {
7                                 getStatus(soneId);
8                         }, 5000);
9                 });
10         }
11
12         function updateStatus(soneId, status, modified, lastUpdated) {
13                 $("#sone .sone#" + soneId).
14                         toggleClass("unknown", status == "unknown").
15                         toggleClass("idle", status == "idle").
16                         toggleClass("inserting", status == "inserting").
17                         toggleClass("downloading", status == "downloading").
18                         toggleClass("modified", modified);
19                 $("#sone .sone#" + soneId + " .last-update span.time").text(lastUpdated);
20         }
21
22         registeredSones = {};
23
24         $(document).ready(function() {
25                 $("#sone .sone").each(function() {
26                         soneId = $(this).attr("id");
27                         if (registeredSones[soneId]) {
28                                 return;
29                         }
30                         registeredSones[soneId] = true;
31                         (function(soneId) {
32                                 setTimeout(function() {
33                                         getStatus(soneId);
34                                 }, 5000);
35                         })(soneId);
36                 });
37         });
38 </script>
39
40 <div id="<% sone.id|html>" class="sone <% sone.status|html><%if sone.modified> modified<%/if>">
41         <div class="unknown-marker" title="<%= View.Sone.Status.Unknown|l10n|html>">?</div>
42         <div class="modified-marker" title="<%= View.Sone.Status.Modified|l10n|html>">!</div>
43         <div class="download-marker" title="<%= View.Sone.Status.Downloading|l10n|html>">⬊</div>
44         <div class="insert-marker" title="<%= View.Sone.Status.Inserting|l10n|html>">⬈</div>
45         <div class="idle-marker" title="<%= View.Sone.Status.Idle|l10n|html>">✔</div>
46         <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>
47         <div class="profile-link"><a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a></div>
48         <div class="short-request-uri"><% sone.requestUri|substring start=4 length=43|html></div>
49         <%ifnull ! currentSone>
50                 <%if ! sone.current>
51                         <%if sone.friend>
52                                 <form class="unfollow" action="unfollowSone.html" method="post">
53                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
54                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
55                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
56                                         <button type="submit"><%= View.Sone.Button.UnfollowSone|l10n|html></button>
57                                 </form>
58                         <%else>
59                                 <form class="follow" action="followSone.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.FollowSone|l10n|html></button>
64                                 </form>
65                         <%/if>
66                         <%if sone.blocked>
67                                 <form class="unblock" action="unblockSone.html" method="post">
68                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
69                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
70                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
71                                         <button type="submit"><%= View.Sone.Button.UnblockSone|l10n|html></button>
72                                 </form>
73                         <%else>
74                                 <form class="block" action="blockSone.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.BlockSone|l10n|html></button>
79                                 </form>
80                         <%/if>
81                 <%/if>
82         <%/if>
83         <div class="spacer">&nbsp;</div>
84 </div>