mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-24 21:07:17 +00:00
[backbone] Add shared repo view
This commit is contained in:
@@ -8,15 +8,19 @@ define([
|
||||
var RepoCollection = Backbone.Collection.extend({
|
||||
model: Repo,
|
||||
url: app.pageOptions.reposUrl,
|
||||
type: 'mine',
|
||||
|
||||
initialize: function() {
|
||||
initialize: function(options) {
|
||||
//console.log('init RepoCollection');
|
||||
if (options) {
|
||||
this.type = options.type ? options.type : 'mine';
|
||||
}
|
||||
},
|
||||
|
||||
fetch: function(options) {
|
||||
// override default fetch url
|
||||
options = options ? _.clone(options) : {};
|
||||
options.url = this.url + '?type=mine'
|
||||
options.url = this.url + '?type=' + this.type;
|
||||
|
||||
//call Backbone's fetch
|
||||
return Backbone.Collection.prototype.fetch.call(this, options);
|
||||
|
@@ -10,6 +10,8 @@ define([
|
||||
var MyHomeRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
'lib/:repo_id(/*path)': 'showDir',
|
||||
'my-libs': 'showMyRepos',
|
||||
'shared-libs': 'showSharedRepos',
|
||||
|
||||
// Default
|
||||
'*actions': 'defaultAction'
|
||||
@@ -29,11 +31,21 @@ define([
|
||||
this.myHomeView.showDir(repo_id, path);
|
||||
},
|
||||
|
||||
showMyRepos: function() {
|
||||
console.log("show My Repos");
|
||||
this.myHomeView.showMyRepos();
|
||||
},
|
||||
|
||||
showSharedRepos: function() {
|
||||
console.log("show shared repos");
|
||||
this.myHomeView.showSharedRepos();
|
||||
},
|
||||
|
||||
defaultAction: function(actions) {
|
||||
// We have no matching route, lets just log what the URL was
|
||||
console.log('No route:', actions);
|
||||
|
||||
this.myHomeView.showRepoList();
|
||||
this.myHomeView.showMyRepos();
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -69,6 +69,7 @@ define([
|
||||
|
||||
hide: function() {
|
||||
this.$el.hide();
|
||||
this.$table.hide();
|
||||
},
|
||||
|
||||
createRepo: function() {
|
||||
|
74
media/scripts/app/views/myhome-shared-repos.js
Normal file
74
media/scripts/app/views/myhome-shared-repos.js
Normal file
@@ -0,0 +1,74 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/repos',
|
||||
'app/views/shared-repo',
|
||||
], function($, _, Backbone, Common, RepoCollection, SharedRepoView) {
|
||||
'use strict';
|
||||
|
||||
var SharedReposView = Backbone.View.extend({
|
||||
el: $('#repo-tabs'),
|
||||
|
||||
initialize: function(options) {
|
||||
this.$tabs = $('#repo-tabs');
|
||||
this.$table = this.$('#repos-shared-to-me table');
|
||||
this.$tableHead = $('thead', this.$table);
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = $('.loading-tip', this.$tabs);
|
||||
this.$emptyTip = $('.empty-tips', this.tabs);
|
||||
|
||||
this.repos = new RepoCollection({type: 'shared'});
|
||||
this.listenTo(this.repos, 'add', this.addOne);
|
||||
this.listenTo(this.repos, 'reset', this.reset);
|
||||
},
|
||||
|
||||
addOne: function(repo, collection, options) {
|
||||
var view = new SharedRepoView({model: repo});
|
||||
if (options.prepend) {
|
||||
this.$tableBody.prepend(view.render().el);
|
||||
} else {
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$tableBody.empty();
|
||||
this.repos.each(this.addOne, this);
|
||||
if (this.repos.length) {
|
||||
this.$emptyTip.hide();
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
this.$table.hide();
|
||||
}
|
||||
this.$loadingTip.hide();
|
||||
},
|
||||
|
||||
renderPath: function() {
|
||||
//
|
||||
},
|
||||
|
||||
showSharedRepos: function() {
|
||||
this.repos.fetch({reset: true});
|
||||
this.$tabs.show();
|
||||
//this.$table.parent().show();
|
||||
this.$table.hide();
|
||||
this.$loadingTip.show();
|
||||
},
|
||||
|
||||
show: function() {
|
||||
this.showSharedRepos();
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.hide();
|
||||
this.$table.hide();
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
return SharedReposView;
|
||||
});
|
@@ -5,10 +5,11 @@ define([
|
||||
'common',
|
||||
'app/collections/groups',
|
||||
'app/views/myhome-repos',
|
||||
'app/views/myhome-shared-repos',
|
||||
'app/views/dir',
|
||||
'app/views/group-nav',
|
||||
], function($, _, Backbone, Common, GroupCollection,
|
||||
ReposView, DirView, GroupNavView) {
|
||||
ReposView, SharedReposView, DirView, GroupNavView) {
|
||||
'use strict';
|
||||
|
||||
var MyHomeView = Backbone.View.extend({
|
||||
@@ -24,6 +25,7 @@ define([
|
||||
this.$cont = this.$('#right-panel');
|
||||
|
||||
this.reposView = new ReposView();
|
||||
this.sharedReposView = new SharedReposView();
|
||||
this.dirView = new DirView();
|
||||
this.groupView = new GroupNavView();
|
||||
},
|
||||
@@ -45,12 +47,19 @@ define([
|
||||
this.$cont.find('.loading').show();
|
||||
},
|
||||
|
||||
showRepoList: function() {
|
||||
showMyRepos: function() {
|
||||
console.log('show repo list');
|
||||
this.sharedReposView.hide();
|
||||
this.reposView.show();
|
||||
this.dirView.hide();
|
||||
},
|
||||
|
||||
showSharedRepos: function() {
|
||||
this.dirView.hide();
|
||||
this.reposView.hide();
|
||||
this.sharedReposView.show();
|
||||
},
|
||||
|
||||
showDir: function(repo_id, path) {
|
||||
console.log('show dir ' + repo_id + ' ' + path);
|
||||
|
||||
|
@@ -3,7 +3,7 @@ define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'text!' + app.config._tmplRoot + 'repos.html'
|
||||
'text!' + app.config._tmplRoot + 'repo.html'
|
||||
], function($, _, Backbone, Common, reposTemplate) {
|
||||
'use strict';
|
||||
|
||||
@@ -18,7 +18,7 @@ define([
|
||||
'click .repo-delete-btn': 'delete',
|
||||
'click .repo-share-btn': 'share'
|
||||
},
|
||||
|
||||
|
||||
initialize: function() {
|
||||
console.log('init RepoView');
|
||||
|
||||
|
45
media/scripts/app/views/shared-repo.js
Normal file
45
media/scripts/app/views/shared-repo.js
Normal file
@@ -0,0 +1,45 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'text!' + app.config._tmplRoot + 'shared-repo.html'
|
||||
], function($, _, Backbone, Common, reposTemplate) {
|
||||
'use strict';
|
||||
|
||||
var SharedRepoView = Backbone.View.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template(reposTemplate),
|
||||
|
||||
events: {
|
||||
'mouseenter': 'showAction',
|
||||
'mouseleave': 'hideAction',
|
||||
'click .repo-delete-btn': 'delete',
|
||||
'click .repo-share-btn': 'share'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, 'destroy', this.remove);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
return this;
|
||||
},
|
||||
|
||||
showAction: function() {
|
||||
this.$el.addClass('hl');
|
||||
this.$el.find('.op-icon').removeClass('vh');
|
||||
},
|
||||
|
||||
hideAction: function() {
|
||||
this.$el.removeClass('hl');
|
||||
this.$el.find('.op-icon').addClass('vh');
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
return SharedRepoView;
|
||||
});
|
Reference in New Issue
Block a user