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

202 lines
6.3 KiB
JavaScript
Raw Normal View History

2015-04-11 07:14:56 +00:00
/*global define*/
define([
'jquery',
'backbone',
'common',
'app/views/side-nav',
2015-04-11 07:14:56 +00:00
'app/views/myhome',
2015-11-30 07:02:03 +00:00
'app/views/groups',
2015-04-11 07:14:56 +00:00
'app/views/group',
2015-04-11 08:33:29 +00:00
'app/views/organization',
'app/views/dir'
], function($, Backbone, Common, SideNavView, MyHomeView, GroupsView, GroupView,
OrgView, DirView) {
2015-04-11 07:14:56 +00:00
"use strict";
var Router = Backbone.Router.extend({
routes: {
'': 'showRepos',
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',
2015-11-30 07:02:03 +00:00
'groups/': 'showGroups',
2015-04-11 07:14:56 +00:00
'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-25 07:39:06 +00:00
'common/lib/:repo_id(/*path)': 'showCommonDir',
2015-05-04 09:02:20 +00:00
'starred/': 'showStarredFile',
2015-07-28 11:54:57 +00:00
'activities/': 'showActivities',
2015-04-11 07:14:56 +00:00
// Default
'*actions': 'showRepos'
2015-04-11 07:14:56 +00:00
},
initialize: function() {
Common.prepareApiCsrf();
Common.initAccountPopup();
Common.initNoticePopup();
this.sideNavView = new SideNavView();
this.dirView = new DirView();
this.myHomeView = new MyHomeView({dirView: this.dirView});
this.groupView = new GroupView({dirView: this.dirView});
this.orgView = new OrgView({dirView: this.dirView});
2015-11-30 07:02:03 +00:00
this.groupsView = new GroupsView();
2015-04-11 07:14:56 +00:00
this.currentView = this.myHomeView;
2015-05-08 07:59:18 +00:00
$('#info-bar .close').click(Common.closeTopNoticeBar);
2015-06-05 09:09:53 +00:00
$('#top-browser-tip .close').click(function () {
$('#top-browser-tip').addClass('hide');
});
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;
}
},
showRepos: function() {
this.switchCurrentView(this.myHomeView);
if (app.pageOptions.can_add_repo) {
this.myHomeView.showMyRepos();
} else {
this.myHomeView.showSharedRepos();
this.sideNavView.setCurTab('shared');
}
},
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();
this.sideNavView.setCurTab('mine');
2015-04-11 07:14:56 +00:00
},
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();
this.sideNavView.setCurTab('shared');
2015-04-11 07:14:56 +00:00
},
2015-05-04 09:02:20 +00:00
showStarredFile: function() {
this.switchCurrentView(this.myHomeView);
this.myHomeView.showStarredFile();
this.sideNavView.setCurTab('starred');
2015-05-04 09:02:20 +00:00
},
2015-07-28 11:54:57 +00:00
showActivities: function() {
2015-07-24 03:37:57 +00:00
this.switchCurrentView(this.myHomeView);
2015-07-28 11:54:57 +00:00
this.myHomeView.showActivities();
this.sideNavView.setCurTab('activities');
2015-07-24 03:37:57 +00:00
},
2015-04-11 07:14:56 +00:00
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);
this.sideNavView.setCurTab('mine');
2015-04-11 07:14:56 +00:00
},
2015-04-25 07:39:06 +00:00
showCommonDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.myHomeView);
this.myHomeView.showDir('common', repo_id, path);
},
2015-04-11 07:14:56 +00:00
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);
this.sideNavView.setCurTab('sub-libs');
2015-04-11 07:14:56 +00:00
},
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);
this.sideNavView.setCurTab('shared');
2015-04-11 07:14:56 +00:00
},
2015-11-30 07:02:03 +00:00
showGroups: function () {
this.switchCurrentView(this.groupsView);
this.groupsView.show();
this.sideNavView.setCurTab('group', {
'cur_group_tab': 'groups',
'cur_group_id': ''
});
2015-11-30 07:02:03 +00:00
},
2015-04-11 07:14:56 +00:00
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);
this.sideNavView.setCurTab('group', {
'cur_group_tab': '',
'cur_group_id': group_id
});
2015-04-11 07:14:56 +00:00
},
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);
2015-12-09 07:08:15 +00:00
this.sideNavView.setCurTab('group', {
'cur_group_tab': '',
'cur_group_id': group_id
});
2015-04-11 07:14:56 +00:00
},
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();
this.sideNavView.setCurTab('org');
2015-04-11 07:14:56 +00:00
},
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);
this.sideNavView.setCurTab('org');
2015-04-11 07:14:56 +00:00
}
2015-04-11 07:14:56 +00:00
});
return Router;
});