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

223 lines
7.1 KiB
JavaScript
Raw Normal View History

2015-04-11 07:14:56 +00:00
/*global define*/
define([
'jquery',
'backbone',
'common',
'app/views/side-nav',
'app/views/myhome-repos',
'app/views/myhome-shared-repos',
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',
'app/views/starred-file',
'app/views/devices',
'app/views/activities',
'app/views/notifications',
'app/views/account'
], function($, Backbone, Common, SideNavView, MyReposView,
SharedReposView, GroupsView, GroupView,
OrgView, DirView, StarredFileView, DevicesView, ActivitiesView,
NotificationsView, AccountView) {
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
'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',
2016-03-28 10:12:25 +00:00
'group/:group_id/': 'showGroup',
2015-04-11 09:35:02 +00:00
'group/:group_id/lib/:repo_id(/*path)': 'showGroupRepoDir',
2016-03-08 05:36:58 +00:00
'group/:group_id/discussions/': 'showGroupDiscussions',
2015-04-11 09:35:02 +00:00
'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',
2016-03-15 10:18:45 +00:00
'devices/': 'showDevices',
2015-04-11 07:14:56 +00:00
// Default
'*actions': 'showRepos'
2015-04-11 07:14:56 +00:00
},
initialize: function() {
2016-05-07 06:15:39 +00:00
$('.initial-loading').hide();
$('.main-content').show();
2015-04-11 07:14:56 +00:00
Common.prepareApiCsrf();
2016-03-17 03:15:28 +00:00
Common.initLocale();
2015-04-11 07:14:56 +00:00
this.sideNavView = new SideNavView();
2016-03-31 03:00:14 +00:00
app.ui.sideNavView = this.sideNavView;
this.dirView = new DirView();
this.myReposView = new MyReposView();
this.sharedReposView = new SharedReposView();
this.orgView = new OrgView();
this.groupView = new GroupView();
2015-11-30 07:02:03 +00:00
this.groupsView = new GroupsView();
this.starredFileView = new StarredFileView();
this.devicesView = new DevicesView();
this.activitiesView = new ActivitiesView();
2015-11-30 07:02:03 +00:00
app.ui.notificationsView = this.notificationsView = new NotificationsView();
app.ui.accountView = this.accountView = new AccountView();
this.currentView = this.myReposView;
2015-04-11 07:14:56 +00:00
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;
}
2016-05-05 05:32:39 +00:00
if (app.ui.groupDiscussions) {
app.ui.groupDiscussions.hide();
}
2015-04-11 09:35:02 +00:00
},
showRepos: function() {
if (app.pageOptions.can_add_repo) {
this.showMyRepos();
} else {
this.showSharedRepos();
}
},
2015-04-11 07:14:56 +00:00
showMyRepos: function() {
this.switchCurrentView(this.myReposView);
this.myReposView.show();
this.sideNavView.setCurTab('mine');
2015-04-11 07:14:56 +00:00
},
showSharedRepos: function() {
this.switchCurrentView(this.sharedReposView);
this.sharedReposView.show();
this.sideNavView.setCurTab('shared');
2015-04-11 07:14:56 +00:00
},
showMyRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.dirView);
this.dirView.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.dirView);
this.dirView.showDir('common', repo_id, path);
2016-03-16 07:47:33 +00:00
this.sideNavView.setCurTab('mine');
2015-04-25 07:39:06 +00:00
},
2015-04-11 07:14:56 +00:00
showSharedRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.dirView);
this.dirView.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
},
2016-03-28 10:12:25 +00:00
showGroup: function(group_id, options) {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.groupView);
this.groupView.show(group_id, options);
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 = '/';
}
var group_name = Common.groupId2Name(group_id);
if (group_name) {
this.switchCurrentView(this.dirView);
this.dirView.showDir('group/' + group_id, repo_id, path,
{'group_name': group_name});
this.sideNavView.setCurTab('group', {
'cur_group_tab': '',
'cur_group_id': group_id
});
} else {
// the group does not exist
Common.feedback('Group {group_id} not found'.replace('{group_id}', group_id), 'error');
app.router.navigate('', {trigger: true});
}
2015-04-11 07:14:56 +00:00
},
2016-03-08 05:36:58 +00:00
showGroupDiscussions: function(group_id) {
2016-03-28 10:12:25 +00:00
this.showGroup(group_id, {showDiscussions: true});
2016-03-08 05:36:58 +00:00
},
2015-04-11 07:14:56 +00:00
showOrgRepos: function() {
2015-04-11 09:35:02 +00:00
this.switchCurrentView(this.orgView);
this.orgView.show();
this.sideNavView.setCurTab('org');
2015-04-11 07:14:56 +00:00
},
showOrgRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.dirView);
this.dirView.showDir('org', repo_id, path);
this.sideNavView.setCurTab('org');
},
showStarredFile: function() {
this.switchCurrentView(this.starredFileView);
this.starredFileView.show();
this.sideNavView.setCurTab('starred');
},
showDevices: function() {
this.switchCurrentView(this.devicesView);
this.devicesView.show();
this.sideNavView.setCurTab('devices');
},
showActivities: function() {
this.switchCurrentView(this.activitiesView);
this.activitiesView.show();
this.sideNavView.setCurTab('activities');
2015-04-11 07:14:56 +00:00
}
2015-04-11 07:14:56 +00:00
});
return Router;
});