@@ -17,7 +17,19 @@ javaxt.express.app.Horizon = function(parent, config) {
1717
1818 var me = this ;
1919 var defaultConfig = {
20+
21+ /** Name of the application. By default, the name will be used as the
22+ * document title. As a user switches tabs, the tab name will be
23+ * appended to the title.
24+ */
2025 name : "Express" ,
26+
27+ /** Style for individual elements within the component. In addition,
28+ * there is a general "javaxt" config for javaxt-components. This is a
29+ * complex, nested config. See "default.js" in the javaxt-webcontrols.
30+ * Note that you can provide CSS class names or an inline set of css
31+ * style definitions for each components and javaxt subcomponents.
32+ */
2133 style : {
2234 javaxt : javaxt . dhtml . style . default ,
2335 header : {
@@ -39,13 +51,42 @@ javaxt.express.app.Horizon = function(parent, config) {
3951 div : "app-footer"
4052 }
4153 } ,
54+
55+
56+ /** Map of URLs to REST end points
57+ */
4258 url : {
43- user : "user" ,
59+
60+ /** URL to the login service
61+ */
4462 login : "login" ,
63+
64+ /** URL to the logoff service
65+ */
4566 logoff : "logoff" ,
67+
68+ /** URL to the web socket endpoint that is sending CRUD notifications
69+ */
4670 websocket : "/ws"
4771 } ,
72+
73+
74+ /** Used to define the maximum idle time for a user before calling
75+ * logoff(). Units are in milliseconds. Default is false (i.e. no
76+ * auto-logoff).
77+ */
78+ autoLogoff : false ,
79+
80+
81+ /** A shared array of javaxt.dhtml.Window components. All the windows in
82+ * the array are automatically closed when a user logs off or when the
83+ * logoff() method is called. You are encouraged to create your own
84+ * array and pass it to the constructor via this config setting and
85+ * update the array whenever you create a new window.
86+ */
4887 windows : [ ] ,
88+
89+
4990 renderers : {
5091 profileButton : function ( user , profileButton ) { }
5192 }
@@ -70,6 +111,10 @@ javaxt.express.app.Horizon = function(parent, config) {
70111 var tabbar , body ;
71112 var tabs = { } ;
72113 var panels = { } ;
114+ var timers = { } ;
115+
116+ var userInteractions = [ "mousemove" , "click" , "keydown" , "touchmove" ] ;
117+
73118
74119
75120 //**************************************************************************
@@ -172,11 +217,24 @@ javaxt.express.app.Horizon = function(parent, config) {
172217 enablePopstateListener ( ) ;
173218
174219
175- //Create web socket listener
220+ //Watch for user events
221+ enableEventListeners ( ) ;
222+
223+
224+ //Create auto-logoff timer
225+ if ( config . autoLogoff && config . autoLogoff > 0 ) {
226+ timers . logoff = setTimeout ( me . logoff , config . autoLogoff ) ;
227+ }
228+
229+
230+ //Create web socket listener. Note that the listener is destroyed on logoff()
176231 if ( ! ws ) ws = new javaxt . dhtml . WebSocket ( {
177232 url : config . url . websocket ,
178233 onMessage : function ( msg ) {
179234
235+ try { me . onMessage ( msg ) ; }
236+ catch ( e ) { }
237+
180238 var arr = msg . split ( "," ) ;
181239 var op = arr [ 0 ] ;
182240 var model = arr [ 1 ] ;
@@ -214,11 +272,34 @@ javaxt.express.app.Horizon = function(parent, config) {
214272 connected = false ;
215273 processEvent ( "disconnect" , "WebSocket" , - 1 , - 1 ) ;
216274 }
275+ } ,
276+ onTimeout : function ( ) {
277+ alert ( "Connection lost" ) ;
217278 }
218279 } ) ;
219280 } ;
220281
221282
283+ //**************************************************************************
284+ //** sendMessage
285+ //**************************************************************************
286+ /** Used to send a message to the server via websockets.
287+ */
288+ this . sendMessage = function ( msg ) {
289+ if ( ws ) ws . send ( msg ) ;
290+ } ;
291+
292+
293+ //**************************************************************************
294+ //** onMessage
295+ //**************************************************************************
296+ /** Called whenever a message is recieved from the server via websockets.
297+ * Used the onModelChangeEvent() event listener to receive CRUD events
298+ * specifically.
299+ */
300+ this . onMessage = function ( msg ) { } ;
301+
302+
222303 //**************************************************************************
223304 //** onModelChangeEvent
224305 //**************************************************************************
@@ -240,6 +321,40 @@ javaxt.express.app.Horizon = function(parent, config) {
240321 this . onLogOff = function ( ) { } ;
241322
242323
324+ //**************************************************************************
325+ //** onUserInteration
326+ //**************************************************************************
327+ /** Called whenever a user interacts with the app (mouse click, mouse move,
328+ * keypress, or touch event).
329+ */
330+ this . onUserInteration = function ( e ) { } ;
331+
332+
333+ var onUserInteration = function ( e ) {
334+ me . onUserInteration ( e ) ;
335+
336+
337+ if ( timers . logoff ) {
338+ clearTimeout ( timers . logoff ) ;
339+ timers . logoff = setTimeout ( me . logoff , config . autoLogoff ) ;
340+ } ;
341+ } ;
342+
343+
344+ var enableEventListeners = function ( ) {
345+ userInteractions . forEach ( ( interaction ) => {
346+ document . body . addEventListener ( interaction , onUserInteration ) ;
347+ } ) ;
348+ } ;
349+
350+
351+ var disableEventListeners = function ( ) {
352+ userInteractions . forEach ( ( interaction ) => {
353+ document . body . removeEventListener ( interaction , onUserInteration ) ;
354+ } ) ;
355+ } ;
356+
357+
243358 //**************************************************************************
244359 //** updateUser
245360 //**************************************************************************
@@ -659,12 +774,28 @@ javaxt.express.app.Horizon = function(parent, config) {
659774 waitmask . show ( ) ;
660775 currUser = null ;
661776
777+ //Disable event listeners
778+ disableEventListeners ( ) ;
779+ disablePopstateListener ( ) ;
780+
662781 //Stop websocket listener
663782 if ( ws ) {
664783 ws . stop ( ) ;
665784 ws = null ;
666785 }
667786
787+
788+ //Stop timers
789+ for ( var key in timers ) {
790+ if ( timers . hasOwnProperty ( key ) ) {
791+ var timer = timers [ key ] ;
792+ clearTimeout ( timer ) ;
793+ }
794+ }
795+ timers = { } ;
796+
797+
798+ //Hide all popup windows
668799 hideWindows ( ) ;
669800
670801
@@ -697,8 +828,6 @@ javaxt.express.app.Horizon = function(parent, config) {
697828 }
698829
699830
700- disablePopstateListener ( ) ;
701-
702831
703832 //Logoff
704833 auth . logoff ( function ( ) {
0 commit comments