Commit the rest of the assistants-offline handling code, now check the affiliations of assistants

Fri, 02 Apr 2010 01:21:30 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 02 Apr 2010 01:21:30 +0100
changeset 37
010783d24970
parent 36
562ff07a3968
child 38
536e0a618d4a

Commit the rest of the assistants-offline handling code, now check the affiliations of assistants

src/js/supportchat.js file | annotate | diff | comparison | revisions
--- 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: \
 				</p> \
 				<input id="support-offline-email" type="text" /> \
-				<input id="support-send-button" type="submit" value="Submit" /> \
+				<input id="support-offline-submit-button" type="submit" value="Submit" /> \
 			</div> \
 			<div id="support-offline-thanks"> \
 				<p>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);

mercurial