1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-05 03:07:01 +00:00
seahub/media/scripts/app/views/myhome.js

92 lines
2.8 KiB
JavaScript
Raw Normal View History

define([
'jquery',
'underscore',
'backbone',
'app/collections/repos',
'app/collections/dirents',
'app/views/repos',
2015-01-25 10:47:42 +00:00
'app/views/dirents',
'app/views/dir'
], function($, _, Backbone, Repos, DirentCollection, RepoView, DirentView, DirView) {
'use strict';
var MyHomeView = Backbone.View.extend({
el: '#main',
initialize: function() {
console.log('init MyHomePage');
// this.on('showDirents', this.showDirents, this);
this.$mine = this.$('#my-own-repos');
2015-01-25 10:47:42 +00:00
this.$repoTabs = this.$('#repo-tabs');
this.$repoList = this.$('#my-own-repos table tbody');
this.dirView = new DirView();
},
initializeRepos: function() {
this.listenTo(Repos, 'add', this.addOne);
this.listenTo(Repos, 'reset', this.addAll);
// this.listenTo(Repos, 'sync', this.render);
this.listenTo(Repos, 'all', this.render);
},
addOne: function(repo) {
2015-01-25 10:47:42 +00:00
console.log('add repo: ' + repo.owner);
var view = new RepoView({model: repo});
this.$repoList.append(view.render().el);
},
addAll: function() {
this.$repoList.empty();
Repos.each(this.addOne, this);
},
addOneDirent: function(dirent) {
var view = new DirentView({model: dirent});
this.$repoList.append(view.render().el);
},
addAllDirent: function() {
this.$repoList.empty();
this.dirents.each(this.addOneDirent, this);
},
renderDirent: function(eventName) {
console.log('render dirents with event: ' + eventName);
if (this.dirents.length) {
this.$mine.show();
}
},
render: function(eventName) {
console.log('render repos with event: ' + eventName);
if (Repos.length) {
this.$mine.show();
}
},
showRepoList: function() {
console.log('show repo list');
this.initializeRepos();
Repos.fetch({reset: true});
2015-01-25 10:47:42 +00:00
this.dirView.hide();
this.$repoTabs.show();
// $('#my-own-repos table').append(new RepoView().render().el);
},
2015-01-25 10:47:42 +00:00
showDir: function(repo_id, path) {
console.log('show dir' + repo_id + ' ' + path);
this.$repoTabs.hide();
var path = path || '/';
2015-01-25 10:47:42 +00:00
this.dirView.showDir(repo_id, path);
// this.dirent_list = new app.DirentListView({id: id, path: path});
// $('#my-own-repos table').children().remove();
// $('#my-own-repos table').append(this.dirent_list.render().el);
}
2015-01-25 10:47:42 +00:00
});
return MyHomeView;
});