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

142 lines
3.9 KiB
JavaScript
Raw Normal View History

define([
'jquery',
'underscore',
'backbone',
2015-01-31 05:17:47 +00:00
'common',
'app/collections/repos',
'app/collections/dirents',
'app/collections/groups',
'app/views/repos',
2015-01-25 10:47:42 +00:00
'app/views/dirents',
'app/views/dir',
2015-01-31 05:17:47 +00:00
'app/views/group-nav',
'app/views/add-repo'
], function($, _, Backbone, Common, Repos, DirentCollection, GroupCollection,
RepoView, DirentView, DirView, GroupNavView, AddRepoView) {
'use strict';
var MyHomeView = Backbone.View.extend({
el: '#main',
2015-01-31 05:17:47 +00:00
events: {
'click #repo-create': 'createRepo',
},
initialize: function() {
console.log('init MyHomePage');
2015-01-31 05:17:47 +00:00
Common.prepareApiCsrf();
_.bindAll(this, 'ajaxLoadingShow', 'ajaxLoadingHide');
this.$el.ajaxStart(this.ajaxLoadingShow).ajaxStop(this.ajaxLoadingHide);
// this.on('showDirents', this.showDirents, this);
this.initializeRepos();
2015-01-25 10:47:42 +00:00
this.$repoTabs = this.$('#repo-tabs');
2015-01-31 05:17:47 +00:00
this.$cont = this.$('#right-panel');
this.$table = this.$('#my-own-repos table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
2015-01-25 10:47:42 +00:00
this.dirView = new DirView();
this.groupView = new GroupNavView();
},
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);
},
2015-01-31 05:17:47 +00:00
ajaxLoadingShow: function() {
Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT);
},
ajaxLoadingHide: function() {
$('.messages .info').hide();
},
addOne: function(repo, collection, options) {
console.log('add repo: ' + repo.get('name'));
var view = new RepoView({model: repo});
2015-01-31 05:17:47 +00:00
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
},
addAll: function() {
2015-01-31 05:17:47 +00:00
this.$tableBody.empty();
Repos.each(this.addOne, this);
},
2015-01-31 05:17:47 +00:00
hideTable: function() {
this.$table.hide();
},
2015-01-31 05:17:47 +00:00
showTable: function() {
this.$table.show();
},
2015-01-31 05:17:47 +00:00
hideLoading: function() {
this.$cont.find('.loading').hide();
},
2015-01-31 05:17:47 +00:00
showLoading: function() {
this.$cont.find('.loading').show();
},
hideEmptyTips: function() {
this.$cont.find('.empty-tips').hide();
},
showEmptyTips: function() {
this.$cont.find('.empty-tips').show();
},
render: function(eventName) {
console.log('render repos with event: ' + eventName);
2015-01-31 05:17:47 +00:00
this.$repoTabs.show();
this.$table.parent().show();
this.hideLoading();
if (Repos.length) {
2015-01-31 05:17:47 +00:00
this.hideEmptyTips();
this.showTable();
} else {
this.showEmptyTips();
this.hideTable();
}
},
showRepoList: function() {
console.log('show repo list');
Repos.fetch({reset: true});
2015-01-31 05:17:47 +00:00
2015-01-25 10:47:42 +00:00
this.dirView.hide();
},
2015-01-25 10:47:42 +00:00
showDir: function(repo_id, path) {
console.log('show dir ' + repo_id + ' ' + path);
2015-01-25 10:47:42 +00:00
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-31 05:17:47 +00:00
},
createRepo: function() {
new AddRepoView();
}
2015-01-25 10:47:42 +00:00
});
return MyHomeView;
});