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

Commit

Permalink
Totally replace old proto.history by Backbone router - Wire router to…
Browse files Browse the repository at this point in the history
… current context node path
  • Loading branch information
cdujeu committed Oct 27, 2014
1 parent 6ab703a commit 68310fb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 234 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

103 changes: 29 additions & 74 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.Ajaxplorer.js
Expand Up @@ -110,10 +110,11 @@ Class.create("Ajaxplorer", {

var WorkspaceRouter = Backbone.Router.extend({
routes: {
":workspace":"switchToWorkspace"
":workspace/*path":"switchToWorkspace"
},
switchToWorkspace: function(workspace) {
switchToWorkspace: function(workspace, path) {
if(!ajaxplorer.user) {return;}
if(path) path = '/' + path;
var repos = ajaxplorer.user.getRepositoriesList();
workspace = workspace.replace("ws-", "");
var object = $H(repos).detect(function(pair){
Expand All @@ -122,7 +123,12 @@ Class.create("Ajaxplorer", {
if(!object) return;
var foundRepo = object.value;
if(ajaxplorer.repositoryId != foundRepo.getId()){
if(path){
this._initLoadRep = path;
}
ajaxplorer.triggerRepositoryChange(foundRepo.getId());
}else if(path){
ajaxplorer.goTo(path);
}
}

Expand All @@ -132,25 +138,14 @@ Class.create("Ajaxplorer", {
var appRoot = ajxpBootstrap.parameters.get('APPLICATION_ROOT');
if(appRoot && appRoot != "/"){
Backbone.history.start({
pushState: true,
pushState: false,
root:appRoot
});
}else{
Backbone.history.start({
pushState: true
pushState: false
});
}
if(this.user && this.user.getActiveRepository()){
var repoList = this.user.getRepositoriesList();
var activeRepo = repoList.get(this.user.getActiveRepository());
if(activeRepo){
var slug = activeRepo.getSlug();
if(!activeRepo.getAccessType().startsWith("ajxp_")){
slug = "ws-" + slug;
}
this.router.navigate(slug);
}
}
var navigate = function(repList, repId){
if(repId === false){
this.router.navigate("/.");
Expand All @@ -161,6 +156,9 @@ Class.create("Ajaxplorer", {
if(!repositoryObject.getAccessType().startsWith("ajxp_")){
slug = "ws-" + slug;
}
if(this._contextHolder && this._contextHolder.getContextNode()){
slug += this._contextHolder.getContextNode().getPath();
}
this.router.navigate(slug);
}
}
Expand All @@ -174,7 +172,18 @@ Class.create("Ajaxplorer", {
var repId = event.memo.active;
navigate(repList, repId);
});

document.observe("ajaxplorer:context_changed", function(event){
var repoList = this.user.getRepositoriesList();
var activeRepo = repoList.get(this.user.getActiveRepository());
if(activeRepo){
var slug = activeRepo.getSlug();
if(!activeRepo.getAccessType().startsWith("ajxp_")){
slug = "ws-" + slug;
}
var path = this.getContextNode().getPath();
this.router.navigate(slug + path);
}
}.bind(this));
},

/**
Expand Down Expand Up @@ -278,23 +287,11 @@ Class.create("Ajaxplorer", {
this.actionBar.loadActionsFromRegistry(event.memo);
}.bind(this) );

if(!Prototype.Browser.WebKit && !Prototype.Browser.IE){
/*
this.history = new Proto.History(function(hash){
this.goTo(this.historyHashToPath(hash));
}.bind(this));
*/
document.observe("ajaxplorer:context_changed", function(event){
this.updateHistory(this.getContextNode().getPath());
}.bind(this));
}else{
document.observe("ajaxplorer:context_changed", function(event){
var path = this.getContextNode().getPath();
document.title = this.appTitle + ' - '+(getBaseName(path)?getBaseName(path):'/');
}.bind(this));
}
document.observe("ajaxplorer:context_changed", function(event){
if(this.skipLsHistory || !this.user || !this.user.getActiveRepository()) return;
var path = this.getContextNode().getPath();
document.title = this.appTitle + ' - '+(getBaseName(path)?getBaseName(path):'/');

if(this.skipLsHistory || !this.user || !this.user.getActiveRepository()) return;
window.setTimeout(function(){
var data = this.user.getPreference("ls_history", true) || {};
data = new Hash(data);
Expand Down Expand Up @@ -1154,48 +1151,6 @@ Class.create("Ajaxplorer", {
};
connexion.sendSync();
},

/**
* Updates the browser history
* @param path String Path
*/
updateHistory: function(path){
if(this.history) this.history.historyLoad(this.pathToHistoryHash(path));
},

/**
* Translate the path to a history step. Return the count.
* @param path String
* @returns Integer
*/
pathToHistoryHash: function(path){
document.title = this.appTitle + ' - '+(getBaseName(path)?getBaseName(path):'/');
if(!this.pathesHash){
this.pathesHash = new Hash();
this.histCount = -1;
}
var foundKey;
this.pathesHash.each(function(pair){
if(pair.value == path) foundKey = pair.key;
});
if(foundKey != undefined) return foundKey;

this.histCount++;
this.pathesHash.set(this.histCount, path);
return this.histCount;
},

/**
* Reverse operation
* @param hash Integer
* @returns String
*/
historyHashToPath: function(hash){
if(!this.pathesHash) return "/";
var path = this.pathesHash.get(hash);
if(path == undefined) return "/";
return path;
},

/**
* Accessor for updating the datamodel context
Expand Down
1 change: 0 additions & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer_list.txt
Expand Up @@ -9,7 +9,6 @@ js/lib/prototype/webfx.selectable.js
js/lib/prototype/webfx.sortable.js
js/lib/prototype/proto.menu.js
js/lib/prototype/splitter.js
js/lib/prototype/proto.history.js
js/lib/prototype/cookiejar.js
js/lib/prototype/protopass.js
js/lib/prototype/resizable.js
Expand Down
158 changes: 0 additions & 158 deletions core/src/plugins/gui.ajax/res/js/lib/prototype/proto.history.js

This file was deleted.

0 comments on commit 68310fb

Please sign in to comment.