1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 08:16:07 +00:00

Merge pull request #1056 from haiwen/code-clean

clean code and icons
This commit is contained in:
llj
2016-03-14 19:57:08 +08:00
49 changed files with 26 additions and 1266 deletions

View File

@@ -1,15 +1,19 @@
define([
'underscore',
'backbone',
'common',
'app/models/pub-repo'
], function(_, Backbone, PubRepo) {
], function(_, Backbone, Common, PubRepo) {
'use strict';
var PubRepoCollection = Backbone.Collection.extend({
model: PubRepo,
url: app.pageOptions.pubReposUrl,
comparator: -'mtime'
comparator: -'mtime',
url: function() {
return Common.getUrl({name: 'pub_repos'});
}
});

View File

@@ -1,15 +1,19 @@
define([
'underscore',
'backbone',
'common',
'app/models/repo'
], function(_, Backbone, Repo) {
], function(_, Backbone, Common, Repo) {
'use strict';
var RepoCollection = Backbone.Collection.extend({
model: Repo,
url: app.pageOptions.reposUrl,
type: 'mine',
url: function() {
return Common.getUrl({name: 'repos'});
},
initialize: function(options) {
//console.log('init RepoCollection');
if (options) {
@@ -20,7 +24,7 @@ define([
fetch: function(options) {
// override default fetch url
options = options ? _.clone(options) : {};
options.url = this.url + '?type=' + this.type;
options.url = this.url() + '?type=' + this.type;
//call Backbone's fetch
return Backbone.Collection.prototype.fetch.call(this, options);

View File

@@ -18,8 +18,6 @@ define([
'': 'showRepos',
'my-libs/': 'showMyRepos',
'my-libs/lib/:repo_id(/*path)': 'showMyRepoDir',
'my-sub-libs/': 'showMySubRepos',
'my-sub-libs/lib/:repo_id(/*path)': 'showMySubRepoDir',
'shared-libs/': 'showSharedRepos',
'shared-libs/lib/:repo_id(/*path)': 'showSharedRepoDir',
'groups/': 'showGroups',
@@ -86,11 +84,6 @@ define([
this.sideNavView.setCurTab('mine');
},
showMySubRepos: function() {
this.switchCurrentView(this.myHomeView);
this.myHomeView.showMySubRepos();
},
showSharedRepos: function() {
this.switchCurrentView(this.myHomeView);
this.myHomeView.showSharedRepos();
@@ -130,17 +123,6 @@ define([
this.myHomeView.showDir('common', repo_id, path);
},
showMySubRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;
} else {
path = '/';
}
this.switchCurrentView(this.myHomeView);
this.myHomeView.showDir('my-sub-libs', repo_id, path);
this.sideNavView.setCurTab('sub-libs');
},
showSharedRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;

View File

@@ -1,170 +0,0 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'file-tree',
'app/collections/repos',
'app/views/sub-lib',
'app/views/add-repo',
], function($, _, Backbone, Common, FileTree, RepoCollection, RepoView, AddRepoView) {
'use strict';
var ReposView = Backbone.View.extend({
el: $('#my-sub-repos'),
events: {
'click #sub-lib-create': 'createRepo'
},
initialize: function(options) {
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.repos = new RepoCollection({type: 'sub'});
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
},
addOne: function(repo, collection, options) {
var view = new RepoView({model: repo});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
},
reset: function() {
this.$('.error').hide();
this.$tableBody.empty();
this.repos.each(this.addOne, this);
if (this.repos.length) {
this.$emptyTip.hide();
this.$table.show();
} else {
this.$emptyTip.show();
this.$table.hide();
}
this.$loadingTip.hide();
},
showSubRepos: function() {
this.$el.show();
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();
}
});
},
show: function() {
this.showSubRepos();
},
hide: function() {
this.$el.hide();
},
createRepo: function() {
var _this = this;
var sublib_create_form = $('#sublib-create-form');
var dir_tree_cont = $('.dir-tree-cont', sublib_create_form);
sublib_create_form.modal();
$.ajax({
url: Common.getUrl({'name': 'get_my_unenc_repos'}),
cache: false,
dataType: 'json',
success: function(data) {
var repos = FileTree.formatRepoData(data);
if (repos.length > 0) {
FileTree.renderDirTree(dir_tree_cont, sublib_create_form, repos);
} else {
dir_tree_cont.html('<p class="error">' + gettext("You don't have any library at present.") + '</p>');
}
},
error: function(jqXHR, textStatus, errorThrown) {
var error;
if (jqXHR.responseText) {
error = $.parseJSON(jqXHR.responseText).error;
} else {
error = gettext("Failed. Please check the network.");
}
dir_tree_cont.html('<p class="error">' + error + '</p>');
}
});
$('.submit', sublib_create_form).click(function() {
var ori_repo_id = $('[name="dst_repo"]', sublib_create_form).val();
var path = $('[name="dst_path"]', sublib_create_form).val();
if (!path || path == '/') {
$('.error', sublib_create_form).html(gettext("Please choose a directory")).removeClass('hide');
return false;
}
// path ends with '/', rm it here
path = path.substr(0, path.length - 1);
$.ajax({
url: Common.getUrl({'name':'sub_repo', 'repo_id':ori_repo_id}) + '?p=' + encodeURIComponent(path),
dataType: 'json',
success: function(data) {
$.modal.close();
var new_sub_lib = {
'id': data["sub_repo_id"],
'name': data["name"],
'origin_repo_id': ori_repo_id,
'origin_path': path,
'abbrev_origin_path': data["abbrev_origin_path"],
'mtime': new Date().getTime() / 1000,
'mtime_relative': gettext("Just now")
};
if (_this.repos.length > 0) {
_this.repos.add(new_sub_lib , {prepend: true});
} else {
_this.repos.reset([new_sub_lib]);
}
},
error: function(xhr, textStatus, errorThrown) {
var err;
if (xhr.responseText) {
err = jQuery.parseJSON(xhr.responseText).error;
} else {
err = gettext("Failed. Please check the network.");
}
$('.error', sublib_create_form).html(err).removeClass('hide');
}
});
return false;
});
}
});
return ReposView;
});

View File

@@ -4,11 +4,10 @@ define([
'backbone',
'common',
'app/views/myhome-repos',
'app/views/myhome-sub-repos',
'app/views/myhome-shared-repos',
'app/views/starred-file',
'app/views/activities'
], function($, _, Backbone, Common, ReposView, SubReposView,
], function($, _, Backbone, Common, ReposView,
SharedReposView, StarredFileView, ActivitiesView) {
'use strict';
@@ -17,7 +16,6 @@ define([
initialize: function(options) {
this.reposView = new ReposView();
this.subReposView = new SubReposView();
this.sharedReposView = new SharedReposView();
this.starredFileView = new StarredFileView();
this.activitiesView = new ActivitiesView();
@@ -35,12 +33,6 @@ define([
this.currentView = this.reposView;
},
showMySubRepos: function() {
this.currentView.hide();
this.subReposView.show();
this.currentView = this.subReposView;
},
showSharedRepos: function() {
this.currentView.hide();
this.sharedReposView.show();

View File

@@ -1,92 +0,0 @@
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var RepoView = Backbone.View.extend({
tagName: 'tr',
template: _.template($('#sub-lib-tmpl').html()),
repoDelConfirmTemplate: _.template($('#repo-del-confirm-template').html()),
events: {
'mouseenter': 'highlight',
'mouseleave': 'rmHighlight',
'click .repo-delete-btn': 'del'
},
initialize: function() {
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
},
// disable 'hover' when 'repo-del-confirm' popup is shown
highlight: function() {
if ($('#my-sub-repos .repo-del-confirm').length == 0) {
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
}
},
rmHighlight: function() {
if ($('#my-sub-repos .repo-del-confirm').length == 0) {
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
}
},
del: function() {
var del_icon = this.$('.repo-delete-btn');
var op_container = this.$('.op-container').css({'position': 'relative'});
var confirm_msg = gettext("Really want to delete {lib_name}?")
.replace('{lib_name}', '<span class="op-target">' + Common.HTMLescape(this.model.get('name')) + '</span>');
var confirm_popup = $(this.repoDelConfirmTemplate({
content: confirm_msg
}))
.appendTo(op_container)
.css({
'left': del_icon.position().left,
'top': del_icon.position().top + del_icon.height() + 2,
'width': 180
});
var _this = this;
$('.no', confirm_popup).click(function() {
confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor
_this.rmHighlight();
});
$('.yes', confirm_popup).click(function() {
$.ajax({
url: Common.getUrl({'name':'repo_del', 'repo_id': _this.model.get('id')}),
type: 'POST',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
success: function(data) {
_this.remove();
Common.feedback(gettext("Delete succeeded."), 'success');
},
error: function(xhr) {
confirm_popup.addClass('hide').remove();
_this.rmHighlight();
var err;
if (xhr.responseText) {
err = $.parseJSON(xhr.responseText).error;
} else {
err = gettext("Failed. Please check the network.");
}
Common.feedback(err, 'error');
}
});
});
}
});
return RepoView;
});

View File

@@ -89,6 +89,8 @@ define([
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
// Repos
case 'repos': return siteRoot + 'api2/repos/';
case 'pub_repos': return siteRoot + 'api2/repos/public/';
case 'repo_del': return siteRoot + 'ajax/repo/' + options.repo_id + '/remove/';
case 'sub_repo': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/sub_repo/';
case 'get_my_unenc_repos': return siteRoot + 'ajax/my-unenc-repos/';