js/supportchat.js

changeset 12
7b0df9aad29c
parent 9
6677316d8834
child 13
7ae5a537d7f1
equal deleted inserted replaced
11:bf6a0898e613 12:7b0df9aad29c
1 /* Config */
2 var LOGIN_DOMAIN = "anon.localhost";
3 var BOSH_URL = "/http-bind";
4
5 /*** Helper functions */
6
7 /*** XMPP handling */
8 var conn = null;
9
10 /* Called by Strophe when status of connection changes
11 (from disconnected to connected, vice-versa, etc.)
12 */
13 function handle_connection_status(status, err)
14 {
15 if(status != Strophe.Status.CONNECTING && status != Strophe.Status.AUTHENTICATING)
16 set_busy_status(false);
17 else if(status != Strophe.Status.CONNECTED)
18 set_busy_status(true);
19
20 if(err)
21 alert(err); //FIXME: Handle gracefully
22
23 if(status == Strophe.Status.CONNECTED)
24 {
25 //FIXME: Join MUC
26 alert("Connected!");
27 }
28 }
29
30 /* Initiate the connection to the XMPP server */
31 function start_connection()
32 {
33 conn = new Strophe.Connection(BOSH_URL);
34 var ret = true;
35 try
36 {
37 conn.connect(LOGIN_DOMAIN, null, handle_connection_status, 50);
38 }
39 catch(e)
40 {
41 ret = false;
42 }
43 return ret;
44 }
45
46
47 /*** UI handling */
48
49 /* Handle the user submitting the question form */
1 function on_question_submit() 50 function on_question_submit()
2 { 51 {
3 var question_type = $("#support-question-type").val(); 52 var question_type = $("#support-question-type").val();
4 var question_submitter = $("#support-question-name").val(); 53 var question_submitter = $("#support-question-name").val();
5 var question_text = $("#support-question-text").val(); 54 var question_text = $("#support-question-text").val();
6 55
7 alert(question_name + " submitted a " + question_type + " question:\n " + question_text); 56 alert(question_name + " submitted a " + question_type + " question:\n " + question_text);
8 } 57 }
9 58
59 /* Update the UI according to whether we are
60 waiting on a network operation
61 */
62 function set_busy_status(status)
63 {
64 //FIXME
65 }
66
10 function display_ui() 67 function display_ui()
11 { 68 {
12 // Display pop-up, showing question form 69 // Display pop-up, showing question form
13 $("#support-chat").show(); 70 if(start_connection())
14 $("#support-question-submit").click(on_question_submit); 71 {
72 $("#support-chat").show();
73 $("#support-question-submit").click(on_question_submit);
74 }
15 } 75 }
16 76
17 $(display_ui); //FIXME (debugging) 77 $(display_ui); //FIXME (debugging)

mercurial