1 /* Config */ |
1 /* Config */ |
2 |
2 |
3 var support_config = { |
3 var support_config = { |
4 login_domain: "anon.localhost", |
4 login_domain: "anon.localhost", |
5 bosh_url: "/http-bind", |
5 bosh_url: "/http-bind", |
|
6 muc_server: "support.localhost", |
6 team_rooms: { |
7 team_rooms: { |
7 "Sales": "sales@support.localhost", |
8 "Sales": "sales@support.localhost", |
8 "Technical": "technical@support.localhost" |
9 "Technical": "technical@support.localhost" |
9 } |
10 } |
10 }; |
11 }; |
50 { |
51 { |
51 var question_type = $("#support-question-type").val(); |
52 var question_type = $("#support-question-type").val(); |
52 var question_name = $("#support-question-name").val(); |
53 var question_name = $("#support-question-name").val(); |
53 var question_text = $("#support-question-text").val(); |
54 var question_text = $("#support-question-text").val(); |
54 |
55 |
55 alert(question_name + " submitted a " + question_type + " question:\n " + question_text); |
56 var our_nick = question_name; |
|
57 |
|
58 // Create our question room |
|
59 var question_muc = new MUC(conn, { |
|
60 joined: function (stanza, muc, nick) |
|
61 { |
|
62 if(nick == our_nick) |
|
63 team_muc.join(support_config.team_rooms[question_type], our_nick); |
|
64 } |
|
65 }); |
|
66 |
|
67 // Get a unique room name from the server and then join the question MUC |
|
68 conn.sendIQ($iq({to: support_config.muc_server, type: "get"}) |
|
69 .c("query", { xmlns: "http://jabber.org/protocol/muc#unique" }), |
|
70 function (result) // Success |
|
71 { |
|
72 var unique = Strophe.getText(result.getElementsByTagName("unique")[0]); |
|
73 question_muc.join(unique + "@" + support_config.muc_server, our_nick); |
|
74 }, |
|
75 function (result) // Failure |
|
76 { |
|
77 //FIXME |
|
78 }); |
|
79 |
|
80 // Create the team MUC object (it will be joined after we join the question MUC) |
|
81 var team_muc = new MUC(conn, { |
|
82 joined: function (stanza, muc, nick) |
|
83 { |
|
84 if(nick != our_nick) |
|
85 return; |
|
86 |
|
87 for(var nick in team_muc.occupants) |
|
88 team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid); |
|
89 }, |
|
90 |
|
91 error: function (stanza, muc, error) |
|
92 { |
|
93 if(error == "conflict") |
|
94 { |
|
95 our_nick += "_"; |
|
96 muc.join(support_config.team_rooms[question_type], our_nick); |
|
97 } |
|
98 else |
|
99 alert("unhandled error: " + error); |
|
100 } |
|
101 }); |
|
102 |
|
103 // Switch to waiting screen |
|
104 $("#support-question").hide(); |
|
105 $("#support-wait").show(); |
56 } |
106 } |
57 |
107 |
58 /* Update the UI according to whether we are |
108 /* Update the UI according to whether we are |
59 waiting on a network operation |
109 waiting on a network operation |
60 */ |
110 */ |