corrade-http-templates – Diff between revs 44 and 45

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 44 Rev 45
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html lang="en"> 2 <html lang="en">
3   3  
4 <head> 4 <head>
5 <title>Corrade Instant Message Template</title> 5 <title>Corrade Instant Message Template</title>
6 6
7 <meta charset="utf-8"> 7 <meta charset="utf-8">
8 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 8 <meta http-equiv="X-UA-Compatible" content="IE=edge">
9 <meta name="viewport" content="width=device-width, initial-scale=1"> 9 <meta name="viewport" content="width=device-width, initial-scale=1">
10 <meta name="description" content="Group Chat Relay using Corrade"> 10 <meta name="description" content="Group Chat Relay using Corrade">
11 <meta name="author" content="Wizardry and Steamworks"> 11 <meta name="author" content="Wizardry and Steamworks">
12 <link rel="icon" href="favicon.ico"> 12 <link rel="icon" href="favicon.ico">
13   13  
14 <!-- Bootstrap core CSS --> 14 <!-- Bootstrap core CSS -->
15 <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> 15 <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
16 <!-- jQuery UI CSS --> 16 <!-- jQuery UI CSS -->
17 <link href="bower_components/jquery-ui/themes/base/jquery-ui.min.css" rel="stylesheet"> 17 <link href="bower_components/jquery-ui/themes/base/jquery-ui.min.css" rel="stylesheet">
-   18 <!-- Custom Styles -->
-   19 <link rel="stylesheet" href="css/style.css?v=1.3">
18 </head> 20 </head>
19   21  
20 <body> 22 <body>
21 23
22 <!-- Modal --> 24 <!-- Modal -->
23 <div id="dialog" class="modal fade" role="dialog"> 25 <div id="dialog" class="modal fade" role="dialog">
24 <div class="modal-dialog"> 26 <div class="modal-dialog">
25   27  
26 <!-- Modal content--> 28 <!-- Modal content-->
27 <div class="modal-content"> 29 <div class="modal-content">
28 <div class="modal-header"> 30 <div class="modal-header">
29 <button type="button" class="close" data-dismiss="modal">&times;</button> 31 <button type="button" class="close" data-dismiss="modal">&times;</button>
30 <h2 class="modal-title">Enter Agent Name</h2> 32 <h2 class="modal-title">Enter Agent Name</h2>
31 </div> 33 </div>
32 <form role="form" data-toggle="validator" class="form-inline"> 34 <form role="form" data-toggle="validator" class="form-inline">
33 <div class="modal-body"> 35 <div class="modal-body">
34 36
35 <div class="form-group"> 37 <div class="form-group">
36 <div class="input-group"> 38 <div class="input-group">
37 <label for="firstname">First Name</label> 39 <label for="firstname">First Name</label>
38 <input class="form-control" maxlength="8" type="text" id="firstname" placeholder="Corrade" required> 40 <input class="form-control" maxlength="8" type="text" id="firstname" placeholder="Corrade" required>
39 </div> 41 </div>
40 <div class="input-group"> 42 <div class="input-group">
41 <label for="lastname">Last Name</label> 43 <label for="lastname">Last Name</label>
42 <input class="form-control" maxlength="8" type="text" id="lastname" placeholder="Resident" required> 44 <input class="form-control" maxlength="8" type="text" id="lastname" placeholder="Resident" required>
43 </div> 45 </div>
44 </div> 46 </div>
45 47
46 48
47 </div> 49 </div>
48 <div class="modal-footer"> 50 <div class="modal-footer">
49 <button type="button" id="startConversation" class="btn btn-primary btn-lg"> 51 <button type="button" id="startConversation" class="btn btn-primary btn-lg">
50 <span class="glyphicon glyphicon-bullhorn" aria-hidden="true"></span> Start 52 <span class="glyphicon glyphicon-bullhorn" aria-hidden="true"></span> Start
51 </button> 53 </button>
52 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 54 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
53 </div> 55 </div>
54 </form> 56 </form>
55 </div> 57 </div>
56   58  
57 </div> 59 </div>
58 </div> 60 </div>
59   61  
60 <div class="container"> 62 <div class="container">
61 <form role="form" data-toggle="validator" action="javascript:return;"> 63 <form role="form" data-toggle="validator" action="javascript:return;">
62 <div class="form-group row"> 64 <div class="form-group row">
63 <div class="input-group"> 65 <div class="input-group">
64 <span class="input-group-addon"> 66 <span class="input-group-addon">
65 <label for="name">Your Name</label> 67 <label for="name">Your Name</label>
66 </span> 68 </span>
67 <input type="text" maxlength="8" value="Someone" id="name" class="form-control" required> 69 <input type="text" maxlength="8" value="Someone" id="name" class="form-control" required>
68 <span class="input-group-btn"> 70 <span class="input-group-btn">
69 <button type="submit" class="btn btn-default" data-toggle="modal" data-target="#dialog">New Conversation</button> 71 <button type="submit" class="btn btn-default" data-toggle="modal" data-target="#dialog">New Conversation</button>
70 </span> 72 </span>
71 </div> 73 </div>
72 </div> 74 </div>
73 </form> 75 </form>
74 76
75 <!-- This div holds the tabs that will be created. This structure should not be deleted. --> 77 <!-- This div holds the tabs that will be created. This structure should not be deleted. -->
76 <div id="tabs"> 78 <div id="tabs">
77 <ul> 79 <ul>
78   80  
79 </ul> 81 </ul>
80 <div> 82 <div>
81   83  
82 </div> 84 </div>
83 </div> 85 </div>
84 </div> 86 </div>
85 87
86 <!-- Include jQuery --> 88 <!-- Include jQuery -->
87 <script src="bower_components/jquery/dist/jquery.min.js"></script> 89 <script src="bower_components/jquery/dist/jquery.min.js"></script>
88 <!-- Include jQuery UI --> 90 <!-- Include jQuery UI -->
89 <script src="bower_components/jquery-ui/jquery-ui.min.js"></script> 91 <script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
90 <!-- Include Bootstrap --> 92 <!-- Include Bootstrap -->
91 <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> 93 <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
92 <!-- Include Bootstrap Validator --> 94 <!-- Include Bootstrap Validator -->
93 <script src="bower_components/bootstrap-validator/js/validator.js"></script> 95 <script src="bower_components/bootstrap-validator/js/validator.js"></script>
94 <!-- Include Velocity --> 96 <!-- Include Velocity -->
95 <script src="bower_components/velocity/velocity.min.js"></script> 97 <script src="bower_components/velocity/velocity.min.js"></script>
96 98
97 <script> 99 <script>
98 $(function() { 100 $(function() {
99 var firstName = $("#firstname"), 101 var firstName = $("#firstname"),
100 lastName = $("#lastname"), 102 lastName = $("#lastname"),
101 tabTemplate = "<li id='#{id}'> \ 103 tabTemplate = "<li id='#{id}'> \
102 <a href='#{href}'>#{label}</a> \ 104 <a href='#{href}'>#{label}</a> \
103 <span class='ui-icon ui-icon-close'></span> \ 105 <span class='ui-icon ui-icon-close'></span> \
104 </li>", 106 </li>",
105 tabCounter = 0, 107 tabCounter = 0,
106 messageIntervals = {}, 108 messageIntervals = {},
107 getConversationsTimeout, 109 getConversationsTimeout,
108 tabs = $("#tabs").tabs(); 110 tabs = $("#tabs").tabs();
109   111  
110 $("#startConversation") 112 $("#startConversation")
111 .on("click", function() { 113 .on("click", function() {
112 addTab(); 114 addTab();
113 $("#dialog").modal('hide'); 115 $("#dialog").modal('hide');
114 }); 116 });
115   117  
116 // Request the active conversations from the backend script and create tabs. 118 // Request the active conversations from the backend script and create tabs.
117 function getConversations() { 119 function getConversations() {
118 $.get("getConversations.php?t=" + Math.random(), function(data) { 120 $.get("getConversations.php?t=" + Math.random(), function(data) {
119 var json = $.parseJSON(data); 121 var json = $.parseJSON(data);
120 $.each(json, function(index, avatar) { 122 $.each(json, function(index, avatar) {
121 if (!conversationExists(avatar.firstname, avatar.lastname)) 123 if (!conversationExists(avatar.firstname, avatar.lastname))
122 addTab(avatar.firstname, avatar.lastname); 124 addTab(avatar.firstname, avatar.lastname);
123 }); 125 });
124 getConversationsTimeout = setTimeout( 126 getConversationsTimeout = setTimeout(
125 getConversations, 127 getConversations,
126 1000 128 1000
127 ); 129 );
128 }); 130 });
129 } 131 }
130   132  
131 // Function to send the message to an agent by passing it back through PHP. 133 // Function to send the message to an agent by passing it back through PHP.
132 function sendInstantMessage(e) { 134 function sendInstantMessage(e) {
133 var index = e.data.index; 135 var index = e.data.index;
134 // If the parameters are empty, then do not send anything to the PHP script. 136 // If the parameters are empty, then do not send anything to the PHP script.
135 if($.trim($("#firstname-" + index).val()) == '' || 137 if($.trim($("#firstname-" + index).val()) == '' ||
136 $.trim($("#lastname-" + index).val()) == '' || 138 $.trim($("#lastname-" + index).val()) == '' ||
137 $.trim($("#message-" + index).val()) == '') 139 $.trim($("#message-" + index).val()) == '')
138 return; 140 return;
139 $("#controls-" + index).animate( 141 $("#controls-" + index).animate(
140 { 142 {
141 opacity: 0 143 opacity: 0
142 }, 144 },
143 { 145 {
144 duration: 1000, 146 duration: 1000,
145 easing: "linear" 147 easing: "linear"
146 } 148 }
147 ); 149 );
148 $.ajax({ 150 $.ajax({
149 type: 'post', 151 type: 'post',
150 url: "sendInstantMessage.php", 152 url: "sendInstantMessage.php",
151 data: { 153 data: {
152 name: $("#name").val(), 154 name: $("#name").val(),
153 firstname: $("#firstname-" + index).val(), 155 firstname: $("#firstname-" + index).val(),
154 lastname: $("#lastname-" + index).val(), 156 lastname: $("#lastname-" + index).val(),
155 message: $("#message-" + index).val() 157 message: $("#message-" + index).val()
156 } 158 }
157 }).done(function(data) { 159 }).done(function(data) {
158 if(data) 160 if(data)
159 alert(data); 161 alert(data);
160 $("#message-" + index).val(""); 162 $("#message-" + index).val("");
161 $("#controls-" + index).animate( 163 $("#controls-" + index).animate(
162 { 164 {
163 opacity: 1 165 opacity: 1
164 }, 166 },
165 { 167 {
166 duration: 1000, 168 duration: 1000,
167 easing: "linear" 169 easing: "linear"
168 } 170 }
169 ); 171 );
170 }); 172 });
171 } 173 }
172   174  
173 // Loads all the stored instant messages from the log file named after the avatar. 175 // Loads all the stored instant messages from the log file named after the avatar.
174 function loadInstantMessage(index) { 176 function loadInstantMessage(index) {
175 $.get("messages/" + $("#firstname-" + index).val() + " " + $("#lastname-" + index).val() + ".log" + "?t=" + Math.random(), function(data) { 177 $.get("messages/" + $("#firstname-" + index).val() + " " + $("#lastname-" + index).val() + ".log" + "?t=" + Math.random(), function(data) {
176 $("#chat-" + index).html(data); 178 $("#chat-" + index).html(data);
177 // Scroll to the bottom of the conversation. 179 // Scroll to the bottom of the conversation.
178 $("#chat-" + index).scrollTop($("#chat-" + index)[0].scrollHeight); 180 $("#chat-" + index).scrollTop($("#chat-" + index)[0].scrollHeight);
179 messageIntervals[index] = setTimeout( 181 messageIntervals[index] = setTimeout(
180 loadInstantMessage, 182 loadInstantMessage,
181 1000, 183 1000,
182 index 184 index
183 ); 185 );
184 }); 186 });
185 } 187 }
186   188  
187 // This function checks whether a conversation / tab already exists. 189 // This function checks whether a conversation / tab already exists.
188 function conversationExists(firstName, lastName) { 190 function conversationExists(firstName, lastName) {
189 var exists = false; 191 var exists = false;
190 for (var i = tabCounter; i >= 0; --i) { 192 for (var i = tabCounter; i >= 0; --i) {
191 if ($("#firstname-" + i).length && 193 if ($("#firstname-" + i).length &&
192 $("#firstname-" + i).val().toUpperCase() == firstName.toUpperCase() && 194 $("#firstname-" + i).val().toUpperCase() == firstName.toUpperCase() &&
193 $("#lastname-" + i).length && 195 $("#lastname-" + i).length &&
194 $("#lastname-" + i).val().toUpperCase() == lastName.toUpperCase()) { 196 $("#lastname-" + i).val().toUpperCase() == lastName.toUpperCase()) {
195 exists = true; 197 exists = true;
196 break; 198 break;
197 } 199 }
198 } 200 }
199 return exists; 201 return exists;
200 } 202 }
201   203  
202 // Adds a new tab in case a conversation with that agent does not exist. 204 // Adds a new tab in case a conversation with that agent does not exist.
203 function addTab(first, last) { 205 function addTab(first, last) {
204 var first = typeof first !== 'undefined' ? first : firstName.val(); 206 var first = typeof first !== 'undefined' ? first : firstName.val();
205 var last = typeof last !== 'undefined' ? last : lastName.val(); 207 var last = typeof last !== 'undefined' ? last : lastName.val();
206 208
207 // A conversation with that agent exists, so just do nothing. 209 // A conversation with that agent exists, so just do nothing.
208 if (conversationExists(first, last)) 210 if (conversationExists(first, last))
209 return; 211 return;
210 212
211 // Normalize avatar names by capitalizing the first letter of the firstname and the last name. 213 // Normalize avatar names by capitalizing the first letter of the firstname and the last name.
212 first = first.charAt(0).toUpperCase() + first.substr(1); 214 first = first.charAt(0).toUpperCase() + first.substr(1);
213 last = last.charAt(0).toUpperCase() + last.substr(1); 215 last = last.charAt(0).toUpperCase() + last.substr(1);
214 216
215 // Build the discussion form and add the tab. 217 // Build the discussion form and add the tab.
216 var label = first + " " + last, 218 var label = first + " " + last,
217 id = "tabs-" + tabCounter, 219 id = "tabs-" + tabCounter,
218 li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{id\}/g, tabCounter).replace(/#\{label\}/g, label)); 220 li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{id\}/g, tabCounter).replace(/#\{label\}/g, label));
219   221  
220 tabs.find(".ui-tabs-nav").append(li); 222 tabs.find(".ui-tabs-nav").append(li);
221 tabs.append("<div id='" + id + "'>"+ " \ 223 tabs.append("<div id='" + id + "'>"+ " \
222 <div id='container-" + tabCounter + "'> \ 224 <div id='container-" + tabCounter + "'> \
223 <form role='form' data-toggle='validator' id='form-" + tabCounter + "' action='javascript:return;'> \ 225 <form role='form' data-toggle='validator' id='form-" + tabCounter + "' action='javascript:return;'> \
224 <div class='form-group row'> \ 226 <div class='form-group row'> \
225 <textarea class='form-control' readonly='readonly' id='chat-" + tabCounter + "' rows='12'></textarea><br/> \ 227 <textarea class='form-control' readonly='readonly' id='chat-" + tabCounter + "' rows='12'></textarea><br/> \
226 </div> \ 228 </div> \
227 <div id='controls-" + tabCounter + "' class='form-group row'> \ 229 <div id='controls-" + tabCounter + "' class='form-group row'> \
228 <div class='col-lg-1'> \ 230 <div class='col-lg-1'> \
229 <div class='input-group'> \ 231 <div class='input-group'> \
230 <span class='input-group-addon'> \ 232 <span class='input-group-addon'> \
231 <label for='message-" + tabCounter + "'>Message</label> \ 233 <label for='message-" + tabCounter + "'>Message</label> \
232 </span> \ 234 </span> \
233 <input type='text' maxlength='255' class='form-control' id='message-" + tabCounter + "' required> \ 235 <input type='text' maxlength='255' class='form-control' id='message-" + tabCounter + "' required> \
234 <span class='input-group-btn' style='font-size: inherit;'> \ 236 <span class='input-group-btn' style='font-size: inherit;'> \
235 <button type='submit' class='btn btn-default' id='send-" + tabCounter + "'>Send</button> \ 237 <button type='submit' class='btn btn-default' id='send-" + tabCounter + "'>Send</button> \
236 </span> \ 238 </span> \
237 </div> \ 239 </div> \
238 </div> \ 240 </div> \
239 </div> \ 241 </div> \
240 <input type='hidden' name='firstname' id='firstname-" + tabCounter + "' value='" + first + "'> \ 242 <input type='hidden' name='firstname' id='firstname-" + tabCounter + "' value='" + first + "'> \
241 <input type='hidden' name='lastname' id='lastname-" + tabCounter + "' value='" + last + "'> \ 243 <input type='hidden' name='lastname' id='lastname-" + tabCounter + "' value='" + last + "'> \
242 </form> \ 244 </form> \
243 </div> \ 245 </div> \
244 </div>"); 246 </div>");
245 tabs.tabs("refresh"); 247 tabs.tabs("refresh");
246 $("#form-" + tabCounter).validator(); 248 $("#form-" + tabCounter).validator();
247   249  
248 // Subscribe to click event to send the instant message. 250 // Subscribe to click event to send the instant message.
249 $("#send-" + tabCounter).on("click", { 251 $("#send-" + tabCounter).on("click", {
250 index: tabCounter 252 index: tabCounter
251 }, sendInstantMessage); 253 }, sendInstantMessage);
252   254  
253 // Subscribe to pressing enter with the message input box selected. 255 // Subscribe to pressing enter with the message input box selected.
254 $("#message-" + tabCounter).keypress({ 256 $("#message-" + tabCounter).keypress({
255 index: tabCounter 257 index: tabCounter
256 }, function(e) { 258 }, function(e) {
257 if (e.which == 13) { 259 if (e.which == 13) {
258 sendInstantMessage(e); 260 sendInstantMessage(e);
259 return false; 261 return false;
260 } 262 }
261 }); 263 });
262   264  
263 ++tabCounter; 265 ++tabCounter;
264 } 266 }
265   267  
266 // Close icon: removing the tab on click and delete the conversation. 268 // Close icon: removing the tab on click and delete the conversation.
267 tabs.on("click", "span.ui-icon-close", function() { 269 tabs.on("click", "span.ui-icon-close", function() {
268 var panelId = $(this).closest("li").remove().attr("aria-controls"); 270 var panelId = $(this).closest("li").remove().attr("aria-controls");
269 var selectedIndex = $(this).closest("li").remove().attr("id"); 271 var selectedIndex = $(this).closest("li").remove().attr("id");
270 // Pause the conversation retrieval timer. 272 // Pause the conversation retrieval timer.
271 clearTimeout(getConversationsTimeout); 273 clearTimeout(getConversationsTimeout);
272 $.ajax({ 274 $.ajax({
273 type: 'post', 275 type: 'post',
274 url: "deleteConversation.php", 276 url: "deleteConversation.php",
275 data: { 277 data: {
276 firstname: $("#firstname-" + selectedIndex).val(), 278 firstname: $("#firstname-" + selectedIndex).val(),
277 lastname: $("#lastname-" + selectedIndex).val() 279 lastname: $("#lastname-" + selectedIndex).val()
278 } 280 }
279 }).done(function(data) { 281 }).done(function(data) {
280 $("#" + panelId).remove(); 282 $("#" + panelId).remove();
281 tabs.tabs("refresh"); 283 tabs.tabs("refresh");
282 // Resume the conversation retrieval timer. 284 // Resume the conversation retrieval timer.
283 getConversationsTimeout = setTimeout( 285 getConversationsTimeout = setTimeout(
284 getConversations, 286 getConversations,
285 1000 287 1000
286 ); 288 );
287 }); 289 });
288 }); 290 });
289   291  
290 // Unbind the message retrieval interval from all other tabs except the active tab. 292 // Unbind the message retrieval interval from all other tabs except the active tab.
291 tabs.on('tabsactivate', function(event, ui) { 293 tabs.on('tabsactivate', function(event, ui) {
292 var selectedIndex = ui.newTab.closest("li").attr("id"); 294 var selectedIndex = ui.newTab.closest("li").attr("id");
293 $.each(messageIntervals, function(index, value) { 295 $.each(messageIntervals, function(index, value) {
294 if (index != selectedIndex) { 296 if (index != selectedIndex) {
295 clearInterval(value); 297 clearInterval(value);
296 } 298 }
297 }); 299 });
298   300  
299 messageIntervals[selectedIndex] = setTimeout( 301 messageIntervals[selectedIndex] = setTimeout(
300 loadInstantMessage, 302 loadInstantMessage,
301 1000, 303 1000,
302 selectedIndex 304 selectedIndex
303 ); 305 );
304 }); 306 });
305   307  
306 // Start a timer to load tabs of existing conversations. 308 // Start a timer to load tabs of existing conversations.
307 getConversationsTimeout = setTimeout( 309 getConversationsTimeout = setTimeout(
308 getConversations, 310 getConversations,
309 1000 311 1000
310 ); 312 );
311   313  
312 }); 314 });
313 </script> 315 </script>
314 </body> 316 </body>
315   317  
316 </html> 318 </html>
317   319  
318
Generated by GNU Enscript 1.6.5.90.
320
Generated by GNU Enscript 1.6.5.90.
319   321  
320   322  
321   323