# HG changeset patch # User Matthew Wild # Date 1270167690 -3600 # Node ID 010783d24970685a185f3e97a38d840b5fe88a37 # Parent 562ff07a3968f13836d55869033568b1a5865d2d Commit the rest of the assistants-offline handling code, now check the affiliations of assistants diff -r 562ff07a3968 -r 010783d24970 src/js/supportchat.js --- a/src/js/supportchat.js Thu Apr 01 16:07:16 2010 +0100 +++ b/src/js/supportchat.js Fri Apr 02 01:21:30 2010 +0100 @@ -8,12 +8,18 @@ "Sales": "sales@support.localhost", "Technical": "technical@support.localhost" }, - send_invites: true + send_invites: true, + offline_support: "support@localhost" }; /*** XMPP handling */ var conn = null; +/*** Query information */ +var question_type; // E.g. "Sales", "Technical" = $("#support-question-type").val(); +var question_name; // Name of the submitter +var question_text; // The query itself + /* Called by Strophe when status of connection changes (from disconnected to connected, vice-versa, etc.) */ @@ -46,7 +52,7 @@ /* Initial UI state */ var ui_state = "question"; -/* Change the UI state (question, wait, converse) */ +/* Called to change the UI state (question, wait, converse) */ function set_ui_state(new_state) { if(ui_state != new_state) @@ -59,9 +65,9 @@ /* Handle the user submitting the question form */ function on_question_submit() { - var question_type = $("#support-question-type").val(); - var question_name = $("#support-question-name").val(); - var question_text = $("#support-question-text").val(); + question_type = $("#support-question-type").val(); + question_name = $("#support-question-name").val(); + question_text = $("#support-question-text").val(); var our_nick = question_name; @@ -113,6 +119,7 @@ // Create the team MUC object (it will be joined after we join the question MUC) var team_muc = new MUC(conn, { + // Someone joined the team MUC joined: function (stanza, muc, nick) { if(nick != our_nick) @@ -121,11 +128,13 @@ var sent = false; for(var nick in team_muc.occupants) { - //FIXME: Check affiliation + var affiliation = $(stanza) + .find("x[xmlns='http://jabber.org/protocol/muc#user']>item") + .attr("affiliation"); + if(affiliation == "none" || nick == our_nick) + continue; sent = true; - if(nick == our_nick) - continue; - else if(support_config.send_invites) + if(support_config.send_invites) team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid); else team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid); @@ -144,7 +153,7 @@ muc.join(support_config.team_rooms[question_type], our_nick); } else - alert("unhandled error: " + error); + alert("unhandled error: " + error); //FIXME } }); } @@ -187,7 +196,7 @@ below: \

\ \ - \ + \ \
\

Thank you. Your question has been submitted \ @@ -209,6 +218,15 @@ if(start_connection()) { $("#support-question-submit").click(on_question_submit); + $("#support-offline-submit-button").click(function () + { + $("#support-offline-form").hide(); + conn.send($msg({to: support_config.offline_support, type: "normal"}) + .c("subject").t("Support query from " + question_name).up() + .c("body").t(question_text + "\n\nReply via email to: "+ + $("#support-offline-email").val())); + $("#support-offline-thanks").show(); + }); ui.dialog({ title:"Live Support", height: 400, @@ -231,4 +249,4 @@ $("[href='#support-chat']").click(display_ui); } -$(activate_links); //FIXME (debugging) +$(activate_links);