2015-01-20 10:25:10 +00:00
|
|
|
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) {
|
2015-01-20 10:25:10 +00:00
|
|
|
'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();
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
2015-01-20 10:25:10 +00:00
|
|
|
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();
|
2015-01-20 10:25:10 +00:00
|
|
|
// $('#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();
|
2015-01-20 10:25:10 +00:00
|
|
|
|
|
|
|
var path = path || '/';
|
2015-01-25 10:47:42 +00:00
|
|
|
this.dirView.showDir(repo_id, path);
|
2015-01-20 10:25:10 +00:00
|
|
|
// 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
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return MyHomeView;
|
|
|
|
});
|