diff --git a/seahub/templates/base_for_backbone.html b/seahub/templates/base_for_backbone.html
index 03d84bfab1..b0477759ed 100644
--- a/seahub/templates/base_for_backbone.html
+++ b/seahub/templates/base_for_backbone.html
@@ -47,14 +47,14 @@
{% block nav %}
-
- {% trans "My Home" %}
+ {% trans "My Home" %}
-
{% trans "Groups" %}{% if grps %} {% endif %}
{% if user.permissions.can_view_org %}
-
- {% trans "Organization" %}
+ {% trans "Organization" %}
{% endif %}
-
diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html
index 07726149a3..29b9b79fda 100644
--- a/seahub/templates/js/templates.html
+++ b/seahub/templates/js/templates.html
@@ -43,7 +43,7 @@
<%= size_formatted %> |
<%= mtime_relative %> |
-
-
+{% if debug %}
+
+{% else %}
+
+{% endif %}
+{% endblock %}
diff --git a/seahub/urls.py b/seahub/urls.py
index 8a2d427048..6b15679124 100644
--- a/seahub/urls.py
+++ b/seahub/urls.py
@@ -92,6 +92,7 @@ urlpatterns = patterns('',
### lib (replace the old `repo` urls) ###
# url(r'^lib/(?P[-0-9a-f]{36})/dir/(?P.*)$', view_lib_dir, name='view_lib_dir'),
+ url(r'^libs/$', libraries, name='libraries'),
url(r'^lib/(?P[-0-9a-f]{36})/file/(?P.*)$', view_lib_file, name='view_lib_file'),
# url(r'^home/my/lib/(?P[-0-9a-f]{36})/dir/(?P.*)$', myhome_lib, name='myhome_lib'),
diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py
index e9c1cb0e75..ead5320a77 100644
--- a/seahub/views/__init__.py
+++ b/seahub/views/__init__.py
@@ -1140,6 +1140,33 @@ def myhome(request):
'repo_password_min_length': settings.REPO_PASSWORD_MIN_LENGTH,
}, context_instance=RequestContext(request))
+@login_required
+@user_mods_check
+def libraries(request):
+ """
+ New URL to replace myhome
+ """
+ username = request.user.username
+
+ # options
+ if request.cloud_mode and request.user.org is None:
+ allow_public_share = False
+ else:
+ allow_public_share = True
+ sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
+ guide_enabled = UserOptions.objects.is_user_guide_enabled(username)
+ max_upload_file_size = get_max_upload_file_size()
+
+ return render_to_response('libraries.html', {
+ "allow_public_share": allow_public_share,
+ "guide_enabled": guide_enabled,
+ "sub_lib_enabled": sub_lib_enabled,
+ 'enable_upload_folder': settings.ENABLE_UPLOAD_FOLDER,
+ 'max_upload_file_size': max_upload_file_size,
+ 'repo_password_min_length': settings.REPO_PASSWORD_MIN_LENGTH,
+ 'PREVIEW_DEFAULT_SIZE': PREVIEW_DEFAULT_SIZE,
+ }, context_instance=RequestContext(request))
+
@login_required
@user_mods_check
def starred(request):
diff --git a/static/scripts/app/collections/group-repos.js b/static/scripts/app/collections/group-repos.js
index 2b5e3ce52d..d1c8fc304b 100644
--- a/static/scripts/app/collections/group-repos.js
+++ b/static/scripts/app/collections/group-repos.js
@@ -1,21 +1,26 @@
define([
'underscore',
'backbone',
+ 'common',
'app/models/group-repo'
-], function(_, Backbone, GroupRepo) {
+], function(_, Backbone, Common, GroupRepo) {
'use strict';
var GroupRepoCollection = Backbone.Collection.extend({
model: GroupRepo,
- url: app.pageOptions.groupReposUrl,
-
comparator: -'mtime',
+ url: function() {
+ return Common.getUrl({name: 'group_repos', group_id: this.group_id});
+ },
+
+ setGroupID: function(group_id) {
+ this.group_id = group_id;
+ }
+
// initialize: function( ) {
// },
-
-
});
return GroupRepoCollection;
diff --git a/static/scripts/app/main.js b/static/scripts/app/main.js
new file mode 100644
index 0000000000..5179f61804
--- /dev/null
+++ b/static/scripts/app/main.js
@@ -0,0 +1,6 @@
+define([
+ 'app/router'
+], function(Router){
+ app.router = new Router();
+ Backbone.history.start();
+});
diff --git a/static/scripts/app/router.js b/static/scripts/app/router.js
new file mode 100644
index 0000000000..f4cacda318
--- /dev/null
+++ b/static/scripts/app/router.js
@@ -0,0 +1,138 @@
+/*global define*/
+define([
+ 'jquery',
+ 'backbone',
+ 'common',
+ 'app/views/myhome',
+ 'app/views/group',
+ 'app/views/Organization',
+ 'app/views/group-nav',
+], function($, Backbone, Common, MyHomeView, GroupView, orgView,
+ GroupNavView) {
+ "use strict";
+
+ var Router = Backbone.Router.extend({
+ routes: {
+ 'my-libs': 'showMyRepos',
+ 'my-libs/lib/:repo_id(/*path)': 'showMyRepoDir',
+ 'my-sub-libs': 'showMySubRepos',
+ 'my-sub-libs/lib/:repo_id(/*path)': 'showMySubRepoDir',
+ 'shared-libs': 'showSharedRepos',
+ 'shared-libs/lib/:repo_id(/*path)': 'showSharedRepoDir',
+ 'group/:group_id/': 'showGroupRepos',
+ 'group/:group_id/:repo_id(/*path)': 'showGroupRepoDir',
+ 'org': 'showOrgRepos',
+ 'org/:repo_id(/*path)': 'showOrgRepoDir',
+
+ // Default
+ '*actions': 'defaultAction'
+ },
+
+ initialize: function() {
+ Common.prepareApiCsrf();
+ Common.initAccountPopup();
+ Common.initNoticePopup();
+
+ this.myHomeView = new MyHomeView();
+ this.groupView = new GroupView();
+ this.orgView = new orgView();
+ this.currentView = this.myHomeView;
+
+ this.groupNavView = new GroupNavView();
+ },
+
+ showMyRepos: function() {
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showMyRepos();
+ },
+
+ showMySubRepos: function() {
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showMySubRepos();
+ },
+
+ showSharedRepos: function() {
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showSharedRepos();
+ },
+
+ showMyRepoDir: function(repo_id, path) {
+ if (path) {
+ path = '/' + path;
+ } else {
+ path = '/';
+ }
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showDir('my-libs', repo_id, path);
+ },
+
+ showMySubRepoDir: function(repo_id, path) {
+ if (path) {
+ path = '/' + path;
+ } else {
+ path = '/';
+ }
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showDir('my-sub-libs', repo_id, path);
+ },
+
+ showSharedRepoDir: function(repo_id, path) {
+ if (path) {
+ path = '/' + path;
+ } else {
+ path = '/';
+ }
+ this.currentView.hide();
+ this.currentView = this.myHomeView;
+ this.myHomeView.showDir('shared-libs', repo_id, path);
+ },
+
+ showGroupRepos: function(group_id) {
+ this.currentView.hide();
+ this.currentView = this.groupView;
+ this.groupView.showRepoList(group_id);
+ },
+
+ showGroupRepoDir: function(group_id, repo_id, path) {
+ if (path) {
+ path = '/' + path;
+ } else {
+ path = '/';
+ }
+ this.currentView.hide();
+ this.currentView = this.groupView;
+ this.groupView.showDir(group_id, repo_id, path);
+ },
+
+ showOrgRepos: function() {
+ this.currentView.hide();
+ this.currentView = this.orgView;
+ this.orgView.showRepoList();
+ },
+
+ showOrgRepoDir: function(repo_id, path) {
+ if (path) {
+ path = '/' + path;
+ } else {
+ path = '/';
+ }
+ this.currentView.hide();
+ this.currentView = this.orgView;
+ this.orgView.showDir(repo_id, path);
+ },
+
+ defaultAction: function(actions) {
+ // We have no matching route, lets just log what the URL was
+ console.log('No route:', actions);
+
+ this.myHomeView.showMyRepos();
+ }
+ });
+
+ return Router;
+});
diff --git a/static/scripts/app/views/group-repos.js b/static/scripts/app/views/group-repo.js
similarity index 86%
rename from static/scripts/app/views/group-repos.js
rename to static/scripts/app/views/group-repo.js
index 6a1f067c70..38af18f3fc 100644
--- a/static/scripts/app/views/group-repos.js
+++ b/static/scripts/app/views/group-repo.js
@@ -9,23 +9,27 @@ define([
var GroupRepoView = Backbone.View.extend({
tagName: 'tr',
- template: _.template($('#group-repos-tmpl').html()),
+ template: _.template($('#group-repo-tmpl').html()),
events: {
'mouseenter': 'showAction',
'mouseleave': 'hideAction',
'click .cancel-share': 'unshare'
},
-
- initialize: function() {
- console.log('init GroupRepoView');
+
+ initialize: function(options) {
+ this.group_id = options.group_id;
Backbone.View.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, 'destroy', this.remove);
},
render: function() {
- this.$el.html(this.template(this.model.toJSON()));
+ var obj = this.model.toJSON();
+ $.extend(obj, {
+ group_id: this.group_id,
+ });
+ this.$el.html(this.template(obj));
return this;
},
diff --git a/static/scripts/app/views/group.js b/static/scripts/app/views/group.js
index f40116fda9..e1659332a7 100644
--- a/static/scripts/app/views/group.js
+++ b/static/scripts/app/views/group.js
@@ -5,14 +5,13 @@ define([
'common',
'app/collections/group-repos',
'app/collections/dirents',
- 'app/views/group-repos',
+ 'app/views/group-repo',
'app/views/add-group-repo',
'app/views/group-recent-change',
'app/views/dir',
- 'app/views/group-nav',
], function($, _, Backbone, Common, GroupRepos, DirentCollection,
- GroupRepoView, AddGroupRepoView/*, DirentView*/, GroupRecentChangeView,
- DirView, GroupNavView) {
+ GroupRepoView, AddGroupRepoView, GroupRecentChangeView,
+ DirView) {
'use strict';
var GroupView = Backbone.View.extend({
@@ -25,28 +24,19 @@ define([
},
initialize: function() {
- Common.prepareApiCsrf();
-
- this.$cont = this.$('#right-panel');
-
- this.$tabs = this.$('#tabs');
- this.$tab = this.$('#tabs div:first-child');
- this.$table = this.$('#grp-repos table');
+ this.$tabs = this.$('#group-repo-tabs');
+ this.$table = this.$('#grp-repos table', this.$tabs);
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
- this.$loadingTip = $('.loading-tip', this.$cont);
- this.$emptyTip = $('.empty-tips', this.$cont);
-
+ this.$loadingTip = $('.loading-tip', this.$tabs);
+ this.$emptyTip = $('.empty-tips', this.$tabs);
this.$createForm = this.$('#repo-create-form');
+
this.repos = new GroupRepos();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
this.dirView = new DirView();
-
- this.groupView = new GroupNavView();
- Common.initAccountPopup();
- Common.initNoticePopup();
},
/*
@@ -64,8 +54,7 @@ define([
},
addOne: function(repo, collection, options) {
- console.log('add repo: ' + repo.get('name'));
- var view = new GroupRepoView({model: repo});
+ var view = new GroupRepoView({model: repo, group_id: this.group_id});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
@@ -86,9 +75,11 @@ define([
}
},
- showRepoList: function() {
+ showRepoList: function(group_id) {
+ this.group_id = group_id;
this.dirView.hide();
this.$tabs.show();
+ this.repos.setGroupID(group_id);
this.repos.fetch({reset: true});
this.$loadingTip.show();
},
@@ -97,7 +88,8 @@ define([
this.$tabs.hide();
},
- showDir: function(repo_id, path) {
+ showDir: function(group_id, repo_id, path) {
+ this.group_id = group_id;
this.hideRepoList();
this.dirView.showDir('', repo_id, path);
},
@@ -146,6 +138,11 @@ define([
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
+ },
+
+ hide: function() {
+ this.hideRepoList();
+ this.dirView.hide();
}
});
diff --git a/static/scripts/app/views/myhome.js b/static/scripts/app/views/myhome.js
index 14b37e7fd5..bc88362b11 100644
--- a/static/scripts/app/views/myhome.js
+++ b/static/scripts/app/views/myhome.js
@@ -8,16 +8,15 @@ define([
'app/views/myhome-sub-repos',
'app/views/myhome-shared-repos',
'app/views/dir',
- 'app/views/group-nav',
], function($, _, Backbone, Common, GroupCollection,
- ReposView, SubReposView, SharedReposView, DirView, GroupNavView) {
+ ReposView, SubReposView, SharedReposView, DirView) {
'use strict';
var MyHomeView = Backbone.View.extend({
el: '#main',
initialize: function() {
- Common.prepareApiCsrf();
+
//_.bindAll(this, 'ajaxLoadingShow', 'ajaxLoadingHide');
//this.$el.ajaxStart(this.ajaxLoadingShow).ajaxStop(this.ajaxLoadingHide);
@@ -28,12 +27,8 @@ define([
this.subReposView = new SubReposView();
this.sharedReposView = new SharedReposView();
this.dirView = new DirView();
- this.groupView = new GroupNavView();
this.currentView = this.reposView;
- Common.initAccountPopup();
- Common.initNoticePopup();
-
$('#initial-loading-view').hide();
},
@@ -77,6 +72,10 @@ define([
this.currentView.hide();
this.dirView.showDir(category, repo_id, path);
this.currentView = this.dirView;
+ },
+
+ hide: function() {
+ this.currentView.hide();
}
diff --git a/static/scripts/app/views/organization-repo.js b/static/scripts/app/views/organization-repo.js
index 708f29c5de..28dd08af6a 100644
--- a/static/scripts/app/views/organization-repo.js
+++ b/static/scripts/app/views/organization-repo.js
@@ -9,7 +9,7 @@ define([
var OrganizationRepoView = Backbone.View.extend({
tagName: 'tr',
- template: _.template($('#organization-repos-tmpl').html()),
+ template: _.template($('#organization-repo-tmpl').html()),
events: {
'mouseenter': 'showAction',
diff --git a/static/scripts/app/views/organization.js b/static/scripts/app/views/organization.js
index 00a201fafc..ba86c68c13 100644
--- a/static/scripts/app/views/organization.js
+++ b/static/scripts/app/views/organization.js
@@ -6,17 +6,15 @@ define([
'app/collections/pub-repos',
'app/views/organization-repo',
'app/views/dir',
- 'app/views/group-nav',
'app/views/add-pub-repo'
], function($, _, Backbone, Common, PubRepoCollection, OrganizationRepoView,
- DirView, GroupNavView, AddPubRepoView) {
+ DirView, AddPubRepoView) {
'use strict';
var OrganizationView = Backbone.View.extend({
el: '#main',
initialize: function() {
- Common.prepareApiCsrf();
this.$reposDiv = $('#organization-repos');
this.$table = $('#organization-repos table');
@@ -29,10 +27,6 @@ define([
this.listenTo(this.repos, 'reset', this.reset);
this.dirView = new DirView();
-
- this.groupView = new GroupNavView();
- Common.initAccountPopup();
- Common.initNoticePopup();
},
events: {
@@ -67,20 +61,20 @@ define([
this.$loadingTip.hide();
},
- showPublicRepos: function() {
+ showRepoList: function() {
this.dirView.hide();
this.$reposDiv.show();
this.repos.fetch({reset: true});
this.$loadingTip.show();
},
- hideRepos: function() {
+ hideRepoList: function() {
this.$reposDiv.hide();
},
showDir: function(repo_id, path) {
var path = path || '/';
- this.hideRepos();
+ this.hideRepoList();
this.dirView.showDir('', repo_id, path);
// this.dirent_list = new app.DirentListView({id: id, path: path});
// $('#my-own-repos table').children().remove();
@@ -118,6 +112,11 @@ define([
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
+ },
+
+ hide: function() {
+ this.hideRepoList();
+ this.dirView.hide();
}
});
diff --git a/static/scripts/common.js b/static/scripts/common.js
index 518b354062..b7b6de8944 100644
--- a/static/scripts/common.js
+++ b/static/scripts/common.js
@@ -108,6 +108,8 @@ define([
case 'set_notice_seen_by_id': return siteRoot + 'ajax/set_notice_seen_by_id/';
case 'repo_set_password': return siteRoot + 'repo/set_password/';
+
+ case 'group_repos': return siteRoot + 'api2/groups/' + options.group_id + '/repos/';
}
},
diff --git a/static/scripts/main.js b/static/scripts/main.js
new file mode 100644
index 0000000000..12a096aae8
--- /dev/null
+++ b/static/scripts/main.js
@@ -0,0 +1,4 @@
+//Load common code that includes config, then load the app logic for this page.
+require(['./common'], function (common) {
+ require(['app/main']);
+});