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

Commit

Permalink
ActionsManager / ActionsToolbar refactoring to handle a "local" datam…
Browse files Browse the repository at this point in the history
…odel. To be even more simplified if possible. Use it in RepositoryEditor to display a tab with all shares of the current edited workspace.
  • Loading branch information
cdujeu committed May 1, 2014
1 parent ee67037 commit facd466
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 65 deletions.
45 changes: 45 additions & 0 deletions core/src/plugins/editor.ajxp_repository/class.RepositoryEditor.js
Expand Up @@ -36,6 +36,7 @@ Class.create("RepositoryEditor", AbstractEditor, {
// INIT TAB
var infoPane = this.element.down("#pane-infos");
var metaPane = this.element.down("#pane-metas");
this.sharesPane = this.element.down("#pane-shares");

var oElement = this.element;
infoPane.setStyle({position:"relative"});
Expand Down Expand Up @@ -64,6 +65,16 @@ Class.create("RepositoryEditor", AbstractEditor, {
return true;
},

close: function($super){
if(this.sharesList){
this.sharesList.destroy();
}
if(this.manager){
this.manager.destroy();
}
$super();
},

save : function(){
if(!this.isDirty()) return;

Expand Down Expand Up @@ -109,6 +120,40 @@ Class.create("RepositoryEditor", AbstractEditor, {
this.node = node;
this.formManager = this.getFormManager();
this.loadRepository(this.repositoryId);

// Load list of shares
var listPane = this.sharesPane.down("#shares-list");
var actionPane = this.sharesPane.down("#shares-toolbar");
listPane.observe("editor:updateTitle", function(e){
Event.stop(e);
});
this.sharesList = new FetchedResultPane(listPane, {
nodeProviderProperties:{get_action:"ls",dir:"/data/repositories/"+this.repositoryId},
updateGlobalContext:false,
selectionChangeCallback:false,
displayMode: 'list',
fixedDisplayMode: 'list',
fit:"height"
});
listPane.removeClassName("class-FetchedResultPane");
this.sharesList._dataLoaded = true;
this.sharesList.reloadDataModel();
this.sharesPane.resizeOnShow = function(){
this.sharesList.resize();
this.sharesList.reload();
}.bind(this);

this.manager = new ActionsManager(true, this.sharesList._dataModel);
this.sharesToolbar = new ActionsToolbar(actionPane, {
toolbarsList:["repo_editor_shares"],
skipBubbling:true,
skipCarousel:true,
submenuOffsetTop:2,
manager:this.manager
});
this.manager.loadActionsFromRegistry(ajaxplorer.getXmlRegistry());


},

updateTitle: function(label){
Expand Down
26 changes: 26 additions & 0 deletions core/src/plugins/editor.ajxp_repository/manifest.xml
Expand Up @@ -12,6 +12,27 @@
<i18n namespace="ajxp_repository_editor" path="plugins/editor.ajxp_repository/i18n"/>
</resources>
</client_settings>
<registry_contributions>
<actions>
<action name="repo_editor_edit_share">
<gui text="ajxp_conf.93" title="301" iconClass="icon-edit" src="edit.png" accessKey="edit_access_key" hasAccessKey="true">
<context selection="true" dir="" recycle="hidden"
actionBar="true" contextMenu="true" infoPanel="true"
actionBarGroup="repo_editor_shares" inZip="false">
</context>
<selectionContext dir="true" file="true" recycle="false" unique="true" allowedMimes="AJXP_MIMES_EDITABLE" behaviour="disable"/></gui>
<rightsContext noUser="true" userLogged="only" read="true" write="true" adminOnly=""/>
<processing>
<clientCallback prepareModal="false"><![CDATA[
var editorData = window.actionArguments[0];
var manager = window.actionManager;
alert('Should display data about ' + manager.getDataModel().getUniqueFileName());
]]></clientCallback>
<serverCallback methodName="switchAction" developerComment="Shortcut for various actions, calling edit with subaction parameter."/>
</processing>
</action>
</actions>
</registry_contributions>
<clientForm id="repository_edit_box"><![CDATA[
<div id="repository_edit_box" class="tabbed_editor" action="editer" box_width="460" box_height="80%" box_resize="true" box_padding="0">
<div class="editor_header">
Expand All @@ -22,6 +43,7 @@
<ul class="tabrow">
<li class="selected" data-PaneID="pane-infos"><span ajxp_message_id="ajxp_repository_editor.3">AJXP_MESSAGE[ajxp_repository_editor.3]</span></li>
<li class="" data-PaneID="pane-metas"><span ajxp_message_id="ajxp_repository_editor.4">AJXP_MESSAGE[ajxp_repository_editor.4]</span></li>
<li class="" data-PaneID="pane-shares"><span ajxp_message_id="ajxp_repository_editor.4">Shares</span></li>
</ul>
<div class="tabpanes">
</div>
Expand All @@ -32,6 +54,10 @@
<ul class="tabrow"></ul>
<div class="tabpanes"></div>
</div>
</div>
<div id="pane-shares">
<div id="shares-toolbar"></div>
<div id="shares-list"></div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.Action.js
Expand Up @@ -147,6 +147,7 @@ Class.create("Action", {
);
}
window.actionArguments = $A([]);
window.actionManager = this.manager;
if(arguments[0]) window.actionArguments = $A(arguments[0]);
if(this.options.callbackCode) {
try{
Expand Down Expand Up @@ -186,6 +187,7 @@ Class.create("Action", {
this.notify("submenu_active", arguments[0][0]);
}
window.actionArguments = null;
window.actionManager = null;
document.fire("ajaxplorer:afterApply-"+this.options.name);
},

Expand Down
128 changes: 82 additions & 46 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.ActionsManager.js
Expand Up @@ -27,7 +27,7 @@ Class.create("ActionsManager", {
* Standard constructor
* @param bUsersEnabled Boolen Whether users management is enabled or not
*/
initialize: function(bUsersEnabled)
initialize: function(bUsersEnabled, dataModel)
{
this._registeredKeys = new Hash();
this._actions = new Hash();
Expand All @@ -37,29 +37,58 @@ Class.create("ActionsManager", {
this.subMenus = [];
this.actions = new Hash();
this.defaultActions = new Hash();
this.toolbars = new Hash();
document.observe("ajaxplorer:context_changed", function(event){
window.setTimeout(function(){
this.fireContextChange();
}.bind(this), 0);
}.bind(this) );

document.observe("ajaxplorer:selection_changed", function(event){
window.setTimeout(function(){
this.fireSelectionChange();
}.bind(this), 0);
}.bind(this) );

document.observe("ajaxplorer:user_logged", function(event){
if(event.memo && event.memo.getPreference){
this.setUser(event.memo);
}else{
this.setUser(null);
}
}.bind(this));

this.toolbars = new Hash();
if(dataModel){
this._dataModel = dataModel;
}
this.contextChangedObs = function(event){
window.setTimeout(function(){
this.fireContextChange();
}.bind(this), 0);
}.bind(this);
this.selectionChangedObs = function(event){
window.setTimeout(function(){
this.fireSelectionChange();
}.bind(this), 0);
}.bind(this);

if(this._dataModel){
this._dataModel.observe("context_changed", this.contextChangedObs);
this._dataModel.observe("selection_changed", this.selectionChangedObs);
this.localDataModel = true;
}else{
document.observe("ajaxplorer:context_changed", this.contextChangedObs);
document.observe("ajaxplorer:selection_changed", this.selectionChangedObs);
this._dataModel = ajaxplorer.getContextHolder();
this.localDataModel = false;
}

if(this.usersEnabled){
document.observe("ajaxplorer:user_logged", function(event){
if(event.memo && event.memo.getPreference){
this.setUser(event.memo);
}else{
this.setUser(null);
}
}.bind(this));
if(ajaxplorer.user) {
this.setUser(ajaxplorer.user);
}
}

},


getDataModel:function(){
return this._dataModel;
},

destroy: function(){
if(this.localDataModel && this._dataModel){
this._dataModel.stopObserving("context_changed", this.contextChangedObs);
this._dataModel.stopObserving("selection_changed", this.selectionChangedObs);
}
},

/**
* Stores the currently logged user object
* @param oUser User User instance
Expand Down Expand Up @@ -112,7 +141,7 @@ Class.create("ActionsManager", {
var isDefault = false;
if(actionsSelectorAtt == 'selectionContext'){
// set default in bold
var userSelection = ajaxplorer.getUserSelection();
var userSelection = this._dataModel;
if(!userSelection.isEmpty()){
var defaultAction = 'file';
if(userSelection.isUnique() && (userSelection.hasDir() || userSelection.hasMime(['ajxp_browsable_archive']))){
Expand Down Expand Up @@ -283,7 +312,7 @@ Class.create("ActionsManager", {
(copy && (!this.defaultActions.get('ctrldragndrop')||this.getDefaultAction('ctrldragndrop').deny))){
return;
}
if(fileName == null) fileNames = ajaxplorer.getUserSelection().getFileNames();
if(fileName == null) fileNames = this._dataModel.getFileNames();
else fileNames = [fileName];
if(destNodeName != null)
{
Expand All @@ -302,7 +331,7 @@ Class.create("ActionsManager", {
}
}
// Check that dest is not the direct parent of source, ie current rep!
if(destDir == ajaxplorer.getContextNode().getPath()){
if(destDir == this._dataModel.getContextNode().getPath()){
if(destNodeName != null) ajaxplorer.displayMessage('ERROR', MessageHash[203]);
return;
}
Expand All @@ -314,7 +343,7 @@ Class.create("ActionsManager", {
}
connexion.addParameter('nodes[]', fileNames);
connexion.addParameter('dest', destDir);
connexion.addParameter('dir', ajaxplorer.getContextNode().getPath());
connexion.addParameter('dir', this._dataModel.getContextNode().getPath());
connexion.onComplete = function(transport){this.parseXmlMessage(transport.responseXML);}.bind(this);
connexion.sendAsync();
},
Expand Down Expand Up @@ -374,8 +403,8 @@ Class.create("ActionsManager", {
if(fElement.type == 'radio' && !fElement.checked) return;
connexion.addParameter(fElement.name, fValue);
});
if(ajaxplorer.getContextNode()){
connexion.addParameter('dir', ajaxplorer.getContextNode().getPath());
if(this._dataModel.getContextNode()){
connexion.addParameter('dir', this._dataModel.getContextNode().getPath());
}
if(completeCallback){
connexion.onComplete = completeCallback;
Expand Down Expand Up @@ -418,9 +447,9 @@ Class.create("ActionsManager", {
}else{
var file = childs[i].getAttribute('file');
if(file){
ajaxplorer.getContextHolder().setPendingSelection(file);
this._dataModel.setPendingSelection(file);
}
reloadNodes.push(ajaxplorer.getContextNode());
reloadNodes.push(this._dataModel.getContextNode());
}
}
else if(obName == 'repository_list')
Expand All @@ -429,7 +458,7 @@ Class.create("ActionsManager", {
}
}
else if(childs[i].nodeName == 'nodes_diff'){
var dm = ajaxplorer.getContextHolder();
var dm = this._dataModel;
var removes = XPathSelectNodes(childs[i], "remove/tree");
var adds = XPathSelectNodes(childs[i], "add/tree");
var updates = XPathSelectNodes(childs[i], "update/tree");
Expand Down Expand Up @@ -558,7 +587,7 @@ Class.create("ActionsManager", {

}
if(reloadNodes.length){
ajaxplorer.getContextHolder().multipleNodesReload(reloadNodes);
this._dataModel.multipleNodesReload(reloadNodes);
}
return !error;
},
Expand All @@ -569,31 +598,34 @@ Class.create("ActionsManager", {
*/
fireSelectionChange: function(){
var userSelection = null;
if (ajaxplorer && ajaxplorer.getUserSelection()){
userSelection = ajaxplorer.getUserSelection();
if(userSelection.isEmpty()) userSelection = null;
}
userSelection = this._dataModel;
if(userSelection.isEmpty()) userSelection = null;
this.actions.each(function(pair){
pair.value.fireSelectionChange(userSelection);
});
document.fire("ajaxplorer:actions_refreshed");
});
if(this.localDataModel){
this.notify("actions_refreshed");
}else{
document.fire("ajaxplorer:actions_refreshed");
}
},

/**
* Spreads a context change to all actions and to registered components
* by triggering ajaxplorer:actions_refreshed event.
*/
fireContextChange: function(){
var crtNode;
if(ajaxplorer && ajaxplorer.getContextNode()){
var crtNode = ajaxplorer.getContextNode();
}
this.actions.each(function(pair){
var crtNode = this._dataModel.getContextNode();
this.actions.each(function(pair){
pair.value.fireContextChange(this.usersEnabled,
this.oUser,
crtNode);
}.bind(this));
document.fire("ajaxplorer:actions_refreshed");
if(this.localDataModel){
this.notify("actions_refreshed");
}else{
document.fire("ajaxplorer:actions_refreshed");
}
},

/**
Expand All @@ -620,7 +652,11 @@ Class.create("ActionsManager", {
this.registerAction(act);
}.bind(this));
}
document.fire("ajaxplorer:actions_loaded", this.actions);
if(this.localDataModel){
this.notify("actions_loaded");
}else{
document.fire("ajaxplorer:actions_loaded", this.actions);
}
this.fireContextChange();
this.fireSelectionChange();
},
Expand Down

0 comments on commit facd466

Please sign in to comment.