2015-04-11 07:14:56 +00:00
|
|
|
/*global define*/
|
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'app/views/myhome',
|
|
|
|
'app/views/group',
|
2015-04-11 08:33:29 +00:00
|
|
|
'app/views/organization',
|
2015-04-17 10:07:17 +00:00
|
|
|
'app/views/dir',
|
2015-04-17 02:59:48 +00:00
|
|
|
'app/views/top-group-nav'
|
2015-04-11 09:35:02 +00:00
|
|
|
], function($, Backbone, Common, MyHomeView, GroupView, OrgView,
|
2015-04-17 10:07:17 +00:00
|
|
|
DirView, GroupNavView) {
|
2015-04-11 07:14:56 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Router = Backbone.Router.extend({
|
|
|
|
routes: {
|
2015-06-12 08:04:10 +00:00
|
|
|
'': '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
|
|
|
'my-sub-libs/': 'showMySubRepos',
|
2015-04-11 07:14:56 +00:00
|
|
|
'my-sub-libs/lib/:repo_id(/*path)': 'showMySubRepoDir',
|
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',
|
|
|
|
'group/:group_id/': 'showGroupRepos',
|
2015-04-11 09:35:02 +00:00
|
|
|
'group/:group_id/lib/:repo_id(/*path)': 'showGroupRepoDir',
|
|
|
|
'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-24 03:37:57 +00:00
|
|
|
'activities/': 'showEvent',
|
2015-04-11 07:14:56 +00:00
|
|
|
// Default
|
2015-06-25 04:05:47 +00:00
|
|
|
'*actions': 'showRepos'
|
2015-04-11 07:14:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
Common.prepareApiCsrf();
|
|
|
|
Common.initAccountPopup();
|
|
|
|
Common.initNoticePopup();
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
this.dirView = new DirView();
|
|
|
|
|
|
|
|
this.myHomeView = new MyHomeView({dirView: this.dirView});
|
|
|
|
this.groupView = new GroupView({dirView: this.dirView});
|
|
|
|
this.orgView = new OrgView({dirView: this.dirView});
|
2015-04-17 02:59:48 +00:00
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
this.currentView = this.myHomeView;
|
|
|
|
|
2015-04-17 02:59:48 +00:00
|
|
|
if (app.pageOptions.top_nav_groups.length > 0) {
|
|
|
|
this.topGroupNavView = new GroupNavView();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-12 08:04:10 +00:00
|
|
|
showRepos: function() {
|
|
|
|
this.switchCurrentView(this.myHomeView);
|
|
|
|
if (app.pageOptions.can_add_repo) {
|
|
|
|
this.myHomeView.showMyRepos();
|
|
|
|
} else {
|
|
|
|
this.myHomeView.showSharedRepos();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showMyRepos: function() {
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showMyRepos();
|
|
|
|
},
|
|
|
|
|
|
|
|
showMySubRepos: function() {
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showMySubRepos();
|
|
|
|
},
|
|
|
|
|
|
|
|
showSharedRepos: function() {
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showSharedRepos();
|
|
|
|
},
|
|
|
|
|
2015-05-04 09:02:20 +00:00
|
|
|
showStarredFile: function() {
|
|
|
|
this.switchCurrentView(this.myHomeView);
|
|
|
|
this.myHomeView.showStarredFile();
|
|
|
|
},
|
|
|
|
|
2015-07-24 03:37:57 +00:00
|
|
|
showEvent: function() {
|
|
|
|
this.switchCurrentView(this.myHomeView);
|
|
|
|
this.myHomeView.showActivity();
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showMyRepoDir: function(repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showDir('my-libs', repo_id, path);
|
|
|
|
},
|
|
|
|
|
2015-04-25 07:39:06 +00:00
|
|
|
showCommonDir: function(repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
|
|
|
this.switchCurrentView(this.myHomeView);
|
|
|
|
this.myHomeView.showDir('common', repo_id, path);
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showMySubRepoDir: function(repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showDir('my-sub-libs', repo_id, path);
|
|
|
|
},
|
|
|
|
|
|
|
|
showSharedRepoDir: function(repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.myHomeView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.myHomeView.showDir('shared-libs', repo_id, path);
|
|
|
|
},
|
|
|
|
|
|
|
|
showGroupRepos: function(group_id) {
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.groupView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.groupView.showRepoList(group_id);
|
|
|
|
},
|
|
|
|
|
|
|
|
showGroupRepoDir: function(group_id, repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.groupView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.groupView.showDir(group_id, repo_id, path);
|
|
|
|
},
|
|
|
|
|
|
|
|
showOrgRepos: function() {
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.orgView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.orgView.showRepoList();
|
|
|
|
},
|
|
|
|
|
|
|
|
showOrgRepoDir: function(repo_id, path) {
|
|
|
|
if (path) {
|
|
|
|
path = '/' + path;
|
|
|
|
} else {
|
|
|
|
path = '/';
|
|
|
|
}
|
2015-04-11 09:35:02 +00:00
|
|
|
this.switchCurrentView(this.orgView);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.orgView.showDir(repo_id, path);
|
|
|
|
}
|
2015-06-25 04:05:47 +00:00
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return Router;
|
|
|
|
});
|