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

Commit

Permalink
Add a small Backbone extension to enable URL routing
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Feb 26, 2014
1 parent 7d1f29d commit 38a23c9
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 5 deletions.
4 changes: 4 additions & 0 deletions core/src/.htaccess
Expand Up @@ -11,6 +11,10 @@ RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shares ./dav.php [L]
RewriteRule ^api ./rest.php [L]
RewriteRule ^user ./index.php?get_action=user_access_point [L]
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !plugins
RewriteCond %{REQUEST_URI} dashboard|settings|ws-
RewriteRule (.*) index.php [L]

#Following lines seem to be necessary if PHP is working
#with apache as CGI or FCGI. Just remove the #
Expand Down
3 changes: 3 additions & 0 deletions core/src/plugins/gui.ajax/res/html/gui.html
Expand Up @@ -6,6 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="icon" type="image/x-png" href="AJXP_THEME_FOLDER/images/html-folder.png">
<link rel="stylesheet" type="text/css" href="AJXP_THEME_FOLDER/css/allz.css?v=AJXP_CURRENT_VERSION">
<script language="javascript" type="text/javascript" src="AJXP_CLIENT_RESOURCES_FOLDER/js/lib/backbone/jquery-min.js"></script>
<script language="javascript" type="text/javascript" src="AJXP_CLIENT_RESOURCES_FOLDER/js/lib/backbone/underscore-min.js"></script>
<script language="javascript" type="text/javascript" src="AJXP_CLIENT_RESOURCES_FOLDER/js/lib/backbone/backbone-min.js"></script>
<script language="javascript" type="text/javascript" src="AJXP_CLIENT_RESOURCES_FOLDER/js/ajaxplorer_boot.js?v=AJXP_CURRENT_VERSION"></script>
</head>
<body bgcolor="#FFFFFF" text="#000000" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" style="overflow:hidden;">
Expand Down
3 changes: 3 additions & 0 deletions core/src/plugins/gui.ajax/res/html/gui_debug.html
Expand Up @@ -7,6 +7,9 @@
}?>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="icon" type="image/x-png" href="<?php print(AJXP_THEME_FOLDER);?>/images/html-folder.png">
<script language="javascript" type="text/javascript" src="<?php print(CLIENT_RESOURCES_FOLDER);?>/js/lib/backbone/jquery-min.js"></script>
<script language="javascript" type="text/javascript" src="<?php print(CLIENT_RESOURCES_FOLDER);?>/js/lib/backbone/underscore-min.js"></script>
<script language="javascript" type="text/javascript" src="<?php print(CLIENT_RESOURCES_FOLDER);?>/js/lib/backbone/backbone-min.js"></script>
<?php
$list = AJXP_INSTALL_PATH."/".AJXP_THEME_FOLDER."/css/allz_list.txt";
$lines = file($list);
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

64 changes: 60 additions & 4 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.Ajaxplorer.js
Expand Up @@ -88,9 +88,63 @@ Class.create("Ajaxplorer", {
this.initTemplates();
modal.initForms();
this.initObjects();
window.setTimeout(function(){
document.fire('ajaxplorer:loaded');
}, 200);
window.setTimeout(function(){
document.fire('ajaxplorer:loaded');
}, 200);

var WorkspaceRouter = Backbone.Router.extend({
routes: {
":workspace":"switchToWorkspace"
},
switchToWorkspace: function(workspace) {
if(!ajaxplorer.user) {return;}
var repos = ajaxplorer.user.getRepositoriesList();
workspace = workspace.replace("ws-", "");
var object = $H(repos).detect(function(pair){
return pair.value.getSlug() == workspace;
});
if(!object) return;
var foundRepo = object.value;
if(ajaxplorer.repositoryId != foundRepo.getId()){
ajaxplorer.triggerRepositoryChange(foundRepo.getId());
}
}

});

window.router = new WorkspaceRouter();
Backbone.history.start({pushState: true});
if(this.user && this.user.getActiveRepository()){
var repoList = this.user.getRepositoriesList();
var activeRepo = repoList.get(this.user.getActiveRepository());
var slug = activeRepo.getSlug();
if(!activeRepo.getAccessType().startsWith("ajxp_")){
slug = "ws-" + slug;
}
window.router.navigate(slug);
}
var navigate = function(repList, repId){
if(repId === false){
window.router.navigate("/");
}else{
var repositoryObject = repList.get(repId);
var slug = repositoryObject.getSlug();
if(!repositoryObject.getAccessType().startsWith("ajxp_")){
slug = "ws-" + slug;
}
window.router.navigate(slug);
}
};

if(this.user){
navigate(this.user.getRepositoriesList(), this.user.getActiveRepository());
}
document.observe("ajaxplorer:repository_list_refreshed", function(event){
var repList = event.memo.list;
var repId = event.memo.active;
navigate(repList, repId);
});

},
/**
* Loads the XML Registry, an image of the application in its current state
Expand Down Expand Up @@ -194,9 +248,11 @@ Class.create("Ajaxplorer", {
}.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));
Expand Down Expand Up @@ -535,7 +591,7 @@ Class.create("Ajaxplorer", {
document.fire("ajaxplorer:repository_list_refreshed", {list:repList,active:repId});
}else{
document.fire("ajaxplorer:repository_list_refreshed", {list:false,active:false});
}
}
},

/**
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/gui.ajax/res/js/lib/backbone/backbone-min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions core/src/plugins/gui.ajax/res/js/lib/backbone/jquery-min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 38a23c9

Please sign in to comment.