1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-01 17:32:21 +00:00
seahub/static/scripts/app/views/myhome-repos.js

165 lines
5.1 KiB
JavaScript
Raw Normal View History

2015-02-01 06:15:00 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'js.cookie',
2015-02-01 06:15:00 +00:00
'app/collections/repos',
'app/views/repo',
'app/views/add-repo',
], function($, _, Backbone, Common, Cookies, RepoCollection, RepoView, AddRepoView) {
2015-02-01 06:15:00 +00:00
'use strict';
var ReposView = Backbone.View.extend({
id: "my-own-repos",
2015-02-01 06:15:00 +00:00
template: _.template($('#my-own-repos-tmpl').html()),
2015-05-11 10:39:21 +00:00
reposHdTemplate: _.template($('#my-repos-hd-tmpl').html()),
2015-02-01 06:15:00 +00:00
events: {
2015-04-20 08:38:59 +00:00
'click .repo-create': 'createRepo',
2015-11-24 04:10:17 +00:00
'click .by-name': 'sortByName',
'click .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.render();
2015-02-01 06:15:00 +00:00
},
addOne: function(repo, collection, options) {
var view = new RepoView({model: repo});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
},
2015-05-11 10:39:21 +00:00
renderReposHd: function() {
this.$tableHead.html(this.reposHdTemplate());
},
2015-02-01 06:15:00 +00:00
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
2015-02-01 06:15:00 +00:00
if (this.repos.length) {
this.$emptyTip.hide();
this.renderReposHd();
this.$tableBody.empty();
this.repos = Common.sortCollection(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
}
Common.updateSortIconByMode(this);
2015-05-12 10:54:10 +00:00
if (app.pageOptions.guide_enabled) {
$('#guide-for-new').modal({appendTo: '#main', 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({
2015-10-08 09:54:59 +00:00
cache: false, // for IE
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
},
render: function() {
this.$el.html(this.template());
this.$table = this.$('table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$repoCreateBtn = this.$('.repo-create');
return this;
},
2015-02-01 06:15:00 +00:00
show: function() {
$("#right-panel").html(this.$el);
2015-02-01 06:15:00 +00:00
this.showMyRepos();
},
hide: function() {
this.$el.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() {
if (app.pageOptions.sort_mode == 'name_up') {
// change sort mode
Cookies.set('sort_mode', 'name_down');
app.pageOptions.sort_mode = 'name_down';
2016-06-30 07:06:43 +00:00
} else {
Cookies.set('sort_mode', 'name_up');
app.pageOptions.sort_mode = 'name_up';
2016-06-30 07:06:43 +00:00
}
Common.updateSortIconByMode(this);
this.repos = Common.sortCollection(this.repos);
this.$tableBody.empty();
this.repos.each(this.addOne, this);
this.repos.comparator = null;
return false;
},
sortByTime: function() {
if (app.pageOptions.sort_mode == 'time_down') {
// change sort mode
Cookies.set('sort_mode', 'time_up');
app.pageOptions.sort_mode = 'time_up';
2016-06-30 07:06:43 +00:00
} else {
Cookies.set('sort_mode', 'time_down');
app.pageOptions.sort_mode = 'time_down';
2016-06-30 07:06:43 +00:00
}
Common.updateSortIconByMode(this);
this.repos = Common.sortCollection(this.repos);
this.$tableBody.empty();
this.repos.each(this.addOne, this);
this.repos.comparator = null;
return false;
}
2015-02-01 06:15:00 +00:00
});
return ReposView;
});