01: /*
02: *
03: * Copyright 2005 Joe Walker
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package uk.ltd.getahead.dwrdemo.livehelp;
19:
20: import java.util.Collection;
21:
22: import org.directwebremoting.Security;
23: import org.directwebremoting.WebContext;
24: import org.directwebremoting.WebContextFactory;
25: import org.directwebremoting.proxy.dwr.Util;
26: import org.directwebremoting.util.Logger;
27:
28: /**
29: * A simple shared input form that several users can share
30: * @author Joe Walker [joe at getahead dot ltd dot uk]
31: */
32: public class LiveHelp {
33: /**
34: * Something has changed
35: * @param id The id of the field that changed
36: * @param value The new value
37: */
38: public void notifyTyping(String id, String value) {
39: Util utilAll = new Util(getUsersToAffect());
40:
41: utilAll.setValue(id, Security.replaceXmlCharacters(value));
42: }
43:
44: /**
45: * The user has tabbed in
46: * @param id The id of the field that changed
47: */
48: public void notifyFocus(String id) {
49: Util utilAll = new Util(getUsersToAffect());
50:
51: utilAll.addClassName(id, "disabled");
52: String addr = WebContextFactory.get().getHttpServletRequest()
53: .getRemoteAddr();
54: utilAll.setValue(id + "Tip", addr);
55:
56: //utilAll.addScript("$('" + id + "').disabled = true;");
57: }
58:
59: /**
60: * The user has tabbed out
61: * @param id The id of the field that changed
62: */
63: public void notifyBlur(String id) {
64: Util utilAll = new Util(getUsersToAffect());
65:
66: utilAll.removeClassName(id, "disabled");
67: utilAll.setValue(id + "Tip", "");
68:
69: //utilAll.addScript("$('" + id + "').disabled = false;");
70: }
71:
72: /**
73: * @return The collection of people to affect
74: */
75: private Collection getUsersToAffect() {
76: WebContext wctx = WebContextFactory.get();
77: String currentPage = wctx.getCurrentPage();
78:
79: // For all the browsers on the current page:
80: Collection sessions = wctx.getScriptSessionsByPage(currentPage);
81:
82: // But not the current user!
83: sessions.remove(wctx.getScriptSession());
84:
85: log.debug("Affecting " + sessions.size() + " users");
86:
87: return sessions;
88: }
89:
90: /**
91: * The log stream
92: */
93: private static final Logger log = Logger.getLogger(LiveHelp.class);
94: }
|