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',
|
2016-06-07 09:32:01 +00:00
|
|
|
'sysadmin-app/views/search-repos',
|
2016-05-27 08:42:40 +00:00
|
|
|
'sysadmin-app/views/system-repo',
|
|
|
|
'sysadmin-app/views/trash-repos',
|
2016-06-07 09:32:01 +00:00
|
|
|
'sysadmin-app/views/dir',
|
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-06-07 09:32:01 +00:00
|
|
|
ReposView, SearchReposView, SystemReposView, TrashReposView, DirView,
|
|
|
|
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',
|
2016-06-07 09:32:01 +00:00
|
|
|
'all-libs/': 'showLibraries',
|
|
|
|
'search-libs/': 'showSearchLibraries',
|
|
|
|
'system-lib/': 'showSystemLibrary',
|
|
|
|
'trash-libs/': 'showTrashLibraries',
|
|
|
|
'libs/:repo_id(/*path)': 'showLibraryDir',
|
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-06-07 09:32:01 +00:00
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
this.reposView = new ReposView();
|
2016-06-07 09:32:01 +00:00
|
|
|
this.searchReposView = new SearchReposView();
|
2016-05-27 08:42:40 +00:00
|
|
|
this.systemReposView = new SystemReposView();
|
|
|
|
this.trashReposView = new TrashReposView();
|
|
|
|
this.dirView = new DirView();
|
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() {
|
2016-06-07 09:32:01 +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);
|
2016-06-07 09:32:01 +00:00
|
|
|
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);
|
|
|
|
this.sideNavView.setCurTab('libraries', {'option': 'all'});
|
|
|
|
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);
|
2016-06-07 09:32:01 +00:00
|
|
|
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);
|
2016-06-07 09:32:01 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
showTrashLibraries: function() {
|
2016-06-07 09:32:01 +00:00
|
|
|
// url_match: null or an array
|
|
|
|
var url_match = location.href.match(/.*?name=(.*)/); // search by owner
|
|
|
|
var owner = url_match ? url_match[1] : '';
|
|
|
|
|
2016-05-27 08:42:40 +00:00
|
|
|
this.switchCurrentView(this.trashReposView);
|
2016-06-07 09:32:01 +00:00
|
|
|
this.sideNavView.setCurTab('libraries', {'option': 'trash'});
|
|
|
|
this.trashReposView.show({'owner': decodeURIComponent(owner)});
|
2016-03-16 05:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return Router;
|
|
|
|
});
|