6 muc_server: "support.localhost", |
6 muc_server: "support.localhost", |
7 team_rooms: { |
7 team_rooms: { |
8 "Sales": "sales@support.localhost", |
8 "Sales": "sales@support.localhost", |
9 "Technical": "technical@support.localhost" |
9 "Technical": "technical@support.localhost" |
10 }, |
10 }, |
11 send_invites: true |
11 send_invites: true, |
|
12 offline_support: "support@localhost" |
12 }; |
13 }; |
13 |
14 |
14 /*** XMPP handling */ |
15 /*** XMPP handling */ |
15 var conn = null; |
16 var conn = null; |
|
17 |
|
18 /*** Query information */ |
|
19 var question_type; // E.g. "Sales", "Technical" = $("#support-question-type").val(); |
|
20 var question_name; // Name of the submitter |
|
21 var question_text; // The query itself |
16 |
22 |
17 /* Called by Strophe when status of connection changes |
23 /* Called by Strophe when status of connection changes |
18 (from disconnected to connected, vice-versa, etc.) |
24 (from disconnected to connected, vice-versa, etc.) |
19 */ |
25 */ |
20 function handle_connection_status(status, err) |
26 function handle_connection_status(status, err) |
44 /*** UI handling */ |
50 /*** UI handling */ |
45 |
51 |
46 /* Initial UI state */ |
52 /* Initial UI state */ |
47 var ui_state = "question"; |
53 var ui_state = "question"; |
48 |
54 |
49 /* Change the UI state (question, wait, converse) */ |
55 /* Called to change the UI state (question, wait, converse) */ |
50 function set_ui_state(new_state) |
56 function set_ui_state(new_state) |
51 { |
57 { |
52 if(ui_state != new_state) |
58 if(ui_state != new_state) |
53 { |
59 { |
54 $("#support-"+ui_state).hide(); |
60 $("#support-"+ui_state).hide(); |
57 } |
63 } |
58 |
64 |
59 /* Handle the user submitting the question form */ |
65 /* Handle the user submitting the question form */ |
60 function on_question_submit() |
66 function on_question_submit() |
61 { |
67 { |
62 var question_type = $("#support-question-type").val(); |
68 question_type = $("#support-question-type").val(); |
63 var question_name = $("#support-question-name").val(); |
69 question_name = $("#support-question-name").val(); |
64 var question_text = $("#support-question-text").val(); |
70 question_text = $("#support-question-text").val(); |
65 |
71 |
66 var our_nick = question_name; |
72 var our_nick = question_name; |
67 |
73 |
68 set_ui_state("wait"); |
74 set_ui_state("wait"); |
69 |
75 |
111 question_muc.join(unique + "@" + support_config.muc_server, our_nick); |
117 question_muc.join(unique + "@" + support_config.muc_server, our_nick); |
112 }); |
118 }); |
113 |
119 |
114 // Create the team MUC object (it will be joined after we join the question MUC) |
120 // Create the team MUC object (it will be joined after we join the question MUC) |
115 var team_muc = new MUC(conn, { |
121 var team_muc = new MUC(conn, { |
|
122 // Someone joined the team MUC |
116 joined: function (stanza, muc, nick) |
123 joined: function (stanza, muc, nick) |
117 { |
124 { |
118 if(nick != our_nick) |
125 if(nick != our_nick) |
119 return; |
126 return; |
120 |
127 |
121 var sent = false; |
128 var sent = false; |
122 for(var nick in team_muc.occupants) |
129 for(var nick in team_muc.occupants) |
123 { |
130 { |
124 //FIXME: Check affiliation |
131 var affiliation = $(stanza) |
|
132 .find("x[xmlns='http://jabber.org/protocol/muc#user']>item") |
|
133 .attr("affiliation"); |
|
134 if(affiliation == "none" || nick == our_nick) |
|
135 continue; |
125 sent = true; |
136 sent = true; |
126 if(nick == our_nick) |
137 if(support_config.send_invites) |
127 continue; |
|
128 else if(support_config.send_invites) |
|
129 team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid); |
138 team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid); |
130 else |
139 else |
131 team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid); |
140 team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid); |
132 } |
141 } |
133 if(!sent) |
142 if(!sent) |
185 <p>To receive a reply to your question via \ |
194 <p>To receive a reply to your question via \ |
186 email, please enter your email address \ |
195 email, please enter your email address \ |
187 below: \ |
196 below: \ |
188 </p> \ |
197 </p> \ |
189 <input id="support-offline-email" type="text" /> \ |
198 <input id="support-offline-email" type="text" /> \ |
190 <input id="support-send-button" type="submit" value="Submit" /> \ |
199 <input id="support-offline-submit-button" type="submit" value="Submit" /> \ |
191 </div> \ |
200 </div> \ |
192 <div id="support-offline-thanks"> \ |
201 <div id="support-offline-thanks"> \ |
193 <p>Thank you. Your question has been submitted \ |
202 <p>Thank you. Your question has been submitted \ |
194 and will be replied to as soon as an assistant \ |
203 and will be replied to as soon as an assistant \ |
195 becomes available.</p> \ |
204 becomes available.</p> \ |
207 ui.appendTo("body"); |
216 ui.appendTo("body"); |
208 |
217 |
209 if(start_connection()) |
218 if(start_connection()) |
210 { |
219 { |
211 $("#support-question-submit").click(on_question_submit); |
220 $("#support-question-submit").click(on_question_submit); |
|
221 $("#support-offline-submit-button").click(function () |
|
222 { |
|
223 $("#support-offline-form").hide(); |
|
224 conn.send($msg({to: support_config.offline_support, type: "normal"}) |
|
225 .c("subject").t("Support query from " + question_name).up() |
|
226 .c("body").t(question_text + "\n\nReply via email to: "+ |
|
227 $("#support-offline-email").val())); |
|
228 $("#support-offline-thanks").show(); |
|
229 }); |
212 ui.dialog({ |
230 ui.dialog({ |
213 title:"Live Support", |
231 title:"Live Support", |
214 height: 400, |
232 height: 400, |
215 width: 285 |
233 width: 285 |
216 }); |
234 }); |