Thu, 01 Apr 2010 16:07:16 +0100
Large commit - reorganises directory structure, lots of small fixes
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
1 | /* Config */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
2 | |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
3 | var support_config = { |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
4 | login_domain: "anon.localhost", |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
5 | bosh_url: "/http-bind", |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
6 | muc_server: "support.localhost", |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
7 | team_rooms: { |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
8 | "Sales": "sales@support.localhost", |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
9 | "Technical": "technical@support.localhost" |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
10 | }, |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
11 | send_invites: true |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
12 | }; |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
13 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
14 | /*** XMPP handling */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
15 | var conn = null; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
16 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
17 | /* Called by Strophe when status of connection changes |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
18 | (from disconnected to connected, vice-versa, etc.) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
19 | */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
20 | function handle_connection_status(status, err) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
21 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
22 | if(err) |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
23 | alert("Connection error: " + err); //FIXME: Handle gracefully |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
24 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
25 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
26 | /* Initiate the connection to the XMPP server */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
27 | function start_connection() |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
28 | { |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
29 | conn = new Strophe.Connection(support_config.bosh_url); |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
30 | var ret = true; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
31 | try |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
32 | { |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
33 | conn.connect(support_config.login_domain, null, handle_connection_status, 50); |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
34 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
35 | catch(e) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
36 | { |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
37 | alert("Connection error: " + e); //FIXME |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
38 | ret = false; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
39 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
40 | return ret; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
41 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
42 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
43 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
44 | /*** UI handling */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
45 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
46 | /* Initial UI state */ |
23
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
47 | var ui_state = "question"; |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
48 | |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
49 | /* Change the UI state (question, wait, converse) */ |
23
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
50 | function set_ui_state(new_state) |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
51 | { |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
52 | if(ui_state != new_state) |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
53 | { |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
54 | $("#support-"+ui_state).hide(); |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
55 | $("#support-"+(ui_state=new_state)).show(); |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
56 | } |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
57 | } |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
58 | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
59 | /* Handle the user submitting the question form */ |
7
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
60 | function on_question_submit() |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
61 | { |
9
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
62 | var question_type = $("#support-question-type").val(); |
13 | 63 | var question_name = $("#support-question-name").val(); |
9
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
64 | var question_text = $("#support-question-text").val(); |
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
65 | |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
66 | var our_nick = question_name; |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
67 | |
23
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
68 | set_ui_state("wait"); |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
69 | |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
70 | // Create our question room |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
71 | var question_muc = new MUC(conn, { |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
72 | // Handle room joins |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
73 | joined: function (stanza, muc, nick) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
74 | { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
75 | if(nick == our_nick) |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
76 | // We joined the question room, now join the team room and tell them |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
77 | team_muc.join(support_config.team_rooms[question_type], our_nick); |
23
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
78 | else if(ui_state == "wait") |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
79 | { |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
80 | // We were waiting for an assistant, and one just joined |
34
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
81 | var html = "<span class='muc-message'><span class='muc-nick'>" + htmlescape(nick) + "</span>" + " is answering your query</span><br/>\n"; |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
82 | $("#support-log").append(html).scrollTop($("#support-log")[0].scrollHeight); |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
83 | $("#support-send-button").click(function () |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
84 | { |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
85 | question_muc.send_message($("#support-input").val()); |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
86 | $("#support-input").val(""); |
510ca613996a
Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
87 | }); |
23
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
88 | set_ui_state("converse"); |
ee84e7c22600
New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents:
22
diff
changeset
|
89 | } |
28
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
90 | }, |
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
91 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
92 | // Handle incoming messages |
28
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
93 | message: function (stanza, muc, nick, message) |
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
94 | { |
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
95 | var html = "<span class='muc-message'><span class='muc-nick'>" + htmlescape(nick) + "</span>" + ": " + htmlescape(message) + "</span><br/>\n"; |
85fb6653b6e0
Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
96 | $("#support-log").append(html).scrollTop($("#support-log")[0].scrollHeight); |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
97 | } |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
98 | }); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
99 | |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
100 | // Get a unique room name from the server and then join the question MUC |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
101 | conn.sendIQ($iq({to: support_config.muc_server, type: "get"}) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
102 | .c("query", { xmlns: "http://jabber.org/protocol/muc#unique" }), |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
103 | function (result) // Success |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
104 | { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
105 | var unique = Strophe.getText(result.getElementsByTagName("unique")[0]); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
106 | question_muc.join(unique + "@" + support_config.muc_server, our_nick); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
107 | }, |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
108 | function (result) // Failure to get unique room name |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
109 | { |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
110 | var unique = "support-"+Math.floor(Math.random()*512); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
111 | question_muc.join(unique + "@" + support_config.muc_server, our_nick); |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
112 | }); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
113 | |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
114 | // Create the team MUC object (it will be joined after we join the question MUC) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
115 | var team_muc = new MUC(conn, { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
116 | joined: function (stanza, muc, nick) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
117 | { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
118 | if(nick != our_nick) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
119 | return; |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
120 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
121 | var sent = false; |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
122 | for(var nick in team_muc.occupants) |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
123 | { |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
124 | //FIXME: Check affiliation |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
125 | sent = true; |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
126 | if(nick == our_nick) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
127 | continue; |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
128 | else if(support_config.send_invites) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
129 | team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
130 | else |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
131 | team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
132 | } |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
133 | if(!sent) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
134 | { |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
135 | set_ui_state("offline"); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
136 | } |
21
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
137 | }, |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
138 | |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
139 | error: function (stanza, muc, error) |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
140 | { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
141 | if(error == "conflict") |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
142 | { |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
143 | our_nick += "_"; |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
144 | muc.join(support_config.team_rooms[question_type], our_nick); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
145 | } |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
146 | else |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
147 | alert("unhandled error: " + error); |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
148 | } |
b691536ed125
Support for joining the question and team MUCs, and notifying team members of the question
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
149 | }); |
7
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
150 | } |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
151 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
152 | function build_ui() |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
153 | { |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
154 | return $(' \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
155 | <div id="support-chat"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
156 | <div id="support-question"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
157 | <h2>What is the nature of your question?</h2> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
158 | <select id="support-question-type"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
159 | <option>Sales</option> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
160 | <option>Technical</option> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
161 | </select> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
162 | <h2>What is your name?</h2> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
163 | <input id="support-question-name" type="text" /> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
164 | <h2>Your question:</h2> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
165 | <textarea id="support-question-text"></textarea><br/> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
166 | <input id="support-question-submit" type="submit" /> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
167 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
168 | <div id="support-wait"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
169 | Please wait while we find someone to \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
170 | answer your query... \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
171 | <br/><br/><br/><br/> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
172 | <center><img src="waiting.gif" alt="Waiting" /></center> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
173 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
174 | <div id="support-converse"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
175 | <div id="support-log"></div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
176 | <div id="support-input-container"><textarea id="support-input" type="text" value=""></textarea></div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
177 | <input id="support-send-button" type="submit" value="Send" /> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
178 | <div style="clear:right;"></div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
179 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
180 | <div id="support-offline"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
181 | <p>Sorry, there are no assistants available \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
182 | to answer your question at the moment. \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
183 | </p> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
184 | <div id="support-offline-form"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
185 | <p>To receive a reply to your question via \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
186 | email, please enter your email address \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
187 | below: \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
188 | </p> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
189 | <input id="support-offline-email" type="text" /> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
190 | <input id="support-send-button" type="submit" value="Submit" /> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
191 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
192 | <div id="support-offline-thanks"> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
193 | <p>Thank you. Your question has been submitted \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
194 | and will be replied to as soon as an assistant \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
195 | becomes available.</p> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
196 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
197 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
198 | </div> \ |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
199 | '); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
200 | } |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
201 | |
3 | 202 | function display_ui() |
203 | { | |
204 | // Display pop-up, showing question form | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
205 | var ui = build_ui(); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
206 | |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
207 | ui.appendTo("body"); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
208 | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
209 | if(start_connection()) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
210 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
211 | $("#support-question-submit").click(on_question_submit); |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
212 | ui.dialog({ |
33 | 213 | title:"Live Support", |
214 | height: 400, | |
215 | width: 285 | |
216 | }); | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
217 | } |
3 | 218 | } |
219 | ||
27
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
220 | /*** Helper functions */ |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
221 | function htmlescape(s) |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
222 | { |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
223 | return s.replace(/&/g,'&'). |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
224 | replace(/>/g,'>'). |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
225 | replace(/</g,'<'). |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
226 | replace(/"/g,'"'); |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
227 | } |
8ca116c827cf
Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents:
26
diff
changeset
|
228 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
229 | function activate_links() |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
230 | { |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
231 | $("[href='#support-chat']").click(display_ui); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
232 | } |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
233 | |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
234 | $(activate_links); //FIXME (debugging) |