1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 08:27:55 +00:00
seahub/static/scripts/app/views/myhome-shared-repos.js

139 lines
4.3 KiB
JavaScript
Raw Normal View History

2015-02-04 13:57:26 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/repos',
'app/views/shared-repo'
2016-09-08 08:26:23 +00:00
], function($, _, Backbone, Common, RepoCollection, SharedRepoView) {
2015-02-04 13:57:26 +00:00
'use strict';
var SharedReposView = Backbone.View.extend({
id: 'repos-shared-to-me',
2015-02-04 13:57:26 +00:00
template: _.template($('#repos-shared-to-me-tmpl').html()),
2015-05-11 10:39:21 +00:00
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
mobileReposHdTemplate: _.template($('#shared-repos-hd-mobile-tmpl').html()),
2015-05-11 10:39:21 +00:00
2015-02-04 13:57:26 +00:00
initialize: function(options) {
this.repos = new RepoCollection({type: 'shared'});
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
this.render();
2015-02-04 13:57:26 +00:00
},
addOne: function(repo, collection, options) {
2015-03-06 09:53:41 +00:00
var view = new SharedRepoView({model: repo, collection: this.repos});
2015-02-04 13:57:26 +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() {
var tmpl = $(window).width() >= 768 ? this.reposHdTemplate : this.mobileReposHdTemplate;
this.$tableHead.html(tmpl());
2015-05-11 10:39:21 +00:00
},
2015-02-04 13:57:26 +00:00
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
2015-02-04 13:57:26 +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-04 13:57:26 +00:00
this.$table.show();
} else {
this.$emptyTip.show();
this.$table.hide();
}
2015-02-04 13:57:26 +00:00
},
showSharedRepos: function() {
2015-11-24 04:10:17 +00:00
this.$el.show();
2015-02-04 13:57:26 +00:00
this.$table.hide();
var $loadingTip = this.$loadingTip;
$loadingTip.show();
var _this = this;
this.repos.fetch({
reset: true,
success: function (collection, response, opts) {
},
error: function (collection, response, opts) {
$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-04 13:57:26 +00:00
},
render: function() {
this.$el.html(this.template());
this.$table = this.$('table');
this.$tableHead = this.$('thead');
this.$tableBody = this.$('tbody');
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
return this;
},
2015-02-04 13:57:26 +00:00
show: function() {
$("#right-panel").html(this.$el);
2015-02-04 13:57:26 +00:00
this.showSharedRepos();
},
hide: function() {
this.$el.detach();
2015-02-04 13:57:26 +00:00
},
events: {
2015-11-24 04:10:17 +00:00
'click .by-name': 'sortByName',
'click .by-time': 'sortByTime'
},
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;
}
2015-02-04 13:57:26 +00:00
});
return SharedReposView;
});