Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/LearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/LearningAction.java,v diff -u -r1.13 -r1.14 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/LearningAction.java 2 Jul 2006 00:49:19 -0000 1.13 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/LearningAction.java 10 Jul 2006 04:51:09 -0000 1.14 @@ -57,9 +57,10 @@ * @author * @version * - * @struts.action path="/learning" parameter="dispatch" + * @struts.action path="/learning" parameter="dispatch" scope="request" name="learningForm" * @struts.action-forward name="chat_client" path="tiles:/learning/main" - * @struts.action-forward name="message_page" path="tiles:/generic/message" + * @struts.action-forward name="runOffline" path="tiles:/learning/runOffline" + * @struts.action-forward name="defineLater" path="tiles:/learning/defineLater" */ public class LearningAction extends LamsDispatchAction { @@ -76,7 +77,7 @@ // TODO need to catch exceptions and handle errors. ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, MODE_OPTIONAL); - + Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); @@ -97,23 +98,22 @@ Chat chat = chatSession.getChat(); + // Retrieve the current user + ChatUser chatUser = getCurrentUser(toolSessionID); + // check defineLater if (chat.getDefineLater()) { - request.setAttribute(ChatConstants.ATTR_MESSAGE, getResources(request).getMessage( - "message.defineLaterSet")); - return mapping.findForward("message_page"); + return mapping.findForward("defineLater"); } // check runOffline if (chat.getRunOffline()) { - request.setAttribute(ChatConstants.ATTR_MESSAGE, getResources(request).getMessage( - "message.runOfflineSet")); - return mapping.findForward("message_page"); + request.setAttribute("MODE", mode.toString()); + request.setAttribute("USER_UID", chatUser.getUid()); + request.setAttribute("SESSION_ID", toolSessionID); + return mapping.findForward("runOffline"); } - // Retrieve the current user - ChatUser chatUser = getCurrentUser(toolSessionID); - // Create the room if it doesnt exist if (chatSession.getJabberRoom() == null) { chatService.createJabberRoom(chatSession); @@ -125,7 +125,7 @@ request.setAttribute("PASSWORD", chatUser.getUserId()); request.setAttribute("CONFERENCEROOM", chatSession.getJabberRoom()); request.setAttribute("NICK", chatUser.getJabberNickname()); - request.setAttribute("MODE", "learner"); + request.setAttribute("MODE", mode.toString()); request.setAttribute("USER_UID", chatUser.getUid()); request.setAttribute("SESSION_ID", toolSessionID); request Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/MonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/MonitoringAction.java,v diff -u -r1.13 -r1.14 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/MonitoringAction.java 2 Jul 2006 08:39:53 -0000 1.13 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/MonitoringAction.java 10 Jul 2006 04:51:09 -0000 1.14 @@ -132,53 +132,6 @@ return mapping.findForward("success"); } - public ActionForward openChatClient(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - - // TODO this method is almost a copy of LearningAction.unspecified. - Long toolSessionID = WebUtil.readLongParam(request, - AttributeNames.PARAM_TOOL_SESSION_ID); - - // set up chatService - if (chatService == null) { - chatService = ChatServiceProxy.getChatService(this.getServlet() - .getServletContext()); - } - - // Retreive the session - ChatSession chatSession = chatService - .getSessionBySessionId(toolSessionID); - if (chatSession == null) { - throw new ChatException( - "Cannot retrieve session with toolSessionId" - + toolSessionID); - } - - // Retrieve the current user - ChatUser chatUser = getCurrentUser(toolSessionID); - - // Create the room if it doesnt exist - if (chatSession.getJabberRoom() == null) { - chatService.createJabberRoom(chatSession); - chatService.saveOrUpdateChatSession(chatSession); - } - - // set the teachers visibility - - request.setAttribute("XMPPDOMAIN", Configuration.get(ConfigurationKeys.XMPP_DOMAIN)); - request.setAttribute("USERNAME", chatUser.getUserId()); - request.setAttribute("PASSWORD", chatUser.getUserId()); - request.setAttribute("CONFERENCEROOM", chatSession.getJabberRoom()); - request.setAttribute("NICK", chatUser.getJabberNickname()); - request.setAttribute("MODE", "teacher"); - - request.setAttribute("chatTitle", chatSession.getChat().getTitle()); - request.setAttribute("chatInstructions", chatSession.getChat() - .getInstructions()); - - return mapping.findForward("chat_client"); - } - public ActionForward openChatHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/LearningForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/LearningForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/LearningForm.java 10 Jul 2006 04:51:35 -0000 1.1 @@ -0,0 +1,76 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ + +package org.lamsfoundation.lams.tool.chat.web.forms; + +import org.apache.struts.action.ActionForm; + +/** + * + * @author Anthony Sukkar + * + * @struts.form name="learningForm" + */ +public class LearningForm extends ActionForm { + + private static final long serialVersionUID = -4728946254882237144L; + + String dispatch; + Long chatUserUID; + Long toolSessionID; + String mode; + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } + + public Long getChatUserUID() { + return chatUserUID; + } + + public void setChatUserUID(Long chatUserUID) { + this.chatUserUID = chatUserUID; + } + + public String getDispatch() { + return dispatch; + } + + public void setDispatch(String dispatch) { + this.dispatch = dispatch; + } + + public Long getToolSessionID() { + return toolSessionID; + } + + public void setToolSessionID(Long toolSessionID) { + this.toolSessionID = toolSessionID; + } +} Index: lams_tool_chat/web/WEB-INF/struts/tiles-defs.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/WEB-INF/struts/Attic/tiles-defs.xml,v diff -u -r1.13 -r1.14 --- lams_tool_chat/web/WEB-INF/struts/tiles-defs.xml 6 Jul 2006 04:40:53 -0000 1.13 +++ lams_tool_chat/web/WEB-INF/struts/tiles-defs.xml 10 Jul 2006 04:51:09 -0000 1.14 @@ -31,11 +31,11 @@ - + - + @@ -59,6 +59,7 @@ --> + @@ -80,10 +81,19 @@ - - + + + + + + + + + + + @@ -97,7 +107,7 @@ - + Fisheye: Tag 1.11 refers to a dead (removed) revision in file `lams_tool_chat/web/chat_client/chat_app.js'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.5 refers to a dead (removed) revision in file `lams_tool_chat/web/chat_client/chat_style.css'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.10 refers to a dead (removed) revision in file `lams_tool_chat/web/chat_client/chat_ui.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_chat/web/common/header.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/common/header.jsp,v diff -u -r1.8 -r1.9 --- lams_tool_chat/web/common/header.jsp 23 May 2006 04:51:37 -0000 1.8 +++ lams_tool_chat/web/common/header.jsp 10 Jul 2006 04:51:09 -0000 1.9 @@ -11,7 +11,7 @@ <bean:message key="activity.title" /> - + Index: lams_tool_chat/web/pages/learning/chat_app.js =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/learning/Attic/chat_app.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/learning/chat_app.js 10 Jul 2006 04:51:09 -0000 1.1 @@ -0,0 +1,298 @@ +// Constants +var GROUPCHAT_MSG = "groupchat_message"; +var PRIVATE_MSG = "private_message"; +var colours = ["#0000FF", "#006699", "#0066FF", "#6633FF", "#00CCFF", "#009900", "#00CC33", "#339900", "#008080", "#66FF66", "#CC6600", "#FF6600", "#FF9900", "#CC6633", "#FF9933", "#990000", "#A50021", "#990033", "#CC3300", "#FF6666", "#330033", "#663399", "#6633CC", "#660099", "#FF00FF", "#999900", "#808000", "#FFFF00", "#666633", "#292929", "#666666"]; + +// Variables +var roster = new Roster(); + +// Helper functions +function htmlEnc(str) { + if (!str) { + return null; + } + str = str.replace(/&/g, "&"); + str = str.replace(//g, ">"); + str = str.replace(/\"/g, """); + str = str.replace(/\n/g, "
"); + return str; +} +function getColour(nick) { + var charSum = 0; + for (var i = 0; i < nick.length; i++) { + charSum += nick.charCodeAt(i); + } + return colours[charSum % (colours.length)]; +} + +// creates a new element. +function createElem(name, attrs, style, text) { + var e = document.createElement(name); + if (attrs) { + for (key in attrs) { + if (key == "attrClass") { + e.className = attrs[key]; + } else { + if (key == "attrId") { + e.id = attrs[key]; + } else { + e.setAttribute(key, attrs[key]); + } + } + } + } + if (style) { + for (key in style) { + e.style[key] = style[key]; + } + } + if (text) { + e.appendChild(document.createTextNode(text)); + } + return e; + +} + +// Roster +function RosterUser(nick) { + this.nick = nick; + this.status = "unavailable"; +} +function getRosterUserByNick(nick) { + for (var i = 0; i < roster.users.length; i++) { + if (roster.users[i].nick == nick) { + return roster.users[i]; + } + } +} +function AddRosterUser(user) { + roster.users[roster.users.length] = user; +} +function UpdateRosterUser(user) { +} +function RemoveRosterUser() { +} +function updateRosterDisplay() { + var oSelect = document.getElementById("roster_user_selector"); + oSelect.innerHTML = ""; + var oOption; + var nick; + for (var i = 0; i < roster.users.length; i++) { + if (roster.users[i].status != "unavailable") { + nick = roster.users[i].nick; + oOption = new Option(nick, nick); + oSelect.options[oSelect.options.length] = oOption; + } + } +} +function Roster() { + this.users = []; + // objects methods + this.getUserByNick = getRosterUserByNick; + this.addUser = AddRosterUser; + this.updateUser = UpdateRosterUser; + this.removeUser = RemoveRosterUser; + this.updateDisplay = updateRosterDisplay; +} +function resetInputs() { + document.getElementById("roster_user_selector").selectedIndex = -1; + updateSendDisplay(); +} +function updateSendDisplay() { + var rosterList = document.getElementById("roster_user_selector"); + var selectedIndex = rosterList.selectedIndex; + if (MODE == "teacher" && !(selectedIndex == -1)) { + var userName = rosterList.options[rosterList.selectedIndex].value; + document.getElementById("sendToUser").innerHTML = "" + userName + ""; + document.getElementById("sendToEveryone").style.display = "none"; + document.getElementById("sendToUser").style.display = ""; + } else { + document.getElementById("sendToUser").style.display = "none"; + document.getElementById("sendToEveryone").style.display = ""; + } +} +function generateMessageHTML(nick, message, type) { + var colour = getColour(nick); + var fromElem = createElem("span", {attrClass: "messageFrom"}, {color: colour}, nick); + var msgElem = createElem("div", {attrClass: "message " + type}, {color: colour}, null); + + msgElem.innerHTML = message; + msgElem.insertBefore(document.createElement("br"), msgElem.firstChild ); + msgElem.insertBefore(fromElem, msgElem.firstChild); + + return msgElem; +} +function updateMessageDisplay(htmlMessage) { + var iRespDiv = document.getElementById("iResp"); + iRespDiv.appendChild(htmlMessage); + iRespDiv.scrollTop = iRespDiv.scrollHeight; +} +// Event handlers +function handleEvent(aJSJaCPacket) { + document.getElementById("iResp").innerHTML += "IN (raw):
" + htmlEnc(aJSJaCPacket.xml()) + "
"; +} +function handleMessage(aJSJaCPacket) { + var nick = aJSJaCPacket.getFrom().substring(aJSJaCPacket.getFrom().indexOf("/") + 1); + var message = htmlEnc(aJSJaCPacket.getBody()); + var type = aJSJaCPacket.getType(); + var htmlMessage; + if (type == "chat") { + htmlMessage = generateMessageHTML(nick, message, PRIVATE_MSG); + } else { + if (type == "groupchat") { + htmlMessage = generateMessageHTML(nick, message, GROUPCHAT_MSG); + } else { + /* somethings wrong, dont add anything.*/ + htmlMessage = ""; + } + } + updateMessageDisplay(htmlMessage); +} +function handlePresence(presence) { + var from = presence.getFrom(); + var status = presence.getStatus(); + var show = presence.getShow(); + var type = presence.getType(); + // get x element for MUC + var x; + for (var i = 0; i < presence.getNode().getElementsByTagName("x").length; i++) { + if (presence.getNode().getElementsByTagName("x").item(i).getAttribute("xmlns") == "http://jabber.org/protocol/muc#user") { + x = presence.getNode().getElementsByTagName("x").item(i); + break; + } + } + + // extract nick. + var nick; + if (from.indexOf("/") != -1) { + nick = from.substring(from.indexOf("/") + 1); + } + var user = roster.getUserByNick(nick); + if (!user) { + user = new RosterUser(nick); + roster.addUser(user); + } + if (show) { + user.status = show; + } else { + if (type) { + if (type == "unavailable") { + user.status = "unavailable"; + } + } else { + // default: means presence is available. + user.status = "available"; + } + } + roster.updateUser(user); + roster.updateDisplay(); + updateSendDisplay(); +} +function handleConnected() { + document.getElementById("login_pane").style.display = "none"; + document.getElementById("chat_pane").style.display = ""; + if (MODE == "learner") { + if (LEARNER_FINISHED == "true") { + if (LOCK_ON_FINISHED == "true") { + // disable sending messages. + document.getElementById("msgArea").disabled = "disabled"; + document.getElementById("sendButton").disabled = "disabled"; + document.getElementById("clearButton").disabled = "disabled"; + } + } else { + document.getElementById("finishButton_pane").style.display = ""; + } + } + + // send presence + var aPresence = new JSJaCPresence(); + aPresence.setTo(CONFERENCEROOM + "/" + NICK); + aPresence.setFrom(USERNAME + "@" + XMPPDOMAIN); + var x = aPresence.getDoc().createElement("x"); + x.setAttribute("xmlns", "http://jabber.org/protocol/muc"); + x.appendChild(aPresence.getDoc().createElement("password")).appendChild(aPresence.getDoc().createTextNode(PASSWORD)); + aPresence.getNode().appendChild(x); + con.send(aPresence); + + // set up roster + roster = new Roster(); +} +function handleError(e) { + document.getElementById("loading_message").style.display = "none"; + document.getElementById("login_err").innerHTML = "Couldn't connect. Please try again...
" + htmlEnc("Code: " + e.getAttribute("code") + "\nType: " + e.getAttribute("type") + "\nCondition: " + e.firstChild.nodeName); + document.getElementById("finishButton_pane").style.display = ""; +} +function doLogin() { + try { + + // setup args for contructor + oArgs = new Object(); + oArgs.httpbase = HTTPBASE; + oArgs.timerval = 2000; + if (typeof (oDbg) != "undefined") { + oArgs.oDbg = oDbg; + } + con = new JSJaCHttpBindingConnection(oArgs); + con.registerHandler("message", handleMessage); + con.registerHandler("presence", handlePresence); + con.registerHandler("iq", handleEvent); + con.registerHandler("onconnect", handleConnected); + con.registerHandler("onerror", handleError); + + // setup args for connect method + oArgs = new Object(); + oArgs.domain = XMPPDOMAIN; + oArgs.username = USERNAME; + oArgs.resource = RESOURCE; + oArgs.pass = PASSWORD; + con.connect(oArgs); + } + catch (e) { + document.getElementById("login_err").innerHTML = e.toString(); + document.getElementById("finishButton_pane").style.display = ""; + } + finally { + return false; + } +} +function sendMsg(aForm) { + var aMsg = new JSJaCMessage(); + var rosterList = document.getElementById("roster_user_selector"); + var selectedIndex = rosterList.selectedIndex; + if (MODE == "teacher" && !(selectedIndex == -1)) { + var toNick = rosterList.options[selectedIndex].value; + aMsg.setTo(CONFERENCEROOM + "/" + toNick); + aMsg.setType("chat"); + // apending the private message to the incoming window, + // since the jabber server will not echo sent private messages. + // TODO: need to check if this is correct behaviour + if (!(NICK == toNick)) { + updateMessageDisplay(generateMessageHTML(NICK, aForm.msg.value, PRIVATE_MSG)); + } + } else { + aMsg.setTo(CONFERENCEROOM); + aMsg.setType("groupchat"); + } + + // } + aMsg.setFrom(USERNAME + "@" + XMPPDOMAIN + "/" + RESOURCE); + aMsg.setBody(aForm.msg.value); + con.send(aMsg); + aForm.msg.value = ""; + return false; +} +function init() { + if (typeof (Debugger) == "function") { + oDbg = new Debugger(4, "simpleclient"); + oDbg.start(); + } + doLogin(); +} +onload = init; +onunload = function () { + if (typeof (con) != "undefined" && con.disconnect) { + con.disconnect(); + } +}; + Index: lams_tool_chat/web/pages/learning/chat_style.css =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/learning/Attic/chat_style.css,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/learning/chat_style.css 10 Jul 2006 04:51:08 -0000 1.1 @@ -0,0 +1,57 @@ +#chat_content { + width: 560px; + padding: 12px; + + /* compensate for content image border */ + margin-left: 4px; +} + +#chat_pane { + width: 98%; +} + +#iResp { + height: 260px; + margin-right: 12px; + margin-left: 12px; + overflow: scroll; + + background-color: white; + border: thin solid black; +} + +.message { + padding-bottom: 4px; +} + +.private_message { + font-style: italic; + background-color: #e6e6fa; +} + +.messageFrom { + font-weight: bold; +} + +#presence { + float: right; + width: 160px; + height: 260px; + overflow: hidden; +} + +#roster_user_selector { + width: 100%; + height: 100%; +} + +#msgArea { + margin-left: 12px; + margin-right: 12px; + width: 532px; + height: 100%; +} + +#finishButton_pane { + +} \ No newline at end of file Index: lams_tool_chat/web/pages/learning/chat_ui.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/learning/Attic/chat_ui.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/learning/chat_ui.jsp 10 Jul 2006 04:51:09 -0000 1.1 @@ -0,0 +1,94 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + + + + + + + + + + + + +

+ +

+
+
+
+ +
+
+

+ message.loading +

+
+
+
+ + + + +
+
+ + + Index: lams_tool_chat/web/pages/learning/defineLater.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/learning/defineLater.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/learning/defineLater.jsp 10 Jul 2006 04:51:09 -0000 1.1 @@ -0,0 +1,21 @@ +<%@ include file="/common/taglibs.jsp"%> + +

+ +

+
+
+ + + + +
+ message.defineLaterSet +
+ +
+ +
+
+ + Index: lams_tool_chat/web/pages/learning/runOffline.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/learning/Attic/runOffline.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/learning/runOffline.jsp 10 Jul 2006 04:51:09 -0000 1.1 @@ -0,0 +1,30 @@ +<%@ include file="/common/taglibs.jsp"%> + +

+ +

+
+
+ + + + +
+ +
+ + + +
+ + + + + button.finish + +
+
+
+
+
+ Index: lams_tool_chat/web/pages/monitoring/summary.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/monitoring/summary.jsp,v diff -u -r1.6 -r1.7 --- lams_tool_chat/web/pages/monitoring/summary.jsp 2 Jul 2006 08:39:53 -0000 1.6 +++ lams_tool_chat/web/pages/monitoring/summary.jsp 10 Jul 2006 04:51:54 -0000 1.7 @@ -67,15 +67,12 @@ - - + + summary.openChat - - -