mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
[backbone] Merge into one library app
This commit is contained in:
@@ -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;
|
||||
|
6
static/scripts/app/main.js
Normal file
6
static/scripts/app/main.js
Normal file
@@ -0,0 +1,6 @@
|
||||
define([
|
||||
'app/router'
|
||||
], function(Router){
|
||||
app.router = new Router();
|
||||
Backbone.history.start();
|
||||
});
|
138
static/scripts/app/router.js
Normal file
138
static/scripts/app/router.js
Normal file
@@ -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;
|
||||
});
|
@@ -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;
|
||||
},
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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',
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -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/';
|
||||
}
|
||||
},
|
||||
|
||||
|
4
static/scripts/main.js
Normal file
4
static/scripts/main.js
Normal file
@@ -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']);
|
||||
});
|
Reference in New Issue
Block a user