1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

Add repo operations

This commit is contained in:
Daniel Pan
2015-12-27 22:09:52 +08:00
committed by llj
parent a7eecaeff4
commit 8d12ea22c7
10 changed files with 251 additions and 28 deletions

View File

@@ -3,8 +3,9 @@ define([
'underscore',
'backbone',
'common',
'app/views/share'
], function($, _, Backbone, Common, ShareView) {
'app/views/share',
'app/views/dialogs/history-settings'
], function($, _, Backbone, Common, ShareView, HistorySettingsDialog) {
'use strict';
var RepoView = Backbone.View.extend({
@@ -12,31 +13,44 @@ define([
template: _.template($('#repo-tmpl').html()),
repoDelConfirmTemplate: _.template($('#repo-del-confirm-template').html()),
renameTemplate: _.template($("#repo-rename-form-template").html()),
events: {
'mouseenter': 'highlight',
'mouseleave': 'rmHighlight',
'click .repo-delete-btn': 'del',
'click .repo-share-btn': 'share'
'click .repo-share-btn': 'share',
'click .js-toggle-popup': 'togglePopup',
'click .js-repo-rename': 'rename',
'click .js-popup-history-settings': 'popupHistorySettings',
'click .js-popup-permission-settings': 'popupPermissionSettings'
},
initialize: function() {
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
var obj = this.model.toJSON();
$.extend(obj, {
enable_repo_history_setting: app.pageOptions.enable_repo_history_setting
});
this.$el.html(this.template(obj));
return this;
},
// disable 'hover' when 'repo-del-confirm' popup is shown
highlight: function() {
if ($('#my-own-repos .repo-del-confirm').length == 0) {
if ($('#my-own-repos .repo-del-confirm').length == 0
&& !$('.hidden-op:visible').length
&& !$('#repo-rename-form').length) {
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
}
},
rmHighlight: function() {
if ($('#my-own-repos .repo-del-confirm').length == 0) {
if ($('#my-own-repos .repo-del-confirm').length == 0
&& !$('.hidden-op:visible').length
&& !$('#repo-rename-form').length) {
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
}
},
@@ -100,6 +114,78 @@ define([
'obj_name': this.model.get('name')
};
new ShareView(options);
},
togglePopup: function() {
var icon = this.$('.js-toggle-popup'),
popup = this.$('.hidden-op');
if (popup.hasClass('hide')) { // the popup is not shown
popup.css({'left': icon.position().left});
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
// below the icon
popup.css('top', icon.position().top + icon.height() + 3);
} else {
popup.css('bottom', icon.parent().outerHeight() - icon.position().top + 3);
}
popup.removeClass('hide');
} else {
popup.addClass('hide');
}
},
rename: function() {
var repo_name = this.model.get('name');
var form = $(this.renameTemplate({
repo_name: repo_name
}));
var $name_span = this.$('.repo-name-span'),
$op_td = this.$('.repo-op-td'),
$name_td = $name_span.closest('td');
$name_td.attr('colspan', 2).css({
'width': $name_span.width() + $op_td.outerWidth(),
'height': $name_span.height()
}).append(form);
$op_td.hide();
$name_span.hide();
this.togglePopup();
var cancelRename = function() {
form.remove();
$op_td.show();
$name_span.show();
$name_td.attr('colspan', 1).css({
'width': $name_span.width()
});
return false; // stop bubbling (to 'doc click to hide .hidden-op')
};
$('.cancel', form).click(cancelRename);
return false;
},
popupHistorySettings: function() {
var options = {
'repo_name': this.model.get('name'),
'repo_id': this.model.get('id')
};
this.togglePopup(); // close the popup
new HistorySettingsDialog(options);
return false;
},
popupPermissionSettings: function() {
var options = {
'repo_name': this.model.get('name'),
'repo_id': this.model.get('id')
};
this.togglePopup(); // close the popup
new HistorySettingsDialog(options);
return false;
}
});