js/supportchat.js

Thu, 18 Mar 2010 18:13:39 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 18 Mar 2010 18:13:39 +0000
changeset 22
54574593fa89
parent 21
b691536ed125
child 23
ee84e7c22600
permissions
-rw-r--r--

Remove some code to control a UI we don't have at the moment

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"
ebc14a22a0c1 Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
10 }
ebc14a22a0c1 Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
11 };
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
13 /*** XMPP handling */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
14 var conn = null;
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 /* Called by Strophe when status of connection changes
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
17 (from disconnected to connected, vice-versa, etc.)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
18 */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
19 function handle_connection_status(status, err)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
20 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
21 if(err)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
22 alert(err); //FIXME: Handle gracefully
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
23 }
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 /* Initiate the connection to the XMPP server */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
26 function start_connection()
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
27 {
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
28 conn = new Strophe.Connection(support_config.bosh_url);
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
29 var ret = true;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
30 try
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
31 {
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
32 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
33 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
34 catch(e)
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 ret = false;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
37 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
38 return ret;
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
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 /*** UI handling */
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 /* 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
45 function on_question_submit()
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
46 {
9
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
47 var question_type = $("#support-question-type").val();
13
7ae5a537d7f1 Fix variable name
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
48 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
49 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
50
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
51 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
52
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
53 // 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
54 var question_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
55 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
56 {
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
57 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
58 team_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
59 }
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
60 });
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
61
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
62 // 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
63 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
64 .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
65 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
66 {
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 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
68 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
69 },
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 function (result) // Failure
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 {
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
72 //FIXME
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 });
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 // 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
76 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
77 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
78 {
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
79 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
80 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
81
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
82 for(var nick in team_muc.occupants)
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
83 team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid);
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
84 },
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
85
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
86 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
87 {
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
88 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
89 {
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
90 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
91 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
92 }
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
93 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
94 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
95 }
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
96 });
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 // Switch to waiting screen
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 $("#support-question").hide();
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 $("#support-wait").show();
7
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
101 }
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
102
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
103 /* Update the UI according to whether we are
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
104 waiting on a network operation
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
105 */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
106 function set_busy_status(status)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
107 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
108 //FIXME
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
109 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
110
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 function display_ui()
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 {
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 // Display pop-up, showing question form
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
114 if(start_connection())
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
115 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
116 $("#support-chat").show();
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
117 $("#support-question-submit").click(on_question_submit);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
118 }
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 }
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 $(display_ui); //FIXME (debugging)

mercurial