1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-02 05:05:43 +00:00
seahub/static/scripts/sysadmin-app/router.js

150 lines
5.0 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-25 02:45:22 +00:00
'sysadmin-app/views/libraries',
'sysadmin-app/views/library-dir',
'sysadmin-app/views/system-library',
'sysadmin-app/views/trash-libraries',
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-05-25 02:45:22 +00:00
LibrariesView, LibraryDirView, SystemLibrariesView,
TrashLibrariesView, AccountView) {
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',
2016-05-25 02:45:22 +00:00
'libraries/': 'showLibraries',
'libraries/:repo_id/dirents(/*path)': 'showLibraryDir',
'libraries/system/': 'showSystemLibrary',
'libraries/trash/': 'showTrashLibraries',
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-25 02:45:22 +00:00
this.librariesView = new LibrariesView();
this.systemLibrariesView = new SystemLibrariesView();
this.trashLibrariesView = new TrashLibrariesView();
this.libraryDirView = new LibraryDirView();
2016-04-23 10:07:09 +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() {
var url = window.location.href;
var page = url.match(/.*?page=(\d+)/);
if (page) {
var current_page = page[1];
} else {
var current_page = null;
}
this.switchCurrentView(this.librariesView);
this.sideNavView.setCurTab('libraries');
this.librariesView.show({'current_page': current_page});
},
showLibraryDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.libraryDirView);
this.libraryDirView.show(repo_id, path);
this.sideNavView.setCurTab('libraries');
},
showSystemLibrary: function() {
this.switchCurrentView(this.systemLibrariesView);
this.sideNavView.setCurTab('libraries');
this.systemLibrariesView.show();
},
showTrashLibraries: function() {
this.switchCurrentView(this.trashLibrariesView);
this.sideNavView.setCurTab('libraries');
this.trashLibrariesView.show();
2016-03-16 05:30:00 +00:00
}
});
return Router;
});