2015-02-01 06:15:00 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'app/collections/repos',
|
|
|
|
'app/views/repo',
|
|
|
|
'app/views/add-repo',
|
2017-06-23 04:02:03 +00:00
|
|
|
'app/views/repo-details',
|
|
|
|
'app/views/widgets/dropdown'
|
2017-06-26 08:08:54 +00:00
|
|
|
], function($, _, Backbone, Common, RepoCollection, RepoView, AddRepoView,
|
2017-06-23 04:02:03 +00:00
|
|
|
RepoDetailsView, DropdownView) {
|
2015-02-01 06:15:00 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ReposView = Backbone.View.extend({
|
2016-03-24 06:43:20 +00:00
|
|
|
id: "my-own-repos",
|
2015-02-01 06:15:00 +00:00
|
|
|
|
2016-03-24 06:43:20 +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',
|
2017-06-23 04:02:03 +00:00
|
|
|
'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();
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
this.render();
|
2017-06-23 04:02:03 +00:00
|
|
|
|
|
|
|
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() {
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$('.error').hide();
|
|
|
|
this.$loadingTip.hide();
|
2015-02-01 06:15:00 +00:00
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
this.renderReposHd();
|
|
|
|
this.$tableBody.empty();
|
2016-09-08 08:26:23 +00:00
|
|
|
|
|
|
|
// sort
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
|
|
|
|
2015-05-12 08:35:39 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
2015-02-01 06:15:00 +00:00
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$table.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
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();
|
2016-03-24 06:43:20 +00:00
|
|
|
this.$loadingTip.show();
|
2015-05-12 08:35:39 +00:00
|
|
|
var _this = this;
|
|
|
|
this.repos.fetch({
|
2015-10-08 09:54:59 +00:00
|
|
|
cache: false, // for IE
|
2015-05-12 08:35:39 +00:00
|
|
|
reset: true,
|
|
|
|
success: function (collection, response, opts) {
|
|
|
|
},
|
|
|
|
error: function (collection, response, opts) {
|
2016-03-24 06:43:20 +00:00
|
|
|
_this.$loadingTip.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +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() {
|
2016-03-24 06:43:20 +00:00
|
|
|
$("#right-panel").html(this.$el);
|
2015-02-01 06:15:00 +00:00
|
|
|
this.showMyRepos();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2016-03-24 06:43:20 +00:00
|
|
|
this.$el.detach();
|
2017-06-26 08:08:54 +00:00
|
|
|
|
|
|
|
this.repoDetailsView.hide();
|
2015-02-01 06:15:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createRepo: function() {
|
2015-04-22 10:45:28 +00:00
|
|
|
new AddRepoView(this.repos);
|
2015-02-01 06:15:00 +00:00
|
|
|
},
|
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
sortByName: function() {
|
2016-09-08 08:26:23 +00:00
|
|
|
Common.toggleSortByNameMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
this.$tableBody.empty();
|
2016-09-07 02:03:21 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
this.repos.comparator = null;
|
|
|
|
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-03-24 08:59:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function() {
|
2016-09-08 08:26:23 +00:00
|
|
|
Common.toggleSortByTimeMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
this.$tableBody.empty();
|
2016-09-07 02:03:21 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
this.repos.comparator = null;
|
|
|
|
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2017-06-23 04:02:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
closeDropdown: function() {
|
|
|
|
this.more_op_dropdown.hide();
|
2015-03-24 08:59:46 +00:00
|
|
|
}
|
2015-02-01 06:15:00 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return ReposView;
|
|
|
|
});
|