1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-23 13:48:20 +00:00
seahub/static/scripts/app/router.js

141 lines
4.1 KiB
JavaScript
Raw Normal View History

2015-04-11 07:14:56 +00:00
/*global define*/
define([
'jquery',
'backbone',
'common',
'app/views/myhome',
'app/views/group',
2015-04-11 08:33:29 +00:00
'app/views/organization',
'app/views/top-group-nav'
2015-04-11 09:35:02 +00:00
], function($, Backbone, Common, MyHomeView, GroupView, OrgView,
2015-04-11 07:14:56 +00:00
GroupNavView) {
"use strict";
var Router = Backbone.Router.extend({
routes: {
2015-04-14 06:48:56 +00:00
'': 'showMyRepos',
2015-04-11 09:35:02 +00:00
'my-libs/': 'showMyRepos',
2015-04-11 07:14:56 +00:00
'my-libs/lib/:repo_id(/*path)': 'showMyRepoDir',
2015-04-11 09:35:02 +00:00
'my-sub-libs/': 'showMySubRepos',
2015-04-11 07:14:56 +00:00
'my-sub-libs/lib/:repo_id(/*path)': 'showMySubRepoDir',
2015-04-11 09:35:02 +00:00
'shared-libs/': 'showSharedRepos',
2015-04-11 07:14:56 +00:00
'shared-libs/lib/:repo_id(/*path)': 'showSharedRepoDir',
'group/:group_id/': 'showGroupRepos',
2015-04-11 09:35:02 +00:00
'group/:group_id/lib/:repo_id(/*path)': 'showGroupRepoDir',
'org/': 'showOrgRepos',
'org/lib/:repo_id(/*path)': 'showOrgRepoDir',
2015-04-11 07:14:56 +00:00
// Default
'*actions': 'defaultAction'
},
initialize: function() {
Common.prepareApiCsrf();
Common.initAccountPopup();
Common.initNoticePopup();
Common.getContacts();
2015-04-11 07:14:56 +00:00
this.myHomeView = new MyHomeView();
this.groupView = new GroupView();
2015-04-11 09:35:02 +00:00
this.orgView = new OrgView();
2015-04-11 07:14:56 +00:00
this.currentView = this.myHomeView;
if (app.pageOptions.top_nav_groups.length > 0) {
this.topGroupNavView = new GroupNavView();
}
2015-04-11 07:14:56 +00:00
},
2015-04-11 09:35:02 +00:00
switchCurrentView: function(newView) {
if (this.currentView != newView) {
this.currentView.hide();
this.currentView = newView;
}
},
2015-04-11 07:14:56 +00:00
showMyRepos: function() {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showMyRepos();
},
showMySubRepos: function() {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showMySubRepos();
},
showSharedRepos: function() {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showSharedRepos();
},
showMyRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showDir('my-libs', repo_id, path);
},
showMySubRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showDir('my-sub-libs', repo_id, path);
},
showSharedRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showDir('shared-libs', repo_id, path);
},
showGroupRepos: function(group_id) {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.groupView);
2015-04-11 07:14:56 +00:00
this.groupView.showRepoList(group_id);
},
showGroupRepoDir: function(group_id, repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.groupView);
2015-04-11 07:14:56 +00:00
this.groupView.showDir(group_id, repo_id, path);
},
showOrgRepos: function() {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.orgView);
2015-04-11 07:14:56 +00:00
this.orgView.showRepoList();
},
showOrgRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.orgView);
2015-04-11 07:14:56 +00:00
this.orgView.showDir(repo_id, path);
},
defaultAction: function(actions) {
// We have no matching route, lets just log what the URL was
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.myHomeView);
2015-04-11 07:14:56 +00:00
this.myHomeView.showMyRepos();
}
});
return Router;
});