mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-21 11:27:18 +00:00
[myhome] added 'repo delete'.
Conflicts: seahub/templates/js/lib-op-popups.html
This commit is contained in:
@@ -12,18 +12,16 @@ define([
|
|||||||
tagName: 'tr',
|
tagName: 'tr',
|
||||||
|
|
||||||
template: _.template(reposTemplate),
|
template: _.template(reposTemplate),
|
||||||
|
repoDelConfirmTemplate: _.template($('#repo-del-confirm-template').html()),
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'mouseenter': 'showAction',
|
'mouseenter': 'highlight',
|
||||||
'mouseleave': 'hideAction',
|
'mouseleave': 'rmHighlight',
|
||||||
'click .repo-delete-btn': 'delete',
|
'click .repo-delete-btn': 'del',
|
||||||
'click .repo-share-btn': 'share'
|
'click .repo-share-btn': 'share'
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
console.log('init RepoView');
|
|
||||||
|
|
||||||
this.listenTo(this.model, 'destroy', this.remove);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -31,67 +29,62 @@ define([
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
showAction: function() {
|
// disable 'hover' when 'repo-del-confirm' popup is shown
|
||||||
this.$el.addClass('hl');
|
highlight: function() {
|
||||||
this.$el.find('.op-icon').removeClass('vh');
|
if ($('#my-own-repos .repo-del-confirm').length == 0) {
|
||||||
},
|
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
|
||||||
|
|
||||||
hideAction: function() {
|
|
||||||
this.$el.removeClass('hl');
|
|
||||||
this.$el.find('.op-icon').addClass('vh');
|
|
||||||
},
|
|
||||||
|
|
||||||
showDelConfirm: function($target, msg, yesCallback) {
|
|
||||||
// TODO: need to refactor, copied from repo_del_js.html
|
|
||||||
|
|
||||||
var op = $target,
|
|
||||||
cont = op.parent().css({'position': 'relative'}),
|
|
||||||
cfm;
|
|
||||||
|
|
||||||
// only show 1 popup each time.
|
|
||||||
$('.repo-del-cfm', op.parents('table')).addClass('hide');
|
|
||||||
|
|
||||||
if (cont.find('.repo-del-cfm').length == 1) {
|
|
||||||
cfm = cont.find('.repo-del-cfm');
|
|
||||||
} else {
|
|
||||||
cfm = $('#repo-del-cfm-popup').clone().removeAttr('id');
|
|
||||||
cont.append(cfm);
|
|
||||||
cfm.css({'left': op.position().left, 'top': op.position().top + op.height() + 2, 'width':202});
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
var con = $('.con', cfm);
|
rmHighlight: function() {
|
||||||
con.html(msg.replace('{placeholder}', '<span class="op-target">' + this.model.get("name") + '</span>'));
|
if ($('#my-own-repos .repo-del-confirm').length == 0) {
|
||||||
cfm.removeClass('hide');
|
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
|
||||||
$('.no',cfm).click(function() {
|
}
|
||||||
cfm.addClass('hide');
|
},
|
||||||
|
|
||||||
|
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
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.yes', cfm).click(yesCallback);
|
var _this = this;
|
||||||
},
|
$('.no', confirm_popup).click(function() {
|
||||||
|
confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor
|
||||||
delete: function(e) {
|
_this.rmHighlight();
|
||||||
e.preventDefault();
|
});
|
||||||
|
$('.yes', confirm_popup).click(function() {
|
||||||
var that = this;
|
$.ajax({
|
||||||
var yesCallback = function() {
|
url: Common.getUrl({'name':'repo_del', 'repo_id': _this.model.get('id')}),
|
||||||
Common.feedback(gettext('Loading...'), 'info', Common.INFO_TIMEOUT); // TODO: what if there is still response after 10 secs ?
|
dataType: 'json',
|
||||||
that.model.destroy({
|
success: function(data) {
|
||||||
wait: true,
|
_this.remove();
|
||||||
success: function(model, rep) {
|
Common.feedback(gettext("Delete succeeded."), 'success');
|
||||||
Common.feedback(gettext('Delete succeeded'), 'success', Common.SUCCESS_TIMOUT);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr) {
|
||||||
Common.feedback(gettext('Error'), 'error', Common.ERROR_TIMEOUT);
|
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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
this.showDelConfirm(
|
|
||||||
$(e.target),
|
|
||||||
gettext('Really want to delete {placeholder} ?')
|
|
||||||
.replace(/\{placeholder\}/g, '<span class="op-target">' + this.model.get('name') + '</span>'),
|
|
||||||
yesCallback
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
share: function() {
|
share: function() {
|
||||||
|
@@ -12,16 +12,16 @@ define([
|
|||||||
tagName: 'tr',
|
tagName: 'tr',
|
||||||
|
|
||||||
template: _.template(reposTemplate),
|
template: _.template(reposTemplate),
|
||||||
|
repoDelConfirmTemplate: _.template($('#repo-del-confirm-template').html()),
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'mouseenter': 'showAction',
|
'mouseenter': 'highlight',
|
||||||
'mouseleave': 'hideAction',
|
'mouseleave': 'rmHighlight',
|
||||||
'click .repo-delete-btn': 'delete',
|
'click .repo-delete-btn': 'del',
|
||||||
'click .repo-share-btn': 'share'
|
'click .repo-share-btn': 'share'
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.listenTo(this.model, 'destroy', this.remove);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -29,67 +29,62 @@ define([
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
showAction: function() {
|
// disable 'hover' when 'repo-del-confirm' popup is shown
|
||||||
this.$el.addClass('hl');
|
highlight: function() {
|
||||||
this.$el.find('.op-icon').removeClass('vh');
|
if ($('#my-sub-repos .repo-del-confirm').length == 0) {
|
||||||
},
|
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
|
||||||
|
|
||||||
hideAction: function() {
|
|
||||||
this.$el.removeClass('hl');
|
|
||||||
this.$el.find('.op-icon').addClass('vh');
|
|
||||||
},
|
|
||||||
|
|
||||||
showDelConfirm: function($target, msg, yesCallback) {
|
|
||||||
// TODO: need to refactor, copied from repo_del_js.html
|
|
||||||
|
|
||||||
var op = $target,
|
|
||||||
cont = op.parent().css({'position': 'relative'}),
|
|
||||||
cfm;
|
|
||||||
|
|
||||||
// only show 1 popup each time.
|
|
||||||
$('.repo-del-cfm', op.parents('table')).addClass('hide');
|
|
||||||
|
|
||||||
if (cont.find('.repo-del-cfm').length == 1) {
|
|
||||||
cfm = cont.find('.repo-del-cfm');
|
|
||||||
} else {
|
|
||||||
cfm = $('#repo-del-cfm-popup').clone().removeAttr('id');
|
|
||||||
cont.append(cfm);
|
|
||||||
cfm.css({'left': op.position().left, 'top': op.position().top + op.height() + 2, 'width':202});
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
var con = $('.con', cfm);
|
rmHighlight: function() {
|
||||||
con.html(msg.replace('{placeholder}', '<span class="op-target">' + this.model.get("name") + '</span>'));
|
if ($('#my-sub-repos .repo-del-confirm').length == 0) {
|
||||||
cfm.removeClass('hide');
|
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
|
||||||
$('.no',cfm).click(function() {
|
}
|
||||||
cfm.addClass('hide');
|
},
|
||||||
|
|
||||||
|
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
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.yes', cfm).click(yesCallback);
|
var _this = this;
|
||||||
},
|
$('.no', confirm_popup).click(function() {
|
||||||
|
confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor
|
||||||
delete: function(e) {
|
_this.rmHighlight();
|
||||||
e.preventDefault();
|
});
|
||||||
|
$('.yes', confirm_popup).click(function() {
|
||||||
var that = this;
|
$.ajax({
|
||||||
var yesCallback = function() {
|
url: Common.getUrl({'name':'repo_del', 'repo_id': _this.model.get('id')}),
|
||||||
Common.feedback(gettext('Loading...'), 'info', Common.INFO_TIMEOUT); // TODO: what if there is still response after 10 secs ?
|
dataType: 'json',
|
||||||
that.model.destroy({
|
success: function(data) {
|
||||||
wait: true,
|
_this.remove();
|
||||||
success: function(model, rep) {
|
Common.feedback(gettext("Delete succeeded."), 'success');
|
||||||
Common.feedback(gettext('Delete succeeded'), 'success', Common.SUCCESS_TIMOUT);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr) {
|
||||||
Common.feedback(gettext('Error'), 'error', Common.ERROR_TIMEOUT);
|
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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
this.showDelConfirm(
|
|
||||||
$(e.target),
|
|
||||||
gettext('Really want to delete {placeholder} ?')
|
|
||||||
.replace(/\{placeholder\}/g, '<span class="op-target">' + this.model.get('name') + '</span>'),
|
|
||||||
yesCallback
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
share: function() {
|
share: function() {
|
||||||
|
@@ -75,7 +75,10 @@ define([
|
|||||||
case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/';
|
case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/';
|
||||||
case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/';
|
case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/';
|
||||||
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
|
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';
|
||||||
|
case 'repo_del': return siteRoot + 'ajax/repo/' + options.repo_id + '/remove/';
|
||||||
|
|
||||||
case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/';
|
case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/';
|
||||||
|
|
||||||
case 'unenc_rw_repos': return siteRoot + 'ajax/unenc-rw-repos/';
|
case 'unenc_rw_repos': return siteRoot + 'ajax/unenc-rw-repos/';
|
||||||
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
|
case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/';
|
||||||
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
|
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
|
||||||
|
@@ -122,3 +122,11 @@
|
|||||||
<button class="simplemodal-close btn">{% trans "Cancel" %}</button>
|
<button class="simplemodal-close btn">{% trans "Cancel" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/template" id="repo-del-confirm-template">
|
||||||
|
<div class="op-confirm repo-del-confirm">
|
||||||
|
<p><%= content %></p>
|
||||||
|
<button class="yes">{% trans "Yes" %}</button>
|
||||||
|
<button class="no">{% trans "No" %}</button>
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<td><%- desc %></td>
|
<td><%- desc %></td>
|
||||||
<td><%- mtime_relative %></td>
|
<td><%- mtime_relative %></td>
|
||||||
<td>
|
<td>
|
||||||
<div>
|
<div class="op-container">
|
||||||
<img src="{{ MEDIA_URL }}img/share_20.png" alt="" class="repo-share-btn op-icon vh" title="{% trans "Share" %}" />
|
<img src="{{ MEDIA_URL }}img/share_20.png" alt="" class="repo-share-btn op-icon vh" title="{% trans "Share" %}" />
|
||||||
<img src="{{ MEDIA_URL }}img/rm.png" class="repo-delete-btn op-icon vh" title="{% trans "Delete" %}" />
|
<img src="{{ MEDIA_URL }}img/rm.png" class="repo-delete-btn op-icon vh" title="{% trans "Delete" %}" />
|
||||||
</div>
|
</div>
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<td><a href="#my-libs/lib/<%= origin_repo_id %><%- origin_path %>"><%- abbrev_origin_path %></a></td>
|
<td><a href="#my-libs/lib/<%= origin_repo_id %><%- origin_path %>"><%- abbrev_origin_path %></a></td>
|
||||||
<td><%- mtime_relative %></td>
|
<td><%- mtime_relative %></td>
|
||||||
<td>
|
<td>
|
||||||
<div>
|
<div class="op-container">
|
||||||
<% if (is_original_owner) { %>
|
<% if (is_original_owner) { %>
|
||||||
<img src="{{MEDIA_URL}}img/share_20.png" alt="" class="repo-share-btn op-icon vh" title="{% trans "Share" %}" />
|
<img src="{{MEDIA_URL}}img/share_20.png" alt="" class="repo-share-btn op-icon vh" title="{% trans "Share" %}" />
|
||||||
<% } %>
|
<% } %>
|
||||||
|
Reference in New Issue
Block a user