1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-29 19:54:53 +00:00
seahub/static/scripts/sysadmin-app/router.js

232 lines
8.5 KiB
JavaScript
Raw Normal View History

2016-03-16 05:30:00 +00:00
/*global define*/
define([
'jquery',
'backbone',
'common',
'sysadmin-app/views/side-nav',
2016-04-23 10:07:09 +00:00
'sysadmin-app/views/dashboard',
'sysadmin-app/views/desktop-devices',
'sysadmin-app/views/mobile-devices',
2016-04-29 02:19:28 +00:00
'sysadmin-app/views/device-errors',
2016-05-27 08:42:40 +00:00
'sysadmin-app/views/repos',
'sysadmin-app/views/search-repos',
2016-05-27 08:42:40 +00:00
'sysadmin-app/views/system-repo',
'sysadmin-app/views/trash-repos',
'sysadmin-app/views/search-trash-repos',
'sysadmin-app/views/dir',
2016-07-20 04:26:54 +00:00
'sysadmin-app/views/groups',
2017-01-19 09:24:00 +00:00
'sysadmin-app/views/search-groups',
2017-02-09 06:59:49 +00:00
'sysadmin-app/views/group-repos',
'sysadmin-app/views/group-members',
2016-04-29 02:19:28 +00:00
'app/views/account'
2016-04-23 10:07:09 +00:00
], function($, Backbone, Common, SideNavView, DashboardView,
2016-04-29 02:19:28 +00:00
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
2016-07-20 04:26:54 +00:00
ReposView, SearchReposView, SystemReposView, TrashReposView,
2017-01-19 09:24:00 +00:00
SearchTrashReposView, DirView, GroupsView, SearchGroupsView,
2017-02-09 06:59:49 +00:00
GroupReposView, GroupMembersView, AccountView) {
2016-05-25 02:45:22 +00:00
2016-03-16 05:30:00 +00:00
"use strict";
var Router = Backbone.Router.extend({
routes: {
'': 'showDashboard',
'dashboard/': 'showDashboard',
2016-04-23 10:07:09 +00:00
'desktop-devices/': 'showDesktopDevices',
'mobile-devices/': 'showMobileDevices',
'device-errors/': 'showDeviceErrors',
'all-libs/': 'showLibraries',
'search-libs/': 'showSearchLibraries',
'system-lib/': 'showSystemLibrary',
'trash-libs/': 'showTrashLibraries',
'search-trash-libs/': 'showSearchTrashLibraries',
'libs/:repo_id(/*path)': 'showLibraryDir',
2016-07-20 04:26:54 +00:00
'groups/': 'showGroups',
2017-01-19 09:24:00 +00:00
'search-groups/': 'showSearchGroups',
2017-02-09 06:59:49 +00:00
'groups/:group_id/libs/': 'showGroupLibraries',
'groups/:group_id/members/': 'showGroupMembers',
2016-03-16 05:30:00 +00:00
// Default
'*actions': 'showDashboard'
},
initialize: function() {
2016-04-23 10:07:09 +00:00
$('#initial-loading-view').hide();
2016-03-16 05:30:00 +00:00
Common.prepareApiCsrf();
2016-04-23 10:07:09 +00:00
Common.initLocale();
2016-03-16 05:30:00 +00:00
this.sideNavView = new SideNavView();
app.ui = {
sideNavView: this.sideNavView
};
this.dashboardView = new DashboardView();
2016-04-23 10:07:09 +00:00
this.desktopDevicesView = new DesktopDevicesView();
this.mobileDevicesView = new MobileDevicesView();
this.deviceErrorsView = new DeviceErrorsView();
2016-05-27 08:42:40 +00:00
this.reposView = new ReposView();
this.searchReposView = new SearchReposView();
2016-05-27 08:42:40 +00:00
this.systemReposView = new SystemReposView();
this.trashReposView = new TrashReposView();
this.searchTrashReposView = new SearchTrashReposView();
2016-05-27 08:42:40 +00:00
this.dirView = new DirView();
2016-04-23 10:07:09 +00:00
2016-07-20 04:26:54 +00:00
this.groupsView = new GroupsView();
2017-01-19 09:24:00 +00:00
this.searchGroupsView = new SearchGroupsView();
2017-02-09 06:59:49 +00:00
this.groupReposView = new GroupReposView();
this.groupMembersView = new GroupMembersView();
2016-07-20 04:26:54 +00:00
2016-04-29 02:19:28 +00:00
app.ui.accountView = this.accountView = new AccountView();
2016-03-16 05:30:00 +00:00
this.currentView = this.dashboardView;
$('#info-bar .close').click(Common.closeTopNoticeBar);
},
switchCurrentView: function(newView) {
if (this.currentView != newView) {
this.currentView.hide();
this.currentView = newView;
}
},
showDashboard: function() {
this.switchCurrentView(this.dashboardView);
this.sideNavView.setCurTab('dashboard');
2016-03-16 08:21:53 +00:00
this.dashboardView.show();
2016-04-23 10:07:09 +00:00
},
showDesktopDevices: function(current_page) {
var url = window.location.href;
var page = url.match(/.*?page=(\d+)/);
if (page) {
2016-05-25 02:45:22 +00:00
var current_page = page[1];
2016-04-23 10:07:09 +00:00
} else {
2016-05-25 02:45:22 +00:00
var current_page = null;
2016-04-23 10:07:09 +00:00
}
this.switchCurrentView(this.desktopDevicesView);
this.sideNavView.setCurTab('devices');
this.desktopDevicesView.show({'current_page': current_page});
},
showMobileDevices: function(current_page) {
var url = window.location.href;
var page = url.match(/.*?page=(\d+)/);
if (page) {
current_page = page[1];
} else {
current_page = null;
}
this.switchCurrentView(this.mobileDevicesView);
this.sideNavView.setCurTab('devices');
this.mobileDevicesView.show({'current_page': current_page});
},
showDeviceErrors: function() {
this.switchCurrentView(this.deviceErrorsView);
this.sideNavView.setCurTab('devices');
this.deviceErrorsView.show();
2016-05-25 02:45:22 +00:00
},
showLibraries: function() {
2016-07-20 04:26:54 +00:00
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#libraries/?page=2", "2"]
var url_match = location.href.match(/.*?page=(\d+)/);
var page = url_match ? url_match[1] : 1; // 1: default
2016-05-27 08:42:40 +00:00
this.switchCurrentView(this.reposView);
this.sideNavView.setCurTab('libraries', {'option': 'all'});
this.reposView.show({'page': page});
},
showSearchLibraries: function() {
// url_match: null or an array
var url_match = location.href.match(/.*?name=(.*)&owner=(.*)/); // search by repo_name/owner
var repo_name = url_match ? url_match[1] : '';
var owner = url_match ? url_match[2] : '';
this.switchCurrentView(this.searchReposView);
2016-06-13 03:51:41 +00:00
this.sideNavView.setCurTab('libraries', {'option': 'search'});
this.searchReposView.show({
'name': decodeURIComponent(repo_name),
'owner': decodeURIComponent(owner)
});
2016-05-25 02:45:22 +00:00
},
showLibraryDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
2016-05-27 08:42:40 +00:00
this.switchCurrentView(this.dirView);
this.dirView.show(repo_id, path);
this.sideNavView.setCurTab('libraries', {'option': ''});
2016-05-25 02:45:22 +00:00
},
showSystemLibrary: function() {
2016-05-27 08:42:40 +00:00
this.switchCurrentView(this.systemReposView);
this.sideNavView.setCurTab('libraries', {'option': 'system'});
2016-05-27 08:42:40 +00:00
this.systemReposView.show();
2016-05-25 02:45:22 +00:00
},
// show trash libs by page
2016-05-25 02:45:22 +00:00
showTrashLibraries: function() {
// url_match: null or an array
var url_match = location.href.match(/.*?page=(\d+)/);
var page = url_match ? url_match[1] : 1; // 1: default
this.switchCurrentView(this.trashReposView);
this.sideNavView.setCurTab('libraries', {'option': 'trash'});
this.trashReposView.show({'page': page});
},
// search trash libs by owner
showSearchTrashLibraries: function() {
// url_match: null or an array
var url_match = location.href.match(/.*?name=(.*)/); // search by owner
var owner = url_match ? url_match[1] : '';
this.switchCurrentView(this.searchTrashReposView);
this.sideNavView.setCurTab('libraries', {'option': 'trash'});
this.searchTrashReposView.show({'owner': decodeURIComponent(owner)});
2016-07-20 04:26:54 +00:00
},
showGroups: function() {
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#groups/?page=2", "2"]
var url_match = location.href.match(/.*?page=(\d+)/);
var page = url_match ? url_match[1] : 1; // 1: default
this.switchCurrentView(this.groupsView);
this.sideNavView.setCurTab('groups');
this.groupsView.show({'page': page});
2017-01-19 09:24:00 +00:00
},
showSearchGroups: function() {
// url_match: null or an array
var url_match = location.href.match(/.*?name=(.*)/); // search by group_name
var group_name = url_match ? url_match[1] : '';
this.switchCurrentView(this.searchGroupsView);
this.sideNavView.setCurTab('groups', {'option': 'search'});
this.searchGroupsView.show({
'name': decodeURIComponent(group_name)
});
2017-02-09 06:59:49 +00:00
},
showGroupLibraries: function(group_id) {
this.switchCurrentView(this.groupReposView);
this.sideNavView.setCurTab('groups');
this.groupReposView.show(group_id);
},
showGroupMembers: function(group_id) {
this.switchCurrentView(this.groupMembersView);
this.sideNavView.setCurTab('groups');
this.groupMembersView.show(group_id);
2016-03-16 05:30:00 +00:00
}
});
return Router;
});