@@ -27,7 +27,7 @@ Class.create("ActionsManager", {
27
27
* Standard constructor
28
28
* @param bUsersEnabled Boolen Whether users management is enabled or not
29
29
*/
30
- initialize : function ( bUsersEnabled )
30
+ initialize : function ( bUsersEnabled , dataModel )
31
31
{
32
32
this . _registeredKeys = new Hash ( ) ;
33
33
this . _actions = new Hash ( ) ;
@@ -37,29 +37,58 @@ Class.create("ActionsManager", {
37
37
this . subMenus = [ ] ;
38
38
this . actions = new Hash ( ) ;
39
39
this . defaultActions = new Hash ( ) ;
40
- this . toolbars = new Hash ( ) ;
41
- document . observe ( "ajaxplorer:context_changed" , function ( event ) {
42
- window . setTimeout ( function ( ) {
43
- this . fireContextChange ( ) ;
44
- } . bind ( this ) , 0 ) ;
45
- } . bind ( this ) ) ;
46
-
47
- document . observe ( "ajaxplorer:selection_changed" , function ( event ) {
48
- window . setTimeout ( function ( ) {
49
- this . fireSelectionChange ( ) ;
50
- } . bind ( this ) , 0 ) ;
51
- } . bind ( this ) ) ;
52
-
53
- document . observe ( "ajaxplorer:user_logged" , function ( event ) {
54
- if ( event . memo && event . memo . getPreference ) {
55
- this . setUser ( event . memo ) ;
56
- } else {
57
- this . setUser ( null ) ;
58
- }
59
- } . bind ( this ) ) ;
60
-
40
+ this . toolbars = new Hash ( ) ;
41
+ if ( dataModel ) {
42
+ this . _dataModel = dataModel ;
43
+ }
44
+ this . contextChangedObs = function ( event ) {
45
+ window . setTimeout ( function ( ) {
46
+ this . fireContextChange ( ) ;
47
+ } . bind ( this ) , 0 ) ;
48
+ } . bind ( this ) ;
49
+ this . selectionChangedObs = function ( event ) {
50
+ window . setTimeout ( function ( ) {
51
+ this . fireSelectionChange ( ) ;
52
+ } . bind ( this ) , 0 ) ;
53
+ } . bind ( this ) ;
54
+
55
+ if ( this . _dataModel ) {
56
+ this . _dataModel . observe ( "context_changed" , this . contextChangedObs ) ;
57
+ this . _dataModel . observe ( "selection_changed" , this . selectionChangedObs ) ;
58
+ this . localDataModel = true ;
59
+ } else {
60
+ document . observe ( "ajaxplorer:context_changed" , this . contextChangedObs ) ;
61
+ document . observe ( "ajaxplorer:selection_changed" , this . selectionChangedObs ) ;
62
+ this . _dataModel = ajaxplorer . getContextHolder ( ) ;
63
+ this . localDataModel = false ;
64
+ }
65
+
66
+ if ( this . usersEnabled ) {
67
+ document . observe ( "ajaxplorer:user_logged" , function ( event ) {
68
+ if ( event . memo && event . memo . getPreference ) {
69
+ this . setUser ( event . memo ) ;
70
+ } else {
71
+ this . setUser ( null ) ;
72
+ }
73
+ } . bind ( this ) ) ;
74
+ if ( ajaxplorer . user ) {
75
+ this . setUser ( ajaxplorer . user ) ;
76
+ }
77
+ }
78
+
61
79
} ,
62
-
80
+
81
+ getDataModel :function ( ) {
82
+ return this . _dataModel ;
83
+ } ,
84
+
85
+ destroy : function ( ) {
86
+ if ( this . localDataModel && this . _dataModel ) {
87
+ this . _dataModel . stopObserving ( "context_changed" , this . contextChangedObs ) ;
88
+ this . _dataModel . stopObserving ( "selection_changed" , this . selectionChangedObs ) ;
89
+ }
90
+ } ,
91
+
63
92
/**
64
93
* Stores the currently logged user object
65
94
* @param oUser User User instance
@@ -112,7 +141,7 @@ Class.create("ActionsManager", {
112
141
var isDefault = false ;
113
142
if ( actionsSelectorAtt == 'selectionContext' ) {
114
143
// set default in bold
115
- var userSelection = ajaxplorer . getUserSelection ( ) ;
144
+ var userSelection = this . _dataModel ;
116
145
if ( ! userSelection . isEmpty ( ) ) {
117
146
var defaultAction = 'file' ;
118
147
if ( userSelection . isUnique ( ) && ( userSelection . hasDir ( ) || userSelection . hasMime ( [ 'ajxp_browsable_archive' ] ) ) ) {
@@ -283,7 +312,7 @@ Class.create("ActionsManager", {
283
312
( copy && ( ! this . defaultActions . get ( 'ctrldragndrop' ) || this . getDefaultAction ( 'ctrldragndrop' ) . deny ) ) ) {
284
313
return ;
285
314
}
286
- if ( fileName == null ) fileNames = ajaxplorer . getUserSelection ( ) . getFileNames ( ) ;
315
+ if ( fileName == null ) fileNames = this . _dataModel . getFileNames ( ) ;
287
316
else fileNames = [ fileName ] ;
288
317
if ( destNodeName != null )
289
318
{
@@ -302,7 +331,7 @@ Class.create("ActionsManager", {
302
331
}
303
332
}
304
333
// Check that dest is not the direct parent of source, ie current rep!
305
- if ( destDir == ajaxplorer . getContextNode ( ) . getPath ( ) ) {
334
+ if ( destDir == this . _dataModel . getContextNode ( ) . getPath ( ) ) {
306
335
if ( destNodeName != null ) ajaxplorer . displayMessage ( 'ERROR' , MessageHash [ 203 ] ) ;
307
336
return ;
308
337
}
@@ -314,7 +343,7 @@ Class.create("ActionsManager", {
314
343
}
315
344
connexion . addParameter ( 'nodes[]' , fileNames ) ;
316
345
connexion . addParameter ( 'dest' , destDir ) ;
317
- connexion . addParameter ( 'dir' , ajaxplorer . getContextNode ( ) . getPath ( ) ) ;
346
+ connexion . addParameter ( 'dir' , this . _dataModel . getContextNode ( ) . getPath ( ) ) ;
318
347
connexion . onComplete = function ( transport ) { this . parseXmlMessage ( transport . responseXML ) ; } . bind ( this ) ;
319
348
connexion . sendAsync ( ) ;
320
349
} ,
@@ -374,8 +403,8 @@ Class.create("ActionsManager", {
374
403
if ( fElement . type == 'radio' && ! fElement . checked ) return ;
375
404
connexion . addParameter ( fElement . name , fValue ) ;
376
405
} ) ;
377
- if ( ajaxplorer . getContextNode ( ) ) {
378
- connexion . addParameter ( 'dir' , ajaxplorer . getContextNode ( ) . getPath ( ) ) ;
406
+ if ( this . _dataModel . getContextNode ( ) ) {
407
+ connexion . addParameter ( 'dir' , this . _dataModel . getContextNode ( ) . getPath ( ) ) ;
379
408
}
380
409
if ( completeCallback ) {
381
410
connexion . onComplete = completeCallback ;
@@ -418,9 +447,9 @@ Class.create("ActionsManager", {
418
447
} else {
419
448
var file = childs [ i ] . getAttribute ( 'file' ) ;
420
449
if ( file ) {
421
- ajaxplorer . getContextHolder ( ) . setPendingSelection ( file ) ;
450
+ this . _dataModel . setPendingSelection ( file ) ;
422
451
}
423
- reloadNodes . push ( ajaxplorer . getContextNode ( ) ) ;
452
+ reloadNodes . push ( this . _dataModel . getContextNode ( ) ) ;
424
453
}
425
454
}
426
455
else if ( obName == 'repository_list' )
@@ -429,7 +458,7 @@ Class.create("ActionsManager", {
429
458
}
430
459
}
431
460
else if ( childs [ i ] . nodeName == 'nodes_diff' ) {
432
- var dm = ajaxplorer . getContextHolder ( ) ;
461
+ var dm = this . _dataModel ;
433
462
var removes = XPathSelectNodes ( childs [ i ] , "remove/tree" ) ;
434
463
var adds = XPathSelectNodes ( childs [ i ] , "add/tree" ) ;
435
464
var updates = XPathSelectNodes ( childs [ i ] , "update/tree" ) ;
@@ -558,7 +587,7 @@ Class.create("ActionsManager", {
558
587
559
588
}
560
589
if ( reloadNodes . length ) {
561
- ajaxplorer . getContextHolder ( ) . multipleNodesReload ( reloadNodes ) ;
590
+ this . _dataModel . multipleNodesReload ( reloadNodes ) ;
562
591
}
563
592
return ! error ;
564
593
} ,
@@ -569,31 +598,34 @@ Class.create("ActionsManager", {
569
598
*/
570
599
fireSelectionChange : function ( ) {
571
600
var userSelection = null ;
572
- if ( ajaxplorer && ajaxplorer . getUserSelection ( ) ) {
573
- userSelection = ajaxplorer . getUserSelection ( ) ;
574
- if ( userSelection . isEmpty ( ) ) userSelection = null ;
575
- }
601
+ userSelection = this . _dataModel ;
602
+ if ( userSelection . isEmpty ( ) ) userSelection = null ;
576
603
this . actions . each ( function ( pair ) {
577
604
pair . value . fireSelectionChange ( userSelection ) ;
578
- } ) ;
579
- document . fire ( "ajaxplorer:actions_refreshed" ) ;
605
+ } ) ;
606
+ if ( this . localDataModel ) {
607
+ this . notify ( "actions_refreshed" ) ;
608
+ } else {
609
+ document . fire ( "ajaxplorer:actions_refreshed" ) ;
610
+ }
580
611
} ,
581
612
582
613
/**
583
614
* Spreads a context change to all actions and to registered components
584
615
* by triggering ajaxplorer:actions_refreshed event.
585
616
*/
586
617
fireContextChange : function ( ) {
587
- var crtNode ;
588
- if ( ajaxplorer && ajaxplorer . getContextNode ( ) ) {
589
- var crtNode = ajaxplorer . getContextNode ( ) ;
590
- }
591
- this . actions . each ( function ( pair ) {
618
+ var crtNode = this . _dataModel . getContextNode ( ) ;
619
+ this . actions . each ( function ( pair ) {
592
620
pair . value . fireContextChange ( this . usersEnabled ,
593
621
this . oUser ,
594
622
crtNode ) ;
595
623
} . bind ( this ) ) ;
596
- document . fire ( "ajaxplorer:actions_refreshed" ) ;
624
+ if ( this . localDataModel ) {
625
+ this . notify ( "actions_refreshed" ) ;
626
+ } else {
627
+ document . fire ( "ajaxplorer:actions_refreshed" ) ;
628
+ }
597
629
} ,
598
630
599
631
/**
@@ -620,7 +652,11 @@ Class.create("ActionsManager", {
620
652
this . registerAction ( act ) ;
621
653
} . bind ( this ) ) ;
622
654
}
623
- document . fire ( "ajaxplorer:actions_loaded" , this . actions ) ;
655
+ if ( this . localDataModel ) {
656
+ this . notify ( "actions_loaded" ) ;
657
+ } else {
658
+ document . fire ( "ajaxplorer:actions_loaded" , this . actions ) ;
659
+ }
624
660
this . fireContextChange ( ) ;
625
661
this . fireSelectionChange ( ) ;
626
662
} ,
0 commit comments