2015-01-20 10:25:10 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2015-01-31 05:17:47 +00:00
|
|
|
'common',
|
2015-01-20 10:25:10 +00:00
|
|
|
'app/collections/repos',
|
|
|
|
'app/collections/dirents',
|
2015-01-27 14:41:16 +00:00
|
|
|
'app/collections/groups',
|
2015-01-20 10:25:10 +00:00
|
|
|
'app/views/repos',
|
2015-01-25 10:47:42 +00:00
|
|
|
'app/views/dirents',
|
2015-01-27 14:41:16 +00:00
|
|
|
'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) {
|
2015-01-20 10:25:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MyHomeView = Backbone.View.extend({
|
|
|
|
el: '#main',
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
events: {
|
|
|
|
'click #repo-create': 'createRepo',
|
|
|
|
},
|
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
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);
|
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
// this.on('showDirents', this.showDirents, this);
|
2015-01-31 06:17:56 +00:00
|
|
|
this.initializeRepos();
|
2015-01-20 10:25:10 +00:00
|
|
|
|
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();
|
2015-01-27 14:41:16 +00:00
|
|
|
|
|
|
|
this.groupView = new GroupNavView();
|
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);
|
|
|
|
},
|
|
|
|
|
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'));
|
2015-01-20 10:25:10 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addAll: function() {
|
2015-01-31 05:17:47 +00:00
|
|
|
this.$tableBody.empty();
|
2015-01-20 10:25:10 +00:00
|
|
|
Repos.each(this.addOne, this);
|
|
|
|
},
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
hideTable: function() {
|
|
|
|
this.$table.hide();
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
showTable: function() {
|
|
|
|
this.$table.show();
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
hideLoading: function() {
|
|
|
|
this.$cont.find('.loading').hide();
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
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();
|
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
if (Repos.length) {
|
2015-01-31 05:17:47 +00:00
|
|
|
this.hideEmptyTips();
|
|
|
|
this.showTable();
|
|
|
|
} else {
|
|
|
|
this.showEmptyTips();
|
|
|
|
this.hideTable();
|
2015-01-20 10:25:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
2015-01-25 10:47:42 +00:00
|
|
|
showDir: function(repo_id, path) {
|
2015-01-31 04:07:49 +00:00
|
|
|
console.log('show dir ' + repo_id + ' ' + path);
|
2015-01-25 10:47:42 +00:00
|
|
|
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-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createRepo: function() {
|
|
|
|
new AddRepoView();
|
2015-01-20 10:25:10 +00:00
|
|
|
}
|
2015-01-25 10:47:42 +00:00
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return MyHomeView;
|
|
|
|
});
|