Update the status of the Sone (more or less) immediately and on-the-fly.
[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);
6                         setTimeout(function() {
7                                 getStatus(soneId);
8                         }, 5000);
9                 });
10         }
11
12         function updateStatus(soneId, status, modified) {
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         }
20
21         $(document).ready(function() {
22                 $("#sone .sone").each(function() {
23                         getStatus($(this).attr("id"));
24                 });
25         });
26 </script>
27
28 <div id="<% sone.id|html>" class="sone <% sone.status|html><%if sone.modified> modified<%/if>">
29         <div class="unknown-marker" title="<%= View.Sone.Status.Unknown|l10n|html>">?</div>
30         <div class="modified-marker" title="<%= View.Sone.Status.Modified|l10n|html>">!</div>
31         <div class="download-marker" title="<%= View.Sone.Status.Downloading|l10n|html>">⬊</div>
32         <div class="insert-marker" title="<%= View.Sone.Status.Inserting|l10n|html>">⬈</div>
33         <div class="idle-marker" title="<%= View.Sone.Status.Idle|l10n|html>">✔</div>
34         <div class="last-update"><%= View.Sone.Label.LastUpdate|l10n|html> <% sone.time|date format="MMM d, yyyy, HH:mm:ss"></div>
35         <div class="profile-link"><a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a></div>
36         <div class="short-request-uri"><% sone.requestUri|substring start=4 length=43|html></div>
37         <%ifnull ! currentSone>
38                 <%if ! sone.current>
39                         <%if sone.friend>
40                                 <form class="unfollow" action="unfollowSone.html" method="post">
41                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
42                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
43                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
44                                         <button type="submit"><%= View.Sone.Button.UnfollowSone|l10n|html></button>
45                                 </form>
46                         <%else>
47                                 <form class="follow" action="followSone.html" method="post">
48                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
49                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
50                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
51                                         <button type="submit"><%= View.Sone.Button.FollowSone|l10n|html></button>
52                                 </form>
53                         <%/if>
54                         <%if sone.blocked>
55                                 <form class="unblock" action="unblockSone.html" method="post">
56                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
57                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
58                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
59                                         <button type="submit"><%= View.Sone.Button.UnblockSone|l10n|html></button>
60                                 </form>
61                         <%else>
62                                 <form class="block" action="blockSone.html" method="post">
63                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
64                                         <input type="hidden" name="sone" value="<% sone.id|html>" />
65                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
66                                         <button type="submit"><%= View.Sone.Button.BlockSone|l10n|html></button>
67                                 </form>
68                         <%/if>
69                 <%/if>
70         <%/if>
71         <div class="spacer">&nbsp;</div>
72 </div>