Add functions to lock and unlock a Sone.
[Sone.git] / src / main / resources / templates / include / head.html
1 <div id="sone" class="<%ifnull ! currentSone>online<%else>offline<%/if>">
2
3         <div id="formPassword"><% formPassword|html></div>
4
5         <script src="javascript/jquery-1.4.2.js" language="javascript"></script>
6         <script src="javascript/sone.js" language="javascript"></script>
7
8         <script language="javascript">
9                 /* this initializes the status update input field. */
10                 $(document).ready(function() {
11                         getTranslation("WebInterface.DefaultText.StatusUpdate", function(text) {
12                                 registerInputTextareaSwap("#sone #update-status .status-input", text, "text", false, false);
13                         })
14                 });
15         </script>
16
17         <script language="javascript">
18                 /* these functions are necessary for updating Sone statuses. */
19                 $(document).ready(function() {
20                         $("#sone .sone").each(function() {
21                                 watchSone($(this).find(".id").text(), $(this).hasClass("local"));
22                         });
23                 });
24         </script>
25
26         <script language="javascript">
27                 /* this initializes all reply input fields. */
28                 $(document).ready(function() {
29                         getTranslation("WebInterface.DefaultText.Reply", function(text) {
30                                 registerInputTextareaSwap("#sone input.reply-input", text, "text", false, false);
31                                 addCommentLinks();
32                         })
33                 });
34         </script>
35
36         <script language="javascript">
37                 /* replaces all “post reply!” forms with AJAX. */
38                 $(document).ready(function() {
39                         $("#sone .create-reply button:submit").click(function() {
40                                 $(this.form).submit(function() {
41                                         return false;
42                                 });
43                                 inputField = $(this.form).find(":input:enabled").get(0);
44                                 postId = getPostId($(inputField));
45                                 text = $(inputField).val();
46                                 $(inputField).val("");
47                                 postReply(postId, text, function(success, error, replyId) {
48                                         if (success) {
49                                                 getReply(replyId, function(soneId, soneName, replyTime, replyDisplayTime, text, html) {
50                                                         newReply = $(html).insertBefore("#sone .post#" + postId + " .create-reply");
51                                                         $("#sone .post#" + postId + " .create-reply").addClass("hidden");
52                                                         getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(deleteReplyText) {
53                                                                 enhanceDeleteReplyButton("#sone .post#" + postId + " .reply#" + replyId + " .delete button", replyId, deleteReplyText);
54                                                         });
55                                                         newReply.find(".status-line .like").submit(function() {
56                                                                 likeReply(getReplyId(this));
57                                                                 return false;
58                                                         });
59                                                         newReply.find(".status-line .unlike").submit(function() {
60                                                                 unlikeReply(getReplyId(this));
61                                                                 return false;
62                                                         });
63                                                         addCommentLink(postId, newReply);
64                                                 });
65                                         } else {
66                                                 alert(error);
67                                         }
68                                 });
69                                 return false;
70                         });
71                 });
72         </script>
73
74         <script language="javascript">
75                 /* replace all “delete” buttons with javascript. */
76                 $(document).ready(function() {
77                         getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {
78                                 deletePostText = text;
79                                 getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(text) {
80                                         deleteReplyText = text;
81                                         $("#sone .post").each(function() {
82                                                 postId = $(this).attr("id");
83                                                 enhanceDeletePostButton("#sone .post#" + postId + " > .inner-part > .status-line .delete button", postId, deletePostText);
84                                                 (function(postId) {
85                                                         $("#sone .post#" + postId + " .reply").each(function() {
86                                                                 replyId = $(this).attr("id");
87                                                                 (function(postId, reply, replyId) {
88                                                                         reply.find(".delete button").each(function() {
89                                                                                 enhanceDeleteReplyButton("#sone .post#" + postId + " .reply#" + replyId + " .delete button", replyId, deleteReplyText);
90                                                                         })
91                                                                 })(postId, $(this), replyId);
92                                                         });
93                                                 })(postId);
94                                         });
95                                 });
96                         });
97                 });
98         </script>
99
100         <script language="javascript">
101                 /* hides all replies but the latest two. */
102                 $(document).ready(function() {
103                         getTranslation("WebInterface.ClickToShow.Replies", function(text) {
104                                 $("#sone .post .replies").each(function() {
105                                         allReplies = $(this).find(".reply");
106                                         if (allReplies.length > 2) {
107                                                 newHidden = false;
108                                                 for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
109                                                         $(allReplies[replyIndex]).addClass("hidden");
110                                                         newHidden |= $(allReplies[replyIndex]).hasClass("new");
111                                                 }
112                                                 clickToShowElement = $("<div></div>").addClass("click-to-show");
113                                                 if (newHidden) {
114                                                         clickToShowElement.addClass("new");
115                                                 }
116                                                 (function(clickToShowElement, allReplies, text) {
117                                                         clickToShowElement.text(text);
118                                                         clickToShowElement.click(function() {
119                                                                 allReplies.removeClass("hidden");
120                                                                 clickToShowElement.addClass("hidden");
121                                                         });
122                                                 })(clickToShowElement, allReplies, text);
123                                                 $(allReplies[0]).before(clickToShowElement);
124                                         }
125                                 });
126                         });
127                 });
128         </script>
129
130         <script language="javascript">
131                 /* convert all “follow”, “unfollow”, “lock”, and “unlock” links to something nicer. */
132                 $(document).ready(function() {
133                         $("#sone .follow").submit(function() {
134                                 var followElement = this;
135                                 $.getJSON("ajax/followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
136                                         $(followElement).addClass("hidden");
137                                         $(followElement).parent().find(".unfollow").removeClass("hidden");
138                                 });
139                                 return false;
140                         });
141                         $("#sone .unfollow").submit(function() {
142                                 var unfollowElement = this;
143                                 $.getJSON("ajax/unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
144                                         $(unfollowElement).addClass("hidden");
145                                         $(unfollowElement).parent().find(".follow").removeClass("hidden");
146                                 });
147                                 return false;
148                         });
149                         $("#sone .lock").submit(function() {
150                                 var lockElement = this;
151                                 $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
152                                         $(lockElement).addClass("hidden");
153                                         $(lockElement).parent().find(".unlock").removeClass("hidden");
154                                 });
155                                 return false;
156                         });
157                         $("#sone .unlock").submit(function() {
158                                 var unlockElement = this;
159                                 $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
160                                         $(unlockElement).addClass("hidden");
161                                         $(unlockElement).parent().find(".lock").removeClass("hidden");
162                                 });
163                                 return false;
164                         });
165                 });
166         </script>
167
168         <script language="javascript">
169                 /* convert all “like” buttons to javascript functions. */
170                 $(document).ready(function() {
171                         $("#sone .post > .inner-part > .status-line .like").submit(function() {
172                                 likePost(getPostId(this));
173                                 return false;
174                         });
175                         $("#sone .post > .inner-part > .status-line .unlike").submit(function() {
176                                 unlikePost(getPostId(this));
177                                 return false;
178                         });
179                         $("#sone .post .reply .status-line .like").submit(function() {
180                                 likeReply(getReplyId(this));
181                                 return false;
182                         });
183                         $("#sone .post .reply .status-line .unlike").submit(function() {
184                                 unlikeReply(getReplyId(this));
185                                 return false;
186                         });
187                 });
188         </script>
189
190         <script language="javascript">
191                 /* process all existing notifications, ajaxify dismiss buttons. */
192                 $(document).ready(function() {
193                         $("#sone #notification-area .notification").each(function() {
194                                 ajaxifyNotification($(this));
195                         });
196                 });
197         </script>
198
199         <script language="javascript">
200                 /* activate notification polling. */
201                 $(document).ready(function() {
202                         setTimeout(getNotifications, 5000);
203                 });
204         </script>
205
206         <div id="main">
207
208                 <div id="notification-area">
209
210                         <form id="notification-dismiss-template" class="hidden dismiss" action="dismissNotification.html" method="post">
211                                 <input type="hidden" name="formPassword" value="<% formPassword|html>" />
212                                 <input type="hidden" name="returnPage" value="<% request.uri|html>" />
213                                 <input type="hidden" name="notification" value="" />
214                                 <button type="submit"><%= Notification.Button.Dismiss|l10n|html></button>
215                         </form>
216
217                         <%foreach webInterface.notifications.all notification>
218                                 <div class="notification" id="<% notification.id|html>">
219                                         <%if notification.dismissable>
220                                                 <form class="dismiss" action="dismissNotification.html" method="post">
221                                                         <input type="hidden" name="formPassword" value="<% formPassword|html>" />
222                                                         <input type="hidden" name="returnPage" value="<% request.uri|html>" />
223                                                         <input type="hidden" name="notification" value="<% notification.id|html>" />
224                                                         <button type="submit"><%= Notification.Button.Dismiss|l10n|html></button>
225                                                 </form>
226                                         <%/if>
227                                         <% notification>
228                                 </div>
229                         <%/foreach>
230                 </div>
231
232                 <div id="profile" class="<%ifnull currentSone>offline<%else>online<%/if>">
233                         <a class="picture" href="index.html">
234                                 <%ifnull !currentSone>
235                                         <img src="/WoT/GetIdenticon?identity=<% currentSone.id|html>&amp;width=80&amp;height=80" width="80" height="80" alt="Profile Avatar" />
236                                 <%else>
237                                         <img src="images/sone.png" width="80" height="80" alt="Sone is offline" />
238                                 <%/if>
239                         </a>
240                         <%ifnull ! currentSone>
241                                 <div id="home-sone">
242                                         <% currentSone|store key=sone>
243                                         <%include include/viewSone.html>
244                                         <%include include/updateStatus.html>
245                                 </div>
246                         <%/if>
247                 </div>