corrade-http-templates – Diff between revs 4 and 5

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 4 Rev 5
Line 19... Line 19...
19 var firstName = $("#firstname"), 19 var firstName = $("#firstname"),
20 lastName = $("#lastname"), 20 lastName = $("#lastname"),
21 tabTemplate = "<li id='#{id}'><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>", 21 tabTemplate = "<li id='#{id}'><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>",
22 tabCounter = 0, 22 tabCounter = 0,
23 messageIntervals = {}, 23 messageIntervals = {},
24 getConversationsTimer; 24 getConversationsTimeout;
Line 25... Line 25...
25   25  
Line 26... Line 26...
26 var tabs = $("#tabs").tabs(); 26 var tabs = $("#tabs").tabs();
27   27  
Line 63... Line 63...
63 var json = $.parseJSON(data); 63 var json = $.parseJSON(data);
64 $.each(json, function(index, avatar) { 64 $.each(json, function(index, avatar) {
65 if (!conversationExists(avatar.firstname, avatar.lastname)) 65 if (!conversationExists(avatar.firstname, avatar.lastname))
66 addTab(avatar.firstname, avatar.lastname); 66 addTab(avatar.firstname, avatar.lastname);
67 }); 67 });
-   68 getConversationsTimeout = setTimeout(
-   69 getConversations,
-   70 1000
-   71 );
68 }); 72 });
69 } 73 }
Line 70... Line 74...
70   74  
71 // Function to send the message to an agent by passing it back through PHP. 75 // Function to send the message to an agent by passing it back through PHP.
Line 100... Line 104...
100   104  
101 // Loads all the stored instant messages from the log file named after the avatar. 105 // Loads all the stored instant messages from the log file named after the avatar.
102 function loadInstantMessage(index) { 106 function loadInstantMessage(index) {
103 $.get("messages/" + $("#firstname-" + index).val() + " " + $("#lastname-" + index).val() + ".log" + "?t=" + Math.random(), function(data) { 107 $.get("messages/" + $("#firstname-" + index).val() + " " + $("#lastname-" + index).val() + ".log" + "?t=" + Math.random(), function(data) {
-   108 $("#chat-" + index).html(data);
-   109 $("#chat-" + index).animate({
-   110 scrollTop: $("#chat-" + index)[0].scrollHeight - $("#chat-" + index).height()
-   111 }, 1000);
-   112 messageIntervals[index] = setTimeout(
-   113 loadInstantMessage,
-   114 1000,
-   115 index
104 $("#chat-" + index).html(data); 116 );
105 }); -  
106   -  
107 $("#chat-" + index).animate({ -  
108 scrollTop: $("#chat-" + index)[0].scrollHeight - $("#chat-" + index).height() -  
109 }, 1000); 117 });
Line 110... Line 118...
110 } 118 }
111   119  
112 // This function checks whether a conversation / tab already exists. 120 // This function checks whether a conversation / tab already exists.
Line 143... Line 151...
143 li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{id\}/g, tabCounter).replace(/#\{label\}/g, label)); 151 li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{id\}/g, tabCounter).replace(/#\{label\}/g, label));
Line 144... Line 152...
144   152  
145 tabs.find(".ui-tabs-nav").append(li); 153 tabs.find(".ui-tabs-nav").append(li);
146 tabs.append("<div id='" + id + "'><p>" + " \ 154 tabs.append("<div id='" + id + "'><p>" + " \
147 <div id='container-" + tabCounter + "'> \ 155 <div id='container-" + tabCounter + "'> \
148 <textarea id='chat-" + tabCounter + "' rows='12'></textarea><br/> \ 156 <textarea readonly='readonly' id='chat-" + tabCounter + "' rows='12'></textarea><br/> \
149 <div id='controls-" + tabCounter + "'> \ 157 <div id='controls-" + tabCounter + "'> \
150 Message: <input type='text' size='70' id='message-" + tabCounter + "'></input> \ 158 Message: <input type='text' size='70' id='message-" + tabCounter + "'></input> \
151 <button type='button' id='send-" + tabCounter + "'>Send</button> \ 159 <button type='button' id='send-" + tabCounter + "'>Send</button> \
152 <input type='hidden' name='firstname' id='firstname-" + tabCounter + "' value='" + first + "'></input> \ 160 <input type='hidden' name='firstname' id='firstname-" + tabCounter + "' value='" + first + "'></input> \
Line 177... Line 185...
177 // Close icon: removing the tab on click and delete the conversation. 185 // Close icon: removing the tab on click and delete the conversation.
178 tabs.on("click", "span.ui-icon-close", function() { 186 tabs.on("click", "span.ui-icon-close", function() {
179 var panelId = $(this).closest("li").remove().attr("aria-controls"); 187 var panelId = $(this).closest("li").remove().attr("aria-controls");
180 var selectedIndex = $(this).closest("li").remove().attr("id"); 188 var selectedIndex = $(this).closest("li").remove().attr("id");
181 // Pause the conversation retrieval timer. 189 // Pause the conversation retrieval timer.
182 clearInterval(getConversationsTimer); 190 clearTimeout(getConversationsTimeout);
183 $.ajax({ 191 $.ajax({
184 type: 'post', 192 type: 'post',
185 url: "deleteConversation.php", 193 url: "deleteConversation.php",
186 data: { 194 data: {
187 firstname: $("#firstname-" + selectedIndex).val(), 195 firstname: $("#firstname-" + selectedIndex).val(),
Line 189... Line 197...
189 } 197 }
190 }).done(function(data) { 198 }).done(function(data) {
191 $("#" + panelId).remove(); 199 $("#" + panelId).remove();
192 tabs.tabs("refresh"); 200 tabs.tabs("refresh");
193 // Resume the conversation retrieval timer. 201 // Resume the conversation retrieval timer.
194 getConversationsTimer = setInterval( 202 getConversationsTimeout = setTimeout(
195 getConversations, 203 getConversations,
196 1000 204 1000
197 ); 205 );
198 }); 206 });
199 }); 207 });
Line 205... Line 213...
205 if (index != selectedIndex) { 213 if (index != selectedIndex) {
206 clearInterval(value); 214 clearInterval(value);
207 } 215 }
208 }); 216 });
Line 209... Line 217...
209   217  
210 messageIntervals[selectedIndex] = setInterval( 218 messageIntervals[selectedIndex] = setTimeout(
211 loadInstantMessage, 219 loadInstantMessage,
212 1000, 220 1000,
213 selectedIndex 221 selectedIndex
214 ); 222 );
Line 215... Line 223...
215 }); 223 });
216   224  
217 // Start a timer to load tabs of existing conversations. 225 // Start a timer to load tabs of existing conversations.
218 getConversationsTimer = setInterval( 226 getConversationsTimeout = setTimeout(
219 getConversations, 227 getConversations,
Line 220... Line 228...
220 1000 228 1000