1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 15:38:15 +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

@@ -0,0 +1,48 @@
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var HistorySettingsDialog = Backbone.View.extend({
tagName: 'div',
id: 'history-settings-dialog',
template: _.template($('#history-settings-dialog-tmpl').html()),
initialize: function(options) {
this.repo_name = options.repo_name;
this.repo_id = options.repo_id;
this.render();
this.$el.modal();
$("#simplemodal-container").css({'height':'auto'});
},
render: function() {
this.$el.html(this.template({
title: gettext("{placeholder} History Settings")
.replace('{placeholder}',
'<span class="op-target ellipsis ellipsis-op-target" title="'
+ Common.HTMLescape(this.repo_name) + '">'
+ Common.HTMLescape(this.repo_name) + '</span>'),
repo_id: this.repo_id,
// TODO: get settings from server
full_history_checked: true,
no_history_checked: false,
partial_history_checked: false,
history_limit: 30
}));
return this;
},
events: {
}
});
return HistorySettingsDialog;
});

View File

@@ -73,7 +73,7 @@ define([
// hide 'hidden-op' popup
$(document).click(function(e) {
var target = e.target || event.srcElement;
var $popup = $('.hidden-op:visible');
var $popup = $('.dirent-hidden-op:visible');
if ($popup.length > 0 && // There is a visible popup
!$('.more-op-icon', $popup.closest('tr')).is(target) &&
!$popup.is(target) &&

View File

@@ -144,7 +144,7 @@ define([
return false;
},
togglePopup: function () {
togglePopup: function() {
var icon = this.$('.more-op-icon'),
popup = this.$('.hidden-op');

View File

@@ -31,6 +31,31 @@ define([
this.repos = new RepoCollection();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
// hide 'hidden-op' popup
$(document).click(function(e) {
var target = e.target || event.srcElement;
var $popup = $('.repo-hidden-op:visible');
if ($popup.length > 0 && // There is a visible repo op popup
!$('.more-op-icon', $popup.closest('tr')).is(target) &&
!$popup.is(target) &&
!$popup.find('*').is(target)) {
// when the popup and op-icon is not target
// hide the popup and remove the highlight if the current repo
// is not the target
$popup.addClass('hide');
var $tr = $popup.closest('tr');
if (!$tr.find('*').is(target)) {
$tr.removeClass('hl').find('.op-icon').addClass('vh');
$('.my-own-repos-table tr:gt(0)').each(function() {
if ($(this).find('*').is(target)) {
$(this).addClass('hl').find('.op-icon').removeClass('vh');
}
});
}
}
});
},
addOne: function(repo, collection, options) {

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;
}
});