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

169 lines
5.2 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({
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()),
2016-11-29 07:03:13 +00:00
mobileReposHdTemplate: _.template($('#my-repos-hd-mobile-tmpl').html()),
2015-05-11 10:39:21 +00:00
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',
'click #my-libs-more-op a': 'closeDropdown'
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
2017-06-26 08:08:54 +00:00
this.repoDetailsView = new RepoDetailsView();
this.render();
this.more_op_dropdown = new DropdownView({
el: this.$("#my-libs-more-op"),
right: 0
})
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);
}
},
2015-05-11 10:39:21 +00:00
renderReposHd: function() {
2016-11-29 07:03:13 +00:00
var tmpl = $(window).width() >= 768 ? this.reposHdTemplate : this.mobileReposHdTemplate;
this.$tableHead.html(tmpl());
2015-05-11 10:39:21 +00:00
},
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();
2016-09-08 08:26:23 +00:00
// sort
Common.updateSortIconByMode({'context': this.$el});
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) {
$('#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();
2017-06-26 08:08:54 +00:00
this.repoDetailsView.hide();
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();
Common.updateSortIconByMode({'context': this.$el});
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();
Common.updateSortIconByMode({'context': this.$el});
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;
});