1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-30 08:53:49 +00:00
seahub/static/scripts/app/views/myhome-repos.js

176 lines
5.6 KiB
JavaScript
Raw Normal View History

2015-02-01 06:15:00 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/repos',
'app/views/repo',
'app/views/add-repo',
'app/views/repo-details',
'app/views/widgets/dropdown'
2017-06-26 08:08:54 +00:00
], function($, _, Backbone, Common, RepoCollection, RepoView, AddRepoView,
RepoDetailsView, DropdownView) {
2015-02-01 06:15:00 +00:00
'use strict';
var ReposView = Backbone.View.extend({
2017-12-05 09:53:45 +00:00
el: '.main-panel',
2015-02-01 06:15:00 +00:00
template: _.template($('#my-own-repos-tmpl').html()),
2017-12-05 09:53:45 +00:00
toolbarTemplate: _.template($('#my-repos-toolbar-tmpl').html()),
theadTemplate: _.template($('#my-repos-thead-tmpl').html()),
theadMobileTemplate: _.template($('#my-repos-thead-mobile-tmpl').html()),
2015-05-11 10:39:21 +00:00
2015-02-01 06:15:00 +00:00
events: {
2017-12-05 09:53:45 +00:00
'click #my-repos-toolbar .repo-create': 'createRepo',
'click #my-libs-more-op a': 'closeDropdown',
'click #my-repos .by-name': 'sortByName',
'click #my-repos .by-time': 'sortByTime'
2015-02-01 06:15:00 +00:00
},
initialize: function(options) {
this.repos = new RepoCollection();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
2015-12-27 14:09:52 +00:00
this.repoDetailsView = new RepoDetailsView({'parentView': this});
2015-02-01 06:15:00 +00:00
},
addOne: function(repo, collection, options) {
2017-06-26 08:08:54 +00:00
var view = new RepoView({model: repo, myReposView: this});
2015-02-01 06:15:00 +00:00
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
},
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
2015-02-01 06:15:00 +00:00
if (this.repos.length) {
this.$emptyTip.hide();
2017-12-05 09:53:45 +00:00
this.renderThead();
this.$tableBody.empty();
2016-09-08 08:26:23 +00:00
// sort
2017-12-05 09:53:45 +00:00
Common.updateSortIconByMode({'context': this.$table});
2016-09-08 08:26:23 +00:00
Common.sortLibs({'libs': this.repos});
this.repos.each(this.addOne, this);
2015-02-01 06:15:00 +00:00
this.$table.show();
} else {
this.$table.hide();
this.$emptyTip.show();
2015-05-12 10:54:10 +00:00
}
if (app.pageOptions.guide_enabled) {
2017-12-05 09:53:45 +00:00
$('#guide-for-new').modal({focus:false});
2016-06-23 08:48:29 +00:00
$('#simplemodal-container').css({'height':'auto'});
2015-05-12 10:54:10 +00:00
app.pageOptions.guide_enabled = false;
2015-02-01 06:15:00 +00:00
}
},
showMyRepos: function() {
this.$table.hide();
this.$loadingTip.show();
var _this = this;
this.repos.fetch({
2017-12-05 09:53:45 +00:00
cache: false,
reset: true,
success: function (collection, response, opts) {
},
error: function (collection, response, opts) {
_this.$loadingTip.hide();
var $error = _this.$('.error');
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = gettext("Error");
}
} else {
err_msg = gettext('Please check the network.');
}
$error.html(err_msg).show();
}
});
2015-02-01 06:15:00 +00:00
},
2017-12-05 09:53:45 +00:00
renderThead: function() {
var tmpl = $(window).width() >= 768 ? this.theadTemplate : this.theadMobileTemplate;
this.$tableHead.html(tmpl());
},
renderToolbar: function() {
this.$toolbar = $('<div class="cur-view-toolbar" id="my-repos-toolbar"></div>').html(this.toolbarTemplate());
this.$('.common-toolbar').before(this.$toolbar);
this.more_op_dropdown = new DropdownView({
el: this.$("#my-libs-more-op")
});
},
renderMainCon: function() {
this.$mainCon = $('<div class="main-panel-main main-panel-main-with-side" id="my-repos"></div>').html(this.template());
this.$el.append(this.$mainCon);
this.$table = this.$('table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
2015-02-01 06:15:00 +00:00
show: function() {
2017-12-05 09:53:45 +00:00
if (!$('#my-repos').length) {
this.renderToolbar();
this.renderMainCon();
}
2015-02-01 06:15:00 +00:00
this.showMyRepos();
},
hide: function() {
2017-12-05 09:53:45 +00:00
this.$toolbar.detach();
this.$mainCon.detach();
2015-02-01 06:15:00 +00:00
},
createRepo: function() {
new AddRepoView(this.repos);
2015-02-01 06:15:00 +00:00
},
sortByName: function() {
2016-09-08 08:26:23 +00:00
Common.toggleSortByNameMode();
2017-12-05 09:53:45 +00:00
Common.updateSortIconByMode({'context': this.$table});
2016-09-08 08:26:23 +00:00
Common.sortLibs({'libs': this.repos});
this.$tableBody.empty();
this.repos.each(this.addOne, this);
this.repos.comparator = null;
return false;
},
sortByTime: function() {
2016-09-08 08:26:23 +00:00
Common.toggleSortByTimeMode();
2017-12-05 09:53:45 +00:00
Common.updateSortIconByMode({'context': this.$table});
2016-09-08 08:26:23 +00:00
Common.sortLibs({'libs': this.repos});
this.$tableBody.empty();
this.repos.each(this.addOne, this);
this.repos.comparator = null;
return false;
},
closeDropdown: function() {
this.more_op_dropdown.hide();
}
2015-02-01 06:15:00 +00:00
});
return ReposView;
});