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

158 lines
4.8 KiB
JavaScript
Raw Normal View History

2015-03-07 07:56:10 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
2015-04-03 09:01:13 +00:00
'app/collections/pub-repos',
'app/views/organization-repo',
2015-05-14 03:28:12 +00:00
'app/views/create-pub-repo',
2016-03-31 13:05:46 +00:00
'app/views/add-pub-repo',
'app/views/widgets/dropdown'
2015-04-03 09:01:13 +00:00
], function($, _, Backbone, Common, PubRepoCollection, OrganizationRepoView,
2016-03-31 13:05:46 +00:00
CreatePubRepoView, AddPubRepoView, DropdownView) {
2015-03-07 07:56:10 +00:00
'use strict';
var OrganizationView = Backbone.View.extend({
id: 'organization',
2015-03-07 07:56:10 +00:00
template: _.template($('#organization-repos-tmpl').html()),
2015-05-11 10:39:21 +00:00
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
initialize: function(options) {
this.repos = new PubRepoCollection();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
this.render();
},
render: function() {
this.$el.html(this.template());
2015-11-24 04:10:17 +00:00
this.$table = this.$('table');
this.$tableHead = $('thead', this.$table);
2015-03-07 07:56:10 +00:00
this.$tableBody = $('tbody', this.$table);
2015-11-24 04:10:17 +00:00
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
2015-03-07 07:56:10 +00:00
2016-03-31 13:05:46 +00:00
this.dropdown = new DropdownView({
el: this.$('.js-add-pub-lib-dropdown'),
right: '0px'
2015-05-28 05:57:00 +00:00
});
2015-03-07 07:56:10 +00:00
},
show: function() {
$("#right-panel").html(this.$el);
this.showRepoList();
},
hide: function() {
this.$el.detach();
},
2015-03-07 07:56:10 +00:00
events: {
2015-11-24 04:10:17 +00:00
'click .share-existing': 'addRepo',
'click .create-new': 'createRepo',
'click .by-name': 'sortByName',
'click .by-time': 'sortByTime'
2015-03-07 07:56:10 +00:00
},
createRepo: function() {
2015-05-14 03:28:12 +00:00
new CreatePubRepoView(this.repos);
2016-03-31 13:05:46 +00:00
this.dropdown.hide();
return false;
2015-05-14 03:28:12 +00:00
},
addRepo: function() {
new AddPubRepoView(this.repos);
2016-03-31 13:05:46 +00:00
this.dropdown.hide();
return false;
2015-03-07 07:56:10 +00:00
},
addOne: function(repo, collection, options) {
var view = new OrganizationRepoView({model: repo, collection: this.repos});
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-03-07 07:56:10 +00:00
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
2015-03-07 07:56:10 +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-03-07 07:56:10 +00:00
this.$table.show();
} else {
this.$table.hide();
this.$emptyTip.show();
2015-03-07 07:56:10 +00:00
}
},
2015-04-11 07:14:56 +00:00
showRepoList: function() {
var $loadingTip = this.$loadingTip;
$loadingTip.show();
var _this = this;
this.repos.fetch({
2015-10-08 09:54:59 +00:00
cache: false,
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();
}
});
},
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-03-07 07:56:10 +00:00
}
});
return OrganizationView;
});