support-chat/js/supportchat.js

Fri, 16 Apr 2010 18:44:53 +0100

author
matthew@heavyhorse.vm.bytemark.co.uk
date
Fri, 16 Apr 2010 18:44:53 +0100
changeset 58
c775513a5d78
parent 56
5dd3b23da0ae
child 59
603d9caeb6d5
permissions
-rw-r--r--

Remove the current assistant if they leave the room

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 },
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
11 send_invites: true,
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
12 offline_support: "support@localhost",
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
13 alternative_url: "http://www.google.co.uk/"
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
14 };
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
15
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
16 /*** XMPP handling */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
17 var conn = null;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
18
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
19 /*** Query information */
39
0b18fb969bd3 Remove part of a comment accidentally copy/pasted
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
20 var question_type; // E.g. "Sales", "Technical"
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
21 var question_name; // Name of the submitter
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
22 var question_text; // The query itself
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
23
53
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
24 /*** XMPP rooms */
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
25 var team_muc; // MUC of the assistant team
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
26 var question_muc; // Temporary room for query discussion
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
27
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
28 /* Called by Strophe when status of connection changes
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
29 (from disconnected to connected, vice-versa, etc.)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
30 */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
31 function handle_connection_status(status, err)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
32 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
33 if(err)
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
34 set_ui_state("error");
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
35 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
36
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
37 /* Initiate the connection to the XMPP server */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
38 function start_connection()
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
39 {
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
40 conn = new Strophe.Connection(support_config.bosh_url);
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
41 var ret = true;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
42 try
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
43 {
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
44 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
45 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
46 catch(e)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
47 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
48 ret = false;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
49 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
50 return ret;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
51 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
52
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
53 /*** UI handling */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
54
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
55 /* Initial UI state */
23
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
56 var ui_state = "question";
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
57
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
58 /* Called to 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
59 function set_ui_state(new_state)
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
60 {
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
61 if(ui_state != new_state)
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
62 {
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
63 $("#support-"+ui_state).hide();
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
64 $("#support-"+(ui_state=new_state)).show();
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
65 }
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
66 }
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
67
54
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
68 var current_assistant = null;
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
69 function set_assistant(new_assistant)
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
70 {
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
71 if(new_assistant == null)
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
72 {
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
73 $("#support-assistant-name").text("No assistant present.");
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
74 question_muc.send_message("{System} There is now no active assistant");
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
75 team_muc.send_message("Query has no active assistant");
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
76 show_message(null, current_assistant + " has left, please stand by.");
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
77 }
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
78 else
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
79 {
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
80 $("#support-assistant-name").html("<u>Assistant:</u> "+htmlescape(new_assistant));
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
81 question_muc.send_message("{System} "+new_assistant+": You are now the selected assistant");
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
82 team_muc.send_message("Query being handled by "+new_assistant);
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
83 show_message(null, "You are now being assisted by " + new_assistant)
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
84 }
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
85 current_assistant = new_assistant;
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
86 }
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
87
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
88 function show_message(nick, message)
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
89 {
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
90 var html = "<span class='muc-"+(nick?"message":"system")+"'>";
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
91 if(nick)
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
92 html += "<span class='muc-nick'>" + htmlescape(nick) + "</span>" + ": ";
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
93 html += htmlescape(message) + "</span><br/>\n";
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
94 $("#support-log").append(html).scrollTop($("#support-log")[0].scrollHeight);
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
95 }
e5e70a46ace8 Add set_assistant and show_message functions
matthew@heavyhorse.vm.bytemark.co.uk
parents: 53
diff changeset
96
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
97 /* 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
98 function on_question_submit()
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
99 {
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
100 question_type = $("#support-question-type").val();
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
101 question_name = $("#support-question-name").val();
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
102 question_text = $("#support-question-text").val();
9
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
103
23
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
104 set_ui_state("wait");
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
105
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
106 // Create our question room
53
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
107 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
108 // Handle room joins
43
a3febc43e4e9 Changes to work with new callback syntax
Matthew Wild <mwild1@gmail.com>
parents: 39
diff changeset
109 joined: function (stanza, muc, occupant)
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
110 {
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
111 if(occupant.nick == question_muc.nick)
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
112 {
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
113 // We joined the question room, now join the team room and tell them
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
114 team_muc.join(support_config.team_rooms[question_type], question_muc.nick);
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
115 // Also post our question to the question room for reference
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
116 question_muc.send_message(question_text);
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
117 }
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
118 else if(current_assistant == null)
23
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
119 {
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
120 // We were waiting for an assistant, and one just joined
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
121 set_assistant(occupant.nick);
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
122 if(ui_state == "wait")
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
123 {
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
124 $("#support-send-button").click(function ()
34
510ca613996a Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents: 33
diff changeset
125 {
510ca613996a Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents: 33
diff changeset
126 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
127 $("#support-input").val("");
510ca613996a Add support for sending messages from the converse UI
Matthew Wild <mwild1@gmail.com>
parents: 33
diff changeset
128 });
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
129 set_ui_state("converse");
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
130 }
23
ee84e7c22600 New logic for controlling the current UI state
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
131 }
28
85fb6653b6e0 Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
132 },
85fb6653b6e0 Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
133
58
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
134 // Someone left the question MUC
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
135 left: function (stanza, muc, occupant)
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
136 {
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
137 if(occupant.nick == current_assistant)
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
138 set_assistant(null);
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
139 },
c775513a5d78 Remove the current assistant if they leave the room
matthew@heavyhorse.vm.bytemark.co.uk
parents: 56
diff changeset
140
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
141 // Handle incoming messages
28
85fb6653b6e0 Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
142 message: function (stanza, muc, nick, message)
85fb6653b6e0 Display incoming messages in the UI
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
143 {
56
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
144 if(nick != question_muc.nick && message.charAt(0) == "!") // Command
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
145 {
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
146 if(message.indexOf("!assist") == 0)
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
147 {
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
148 set_assistant(nick);
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
149 }
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
150 else if(message.indexOf("!stop") == 0)
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
151 {
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
152 set_assistant(null);
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
153 }
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
154 }
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
155 else if(nick != question_muc.nick || message.indexOf("{System} ") != 0) // Normal message
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
156 {
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
157 show_message(nick, message);
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
158 }
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
159 }
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
160 });
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
161
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
162 // 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
163 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
164 .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
165 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
166 {
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
167 var unique = Strophe.getText(result.getElementsByTagName("unique")[0]);
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
168 question_muc.join(unique + "@" + support_config.muc_server, question_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
169 },
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
170 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
171 {
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
172 var unique = "support-"+Math.floor(Math.random()*512);
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
173 question_muc.join(unique + "@" + support_config.muc_server, question_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
174 });
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
175
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
176 // Create the team MUC object (it will be joined after we join the question MUC)
53
5cb47f4087a8 Declare question_muc/team_muc as global singletons
matthew@heavyhorse.vm.bytemark.co.uk
parents: 51
diff changeset
177 team_muc = new MUC(conn, {
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
178 // Someone joined the team MUC
43
a3febc43e4e9 Changes to work with new callback syntax
Matthew Wild <mwild1@gmail.com>
parents: 39
diff changeset
179 joined: function (stanza, muc, occupant)
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
180 {
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
181 if(occupant.nick != team_muc.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
182 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
183
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
184 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
185 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
186 {
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
187 if(team_muc.occupants[nick].affiliation == "none" || nick == team_muc.nick)
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
188 continue;
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
189 sent = true;
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
190 if(support_config.send_invites)
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
191 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
192 else
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
193 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
194 }
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
195 if(!sent)
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
196 {
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
197 set_ui_state("offline");
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
198 }
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
199 },
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
200
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
201 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
202 {
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
203 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
204 {
55
6f0822a428b7 Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.
matthew@heavyhorse.vm.bytemark.co.uk
parents: 54
diff changeset
205 muc.join(support_config.team_rooms[question_type], team_muc.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
206 }
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
207 else
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
208 set_ui_state("error");
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
209 }
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
210 });
7
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
211 }
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
212
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
213 function build_ui()
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
214 {
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
215 return $(" \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
216 <div id='support-chat'> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
217 <div id='support-question'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
218 <h2>What is the nature of your question?</h2> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
219 <select id='support-question-type'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
220 <option>Sales</option> \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
221 <option>Technical</option> \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
222 </select> \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
223 <h2>What is your name?</h2> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
224 <input id='support-question-name' type='text' /> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
225 <h2>Your question:</h2> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
226 <textarea id='support-question-text'></textarea><br/> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
227 <input id='support-question-submit' type='submit' /> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
228 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
229 <div id='support-wait'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
230 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
231 answer your query... \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
232 <br/><br/><br/><br/> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
233 <center><img src='waiting.gif' alt='Waiting' /></center> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
234 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
235 <div id='support-converse'> \
56
5dd3b23da0ae Management of current assistant via !assist and !stop
matthew@heavyhorse.vm.bytemark.co.uk
parents: 55
diff changeset
236 <div id='support-assistant-name'></div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
237 <div id='support-log'></div> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
238 <div id='support-input-container'><textarea id='support-input' type='text' value=''></textarea></div> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
239 <input id='support-send-button' type='submit' value='Send' /> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
240 <div style='clear:right;'></div> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
241 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
242 <div id='support-offline'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
243 <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
244 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
245 </p> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
246 <div id='support-offline-form'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
247 <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
248 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
249 below: \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
250 </p> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
251 <input id='support-offline-email' type='text' /> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
252 <input id='support-offline-submit-button' type='submit' value='Submit' /> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
253 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
254 <div id='support-offline-thanks'> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
255 <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
256 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
257 becomes available.</p> \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
258 </div> \
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
259 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
260 <div id='support-error'> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
261 <p>Sorry, there is a problem with the live support \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
262 service at the moment. Please see our \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
263 <a href='"+support_config.alternative_url+"'>alternative \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
264 support channels</a> to receive assistance. \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
265 </p> \
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
266 </div> \
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
267 </div> \
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
268 ");
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
269 }
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
270
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 function display_ui()
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272 {
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 // 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
274 var ui = build_ui();
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
275
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
276 ui.appendTo("body");
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
277
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
278 $("#support-question-submit").click(on_question_submit);
50
53bfdcb686f7 Bind enter to the send button in the chat UI
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
279 $("#support-input").keypress(function (event) {
53bfdcb686f7 Bind enter to the send button in the chat UI
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
280 if(event.keyCode == 13)
51
7f893f429760 Suppress enter key press so it doesn't reach the textbox
matthew@heavyhorse.vm.bytemark.co.uk
parents: 50
diff changeset
281 {
7f893f429760 Suppress enter key press so it doesn't reach the textbox
matthew@heavyhorse.vm.bytemark.co.uk
parents: 50
diff changeset
282 event.preventDefault();
50
53bfdcb686f7 Bind enter to the send button in the chat UI
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
283 $("#support-send-button").click();
51
7f893f429760 Suppress enter key press so it doesn't reach the textbox
matthew@heavyhorse.vm.bytemark.co.uk
parents: 50
diff changeset
284 }
50
53bfdcb686f7 Bind enter to the send button in the chat UI
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
285 });
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
286 $("#support-offline-submit-button").click(function ()
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
287 {
38
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
288 $("#support-offline-form").hide();
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
289 conn.send($msg({to: support_config.offline_support, type: "normal"})
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
290 .c("subject").t("Support query from " + question_name).up()
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
291 .c("body").t(question_text + "\n\nReply via email to: "+
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
292 $("#support-offline-email").val()));
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
293 $("#support-offline-thanks").show();
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
294 });
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
295
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
296 ui.dialog({
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
297 title:"Live Support",
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
298 height: 400,
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
299 width: 285
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
300 });
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
301
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
302 if(!start_connection())
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
303 {
536e0a618d4a Add error page to the UI, and use it on connection errors
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
304 set_ui_state("error");
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
305 }
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 }
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307
27
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
308 /*** Helper functions */
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
309 function htmlescape(s)
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
310 {
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
311 return s.replace(/&/g,'&amp;').
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
312 replace(/>/g,'&gt;').
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
313 replace(/</g,'&lt;').
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
314 replace(/"/g,'&quot;');
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
315 }
8ca116c827cf Add htmlescape() helper function
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
316
36
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
317 function activate_links()
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
318 {
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
319 $("[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
320 }
562ff07a3968 Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
321
37
010783d24970 Commit the rest of the assistants-offline handling code, now check the affiliations of assistants
Matthew Wild <mwild1@gmail.com>
parents: 36
diff changeset
322 $(activate_links);

mercurial