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

311 lines
11 KiB
JavaScript
Raw Normal View History

2015-04-11 07:14:56 +00:00
/*global define*/
define([
'jquery',
'backbone',
'common',
'js.cookie',
'app/views/side-nav',
'app/views/myhome-repos',
'app/views/my-deleted-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/activities',
2016-06-30 07:06:43 +00:00
'app/views/devices',
2016-07-12 08:34:20 +00:00
'app/views/invitations',
2016-06-30 07:06:43 +00:00
'app/views/share-admin-repos',
'app/views/share-admin-folders',
'app/views/share-admin-share-links',
'app/views/share-admin-upload-links',
'app/views/notifications',
'app/views/account'
], function($, Backbone, Common, Cookies, SideNavView, MyReposView,
MyDeletedReposView, SharedReposView, GroupsView, GroupView, OrgView,
DirView, StarredFileView, ActivitiesView, DevicesView, InvitationsView,
2016-07-12 08:34:20 +00:00
ShareAdminReposView, ShareAdminFoldersView, ShareAdminShareLinksView,
2016-06-30 07:06:43 +00:00
ShareAdminUploadLinksView, 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',
'my-libs/deleted/': 'showMyDeletedRepos',
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',
2016-07-12 08:34:20 +00:00
'invitations/': 'showInvitations',
2016-06-30 07:06:43 +00:00
'share-admin-libs/': 'showShareAdminRepos',
'share-admin-folders/': 'showShareAdminFolders',
'share-admin-share-links/': 'showShareAdminShareLinks',
'share-admin-upload-links/': 'showShareAdminUploadLinks',
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();
2017-12-05 09:53:45 +00:00
$('.main-content').removeClass('hide');
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.myDeletedReposView = new MyDeletedReposView();
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();
2016-07-12 08:34:20 +00:00
this.invitationsView = new InvitationsView();
this.activitiesView = new ActivitiesView();
2016-06-30 07:06:43 +00:00
this.shareAdminReposView = new ShareAdminReposView();
this.shareAdminFoldersView = new ShareAdminFoldersView();
this.shareAdminShareLinksView = new ShareAdminShareLinksView();
this.shareAdminUploadLinksView = new ShareAdminUploadLinksView();
2015-11-30 07:02:03 +00:00
app.ui.notificationsView = this.notificationsView = new NotificationsView();
app.ui.accountView = this.accountView = new AccountView();
app.pageOptions.sort_mode = Cookies.get('sort_mode') || 'name_up';
var _this = this;
var originalWindowWidth = $(window).width();
$(window).on('resize', function() {
var curWidth = $(window).width();
if (_this.currentView.reset) {
if ((originalWindowWidth < 768 && curWidth >= 768 ) ||
(originalWindowWidth >= 768 && curWidth < 768)) {
_this.currentView.reset();
}
}
originalWindowWidth = curWidth;
});
2016-12-03 09:29:41 +00:00
// for popups such as '#share-popup'
$(window).on('resize', function() {
2016-12-03 09:29:41 +00:00
var $el = $('#share-popup, #repo-share-link-admin-dialog, #repo-folder-perm-popup, #folder-perm-popup');
if ($el.is(':visible')) {
if ($(window).width() < 768) {
$el.css({
'width': $(window).width() - 50,
'height': $(window).height() - 50,
'overflow': 'auto'
});
$.modal.update($(window).height() - 50, $(window).width() - 50);
} else {
$el.removeAttr('style');
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
}
}
});
$('#info-bar .close').on('click', Common.closeTopNoticeBar);
$('#top-browser-tip-close').on('click', function () {
2015-06-05 09:09:53 +00:00
$('#top-browser-tip').addClass('hide');
});
2015-04-11 07:14:56 +00:00
},
2015-04-11 09:35:02 +00:00
switchCurrentView: function(newView) {
2017-12-05 09:53:45 +00:00
if (!this.currentView) {
2015-04-11 09:35:02 +00:00
this.currentView = newView;
2017-12-05 09:53:45 +00:00
} else {
if (this.currentView != newView) {
this.currentView.hide();
this.currentView = newView;
}
2016-05-05 05:32:39 +00:00
}
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');
},
showMyDeletedRepos: function() {
this.switchCurrentView(this.myDeletedReposView);
this.myDeletedReposView.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');
},
2016-06-30 07:06:43 +00:00
showActivities: function() {
this.switchCurrentView(this.activitiesView);
this.activitiesView.show();
this.sideNavView.setCurTab('activities');
},
showDevices: function() {
this.switchCurrentView(this.devicesView);
this.devicesView.show();
this.sideNavView.setCurTab('devices');
},
2016-07-12 08:34:20 +00:00
showInvitations: function() {
this.switchCurrentView(this.invitationsView);
this.invitationsView.show();
this.sideNavView.setCurTab('invitations');
},
2016-06-30 07:06:43 +00:00
showShareAdminRepos: function() {
this.switchCurrentView(this.shareAdminReposView);
this.shareAdminReposView.show();
this.sideNavView.setCurTab('share-admin-repos');
},
showShareAdminFolders: function() {
this.switchCurrentView(this.shareAdminFoldersView);
this.shareAdminFoldersView.show();
this.sideNavView.setCurTab('share-admin-folders');
},
showShareAdminShareLinks: function() {
this.switchCurrentView(this.shareAdminShareLinksView);
this.shareAdminShareLinksView.show();
this.sideNavView.setCurTab('share-admin-links');
},
showShareAdminUploadLinks: function() {
this.switchCurrentView(this.shareAdminUploadLinksView);
this.shareAdminUploadLinksView.show();
this.sideNavView.setCurTab('share-admin-links');
2015-04-11 07:14:56 +00:00
}
2015-04-11 07:14:56 +00:00
});
return Router;
});