@@ -48,7 +48,10 @@ javaxt.express.app.Horizon = function(parent, config) {
4848 //"Home": com.acme.DashboardPanel,
4949 //"Admin": com.acme.AdminPanel
5050 } ,
51- windows : [ ]
51+ windows : [ ] ,
52+ renderers : {
53+ profileButton : function ( user , profileButton ) { }
54+ }
5255 } ;
5356
5457 var waitmask ;
@@ -130,9 +133,20 @@ javaxt.express.app.Horizon = function(parent, config) {
130133 //** update
131134 //**************************************************************************
132135 this . update = function ( user ) {
136+
137+ //Update title
138+ document . title = config . name ;
139+
140+
141+ //Update user
142+ var prevUserID = currUser ? currUser . id : null ;
133143 updateUser ( user ) ;
144+ if ( user . id === prevUserID ) return ;
134145
135146
147+ //Watch for forward and back events via a 'popstate' listener
148+ enablePopstateListener ( ) ;
149+
136150
137151 //Create web socket listener
138152 if ( ! ws ) ws = new javaxt . dhtml . WebSocket ( {
@@ -181,19 +195,38 @@ javaxt.express.app.Horizon = function(parent, config) {
181195 } ;
182196
183197
198+ //**************************************************************************
199+ //** onModelChangeEvent
200+ //**************************************************************************
201+ /** Called whenever a Model created, updated, or deleted.
202+ * @param op Operation name. Options include "create", "update", or "delete"
203+ * @param model The name of the model that was changed (e.g. "User").
204+ * @param id The unique identifier associated with the model (e.g. 12345)
205+ * @param userID The unique identifier associated with the user that's
206+ * responsible for the change.
207+ */
208+ this . onModelChangeEvent = function ( op , model , id , userID ) { } ;
209+
210+
211+ //**************************************************************************
212+ //** onLogOff
213+ //**************************************************************************
214+ /** Called after the logoff() method is complete.
215+ */
216+ this . onLogOff = function ( ) { } ;
217+
218+
184219 //**************************************************************************
185220 //** updateUser
186221 //**************************************************************************
187222 var updateUser = function ( user ) {
188223 currUser = user ;
189- document . title = config . name + " - Home" ;
190- if ( user . person ) {
191- profileButton . innerHTML = user . person . firstName . substring ( 0 , 1 ) ;
192- }
193224
194225
195- //Watch for forward and back events via a 'popstate' listener
196- enablePopstateListener ( ) ;
226+ //Update the profile button
227+ if ( config . renderers . profileButton ) {
228+ config . renderers . profileButton ( user , profileButton ) ;
229+ }
197230
198231
199232 //Show/hide admin tab
@@ -228,7 +261,7 @@ javaxt.express.app.Horizon = function(parent, config) {
228261 tabs [ currTab ] . click ( ) ;
229262 }
230263 else {
231- tabs [ "Home" ] . click ( ) ;
264+ Object . values ( tabs ) [ 0 ] . click ( ) ;
232265 }
233266 } ) ;
234267
@@ -274,24 +307,7 @@ javaxt.express.app.Horizon = function(parent, config) {
274307 }
275308 }
276309 else {
277- if ( id === document . user . id ) {
278- if ( model === "User" ) {
279- if ( op === "delete" ) {
280- logoff ( ) ;
281- return ;
282- }
283- else if ( op === "update" ) {
284- get ( config . url . user + "?id=" + id , {
285- success : function ( text ) {
286- var user = JSON . parse ( text ) ;
287- document . user = merge ( user , document . user ) ;
288- if ( document . user . status !== 1 ) logoff ( ) ;
289- else updateUser ( document . user ) ;
290- }
291- } ) ;
292- }
293- }
294- }
310+ me . onModelChangeEvent ( op , model , id , userID ) ;
295311 }
296312
297313
@@ -387,7 +403,7 @@ javaxt.express.app.Horizon = function(parent, config) {
387403 this . className = "active" ;
388404 fn . apply ( me , [ ] ) ;
389405 document . title = config . name + " - " + label ;
390- document . user . preferences . set ( "Tab" , label ) ;
406+ if ( currUser ) currUser . preferences . set ( "Tab" , label ) ;
391407 } ;
392408
393409
@@ -505,7 +521,7 @@ javaxt.express.app.Horizon = function(parent, config) {
505521 console . log ( "Show Accout" ) ;
506522 } ) ) ;
507523 div . appendChild ( createMenuOption ( "Sign Out" , "times" , function ( ) {
508- logoff ( ) ;
524+ me . logoff ( ) ;
509525 } ) ) ;
510526 profileMenu = div ;
511527 }
@@ -604,7 +620,7 @@ javaxt.express.app.Horizon = function(parent, config) {
604620 //**************************************************************************
605621 //** logoff
606622 //**************************************************************************
607- var logoff = function ( ) {
623+ this . logoff = function ( ) {
608624 waitmask . show ( ) ;
609625 currUser = null ;
610626
@@ -644,7 +660,7 @@ javaxt.express.app.Horizon = function(parent, config) {
644660
645661 //Logoff
646662 auth . logoff ( function ( ) {
647- document . user = null ;
663+ me . onLogOff ( ) ;
648664 var pageLoader = new javaxt . dhtml . PageLoader ( ) ;
649665 pageLoader . loadPage ( "index.html" , function ( ) {
650666 waitmask . hide ( ) ;
@@ -678,7 +694,6 @@ javaxt.express.app.Horizon = function(parent, config) {
678694 var createTable = javaxt . dhtml . utils . createTable ;
679695 var addShowHide = javaxt . dhtml . utils . addShowHide ;
680696 var merge = javaxt . dhtml . utils . merge ;
681- var get = javaxt . dhtml . utils . get ;
682697
683698
684699 init ( ) ;
0 commit comments