Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit facd466

Browse files
committed
ActionsManager / ActionsToolbar refactoring to handle a "local" datamodel. To be even more simplified if possible. Use it in RepositoryEditor to display a tab with all shares of the current edited workspace.
1 parent ee67037 commit facd466

File tree

9 files changed

+197
-65
lines changed

9 files changed

+197
-65
lines changed

core/src/plugins/editor.ajxp_repository/class.RepositoryEditor.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Class.create("RepositoryEditor", AbstractEditor, {
3636
// INIT TAB
3737
var infoPane = this.element.down("#pane-infos");
3838
var metaPane = this.element.down("#pane-metas");
39+
this.sharesPane = this.element.down("#pane-shares");
3940

4041
var oElement = this.element;
4142
infoPane.setStyle({position:"relative"});
@@ -64,6 +65,16 @@ Class.create("RepositoryEditor", AbstractEditor, {
6465
return true;
6566
},
6667

68+
close: function($super){
69+
if(this.sharesList){
70+
this.sharesList.destroy();
71+
}
72+
if(this.manager){
73+
this.manager.destroy();
74+
}
75+
$super();
76+
},
77+
6778
save : function(){
6879
if(!this.isDirty()) return;
6980

@@ -109,6 +120,40 @@ Class.create("RepositoryEditor", AbstractEditor, {
109120
this.node = node;
110121
this.formManager = this.getFormManager();
111122
this.loadRepository(this.repositoryId);
123+
124+
// Load list of shares
125+
var listPane = this.sharesPane.down("#shares-list");
126+
var actionPane = this.sharesPane.down("#shares-toolbar");
127+
listPane.observe("editor:updateTitle", function(e){
128+
Event.stop(e);
129+
});
130+
this.sharesList = new FetchedResultPane(listPane, {
131+
nodeProviderProperties:{get_action:"ls",dir:"/data/repositories/"+this.repositoryId},
132+
updateGlobalContext:false,
133+
selectionChangeCallback:false,
134+
displayMode: 'list',
135+
fixedDisplayMode: 'list',
136+
fit:"height"
137+
});
138+
listPane.removeClassName("class-FetchedResultPane");
139+
this.sharesList._dataLoaded = true;
140+
this.sharesList.reloadDataModel();
141+
this.sharesPane.resizeOnShow = function(){
142+
this.sharesList.resize();
143+
this.sharesList.reload();
144+
}.bind(this);
145+
146+
this.manager = new ActionsManager(true, this.sharesList._dataModel);
147+
this.sharesToolbar = new ActionsToolbar(actionPane, {
148+
toolbarsList:["repo_editor_shares"],
149+
skipBubbling:true,
150+
skipCarousel:true,
151+
submenuOffsetTop:2,
152+
manager:this.manager
153+
});
154+
this.manager.loadActionsFromRegistry(ajaxplorer.getXmlRegistry());
155+
156+
112157
},
113158

114159
updateTitle: function(label){

core/src/plugins/editor.ajxp_repository/manifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@
1212
<i18n namespace="ajxp_repository_editor" path="plugins/editor.ajxp_repository/i18n"/>
1313
</resources>
1414
</client_settings>
15+
<registry_contributions>
16+
<actions>
17+
<action name="repo_editor_edit_share">
18+
<gui text="ajxp_conf.93" title="301" iconClass="icon-edit" src="edit.png" accessKey="edit_access_key" hasAccessKey="true">
19+
<context selection="true" dir="" recycle="hidden"
20+
actionBar="true" contextMenu="true" infoPanel="true"
21+
actionBarGroup="repo_editor_shares" inZip="false">
22+
</context>
23+
<selectionContext dir="true" file="true" recycle="false" unique="true" allowedMimes="AJXP_MIMES_EDITABLE" behaviour="disable"/></gui>
24+
<rightsContext noUser="true" userLogged="only" read="true" write="true" adminOnly=""/>
25+
<processing>
26+
<clientCallback prepareModal="false"><![CDATA[
27+
var editorData = window.actionArguments[0];
28+
var manager = window.actionManager;
29+
alert('Should display data about ' + manager.getDataModel().getUniqueFileName());
30+
]]></clientCallback>
31+
<serverCallback methodName="switchAction" developerComment="Shortcut for various actions, calling edit with subaction parameter."/>
32+
</processing>
33+
</action>
34+
</actions>
35+
</registry_contributions>
1536
<clientForm id="repository_edit_box"><![CDATA[
1637
<div id="repository_edit_box" class="tabbed_editor" action="editer" box_width="460" box_height="80%" box_resize="true" box_padding="0">
1738
<div class="editor_header">
@@ -22,6 +43,7 @@
2243
<ul class="tabrow">
2344
<li class="selected" data-PaneID="pane-infos"><span ajxp_message_id="ajxp_repository_editor.3">AJXP_MESSAGE[ajxp_repository_editor.3]</span></li>
2445
<li class="" data-PaneID="pane-metas"><span ajxp_message_id="ajxp_repository_editor.4">AJXP_MESSAGE[ajxp_repository_editor.4]</span></li>
46+
<li class="" data-PaneID="pane-shares"><span ajxp_message_id="ajxp_repository_editor.4">Shares</span></li>
2547
</ul>
2648
<div class="tabpanes">
2749
</div>
@@ -32,6 +54,10 @@
3254
<ul class="tabrow"></ul>
3355
<div class="tabpanes"></div>
3456
</div>
57+
</div>
58+
<div id="pane-shares">
59+
<div id="shares-toolbar"></div>
60+
<div id="shares-list"></div>
3561
</div>
3662
</div>
3763
</div>

core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/plugins/gui.ajax/res/js/ajaxplorer/class.Action.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Class.create("Action", {
147147
);
148148
}
149149
window.actionArguments = $A([]);
150+
window.actionManager = this.manager;
150151
if(arguments[0]) window.actionArguments = $A(arguments[0]);
151152
if(this.options.callbackCode) {
152153
try{
@@ -186,6 +187,7 @@ Class.create("Action", {
186187
this.notify("submenu_active", arguments[0][0]);
187188
}
188189
window.actionArguments = null;
190+
window.actionManager = null;
189191
document.fire("ajaxplorer:afterApply-"+this.options.name);
190192
},
191193

core/src/plugins/gui.ajax/res/js/ajaxplorer/class.ActionsManager.js

Lines changed: 82 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Class.create("ActionsManager", {
2727
* Standard constructor
2828
* @param bUsersEnabled Boolen Whether users management is enabled or not
2929
*/
30-
initialize: function(bUsersEnabled)
30+
initialize: function(bUsersEnabled, dataModel)
3131
{
3232
this._registeredKeys = new Hash();
3333
this._actions = new Hash();
@@ -37,29 +37,58 @@ Class.create("ActionsManager", {
3737
this.subMenus = [];
3838
this.actions = new Hash();
3939
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+
6179
},
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+
6392
/**
6493
* Stores the currently logged user object
6594
* @param oUser User User instance
@@ -112,7 +141,7 @@ Class.create("ActionsManager", {
112141
var isDefault = false;
113142
if(actionsSelectorAtt == 'selectionContext'){
114143
// set default in bold
115-
var userSelection = ajaxplorer.getUserSelection();
144+
var userSelection = this._dataModel;
116145
if(!userSelection.isEmpty()){
117146
var defaultAction = 'file';
118147
if(userSelection.isUnique() && (userSelection.hasDir() || userSelection.hasMime(['ajxp_browsable_archive']))){
@@ -283,7 +312,7 @@ Class.create("ActionsManager", {
283312
(copy && (!this.defaultActions.get('ctrldragndrop')||this.getDefaultAction('ctrldragndrop').deny))){
284313
return;
285314
}
286-
if(fileName == null) fileNames = ajaxplorer.getUserSelection().getFileNames();
315+
if(fileName == null) fileNames = this._dataModel.getFileNames();
287316
else fileNames = [fileName];
288317
if(destNodeName != null)
289318
{
@@ -302,7 +331,7 @@ Class.create("ActionsManager", {
302331
}
303332
}
304333
// 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()){
306335
if(destNodeName != null) ajaxplorer.displayMessage('ERROR', MessageHash[203]);
307336
return;
308337
}
@@ -314,7 +343,7 @@ Class.create("ActionsManager", {
314343
}
315344
connexion.addParameter('nodes[]', fileNames);
316345
connexion.addParameter('dest', destDir);
317-
connexion.addParameter('dir', ajaxplorer.getContextNode().getPath());
346+
connexion.addParameter('dir', this._dataModel.getContextNode().getPath());
318347
connexion.onComplete = function(transport){this.parseXmlMessage(transport.responseXML);}.bind(this);
319348
connexion.sendAsync();
320349
},
@@ -374,8 +403,8 @@ Class.create("ActionsManager", {
374403
if(fElement.type == 'radio' && !fElement.checked) return;
375404
connexion.addParameter(fElement.name, fValue);
376405
});
377-
if(ajaxplorer.getContextNode()){
378-
connexion.addParameter('dir', ajaxplorer.getContextNode().getPath());
406+
if(this._dataModel.getContextNode()){
407+
connexion.addParameter('dir', this._dataModel.getContextNode().getPath());
379408
}
380409
if(completeCallback){
381410
connexion.onComplete = completeCallback;
@@ -418,9 +447,9 @@ Class.create("ActionsManager", {
418447
}else{
419448
var file = childs[i].getAttribute('file');
420449
if(file){
421-
ajaxplorer.getContextHolder().setPendingSelection(file);
450+
this._dataModel.setPendingSelection(file);
422451
}
423-
reloadNodes.push(ajaxplorer.getContextNode());
452+
reloadNodes.push(this._dataModel.getContextNode());
424453
}
425454
}
426455
else if(obName == 'repository_list')
@@ -429,7 +458,7 @@ Class.create("ActionsManager", {
429458
}
430459
}
431460
else if(childs[i].nodeName == 'nodes_diff'){
432-
var dm = ajaxplorer.getContextHolder();
461+
var dm = this._dataModel;
433462
var removes = XPathSelectNodes(childs[i], "remove/tree");
434463
var adds = XPathSelectNodes(childs[i], "add/tree");
435464
var updates = XPathSelectNodes(childs[i], "update/tree");
@@ -558,7 +587,7 @@ Class.create("ActionsManager", {
558587

559588
}
560589
if(reloadNodes.length){
561-
ajaxplorer.getContextHolder().multipleNodesReload(reloadNodes);
590+
this._dataModel.multipleNodesReload(reloadNodes);
562591
}
563592
return !error;
564593
},
@@ -569,31 +598,34 @@ Class.create("ActionsManager", {
569598
*/
570599
fireSelectionChange: function(){
571600
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;
576603
this.actions.each(function(pair){
577604
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+
}
580611
},
581612

582613
/**
583614
* Spreads a context change to all actions and to registered components
584615
* by triggering ajaxplorer:actions_refreshed event.
585616
*/
586617
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){
592620
pair.value.fireContextChange(this.usersEnabled,
593621
this.oUser,
594622
crtNode);
595623
}.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+
}
597629
},
598630

599631
/**
@@ -620,7 +652,11 @@ Class.create("ActionsManager", {
620652
this.registerAction(act);
621653
}.bind(this));
622654
}
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+
}
624660
this.fireContextChange();
625661
this.fireSelectionChange();
626662
},

0 commit comments

Comments
 (0)