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',
|
2015-03-07 08:40:30 +00:00
|
|
|
'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({
|
2016-04-29 08:47:04 +00:00
|
|
|
id: 'organization',
|
2015-03-07 07:56:10 +00:00
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
template: _.template($('#organization-repos-tmpl').html()),
|
2015-05-11 10:39:21 +00:00
|
|
|
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
initialize: function(options) {
|
2016-03-24 06:43:20 +00:00
|
|
|
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');
|
2015-05-11 09:30:11 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +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() {
|
2015-04-22 10:45:28 +00:00
|
|
|
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() {
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$('.error').hide();
|
|
|
|
this.$loadingTip.hide();
|
2015-03-07 07:56:10 +00:00
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
this.renderReposHd();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
this.repos.each(this.addOne, this);
|
2015-03-07 07:56:10 +00:00
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$table.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$emptyTip.show();
|
2015-03-07 07:56:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showRepoList: function() {
|
2015-05-12 08:35:39 +00:00
|
|
|
var $loadingTip = this.$loadingTip;
|
|
|
|
$loadingTip.show();
|
|
|
|
var _this = this;
|
|
|
|
this.repos.fetch({
|
2015-10-08 09:54:59 +00:00
|
|
|
cache: false,
|
2015-05-12 08:35:39 +00:00
|
|
|
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-03-07 08:40:30 +00:00
|
|
|
},
|
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
sortByName: function() {
|
2015-07-11 06:51:26 +00:00
|
|
|
$('.by-time .sort-icon', this.$table).hide();
|
2015-03-24 08:59:46 +00:00
|
|
|
var repos = this.repos;
|
2016-06-30 07:06:43 +00:00
|
|
|
var $el = $('.by-name .sort-icon', this.$table);
|
|
|
|
if ($el.hasClass('icon-caret-up')) {
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
|
|
|
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
2015-04-30 03:59:09 +00:00
|
|
|
return -result;
|
2016-06-30 07:06:43 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
|
|
|
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
2015-04-30 03:59:09 +00:00
|
|
|
return result;
|
2016-06-30 07:06:43 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-24 08:59:46 +00:00
|
|
|
repos.sort();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
repos.each(this.addOne, this);
|
2016-06-30 07:06:43 +00:00
|
|
|
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
2015-05-11 07:31:03 +00:00
|
|
|
repos.comparator = null;
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-03-24 08:59:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function() {
|
2015-07-11 06:51:26 +00:00
|
|
|
$('.by-name .sort-icon', this.$table).hide();
|
2015-03-24 08:59:46 +00:00
|
|
|
var repos = this.repos;
|
2016-06-30 07:06:43 +00:00
|
|
|
var $el = $('.by-time .sort-icon', this.$table);
|
|
|
|
if ($el.hasClass('icon-caret-down')) {
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
2015-03-24 08:59:46 +00:00
|
|
|
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
2016-06-30 07:06:43 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
2015-03-24 08:59:46 +00:00
|
|
|
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
2016-06-30 07:06:43 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-24 08:59:46 +00:00
|
|
|
repos.sort();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
repos.each(this.addOne, this);
|
2016-06-30 07:06:43 +00:00
|
|
|
$el.toggleClass('icon-caret-up icon-caret-down').show();
|
2015-05-11 07:31:03 +00:00
|
|
|
repos.comparator = null;
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-03-07 07:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return OrganizationView;
|
|
|
|
});
|