1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 12:27:48 +00:00

[repo] modified mv/cp

This commit is contained in:
llj
2014-08-25 19:07:38 +08:00
parent fc62b92bd3
commit b23d1be206
2 changed files with 21 additions and 27 deletions

View File

@@ -187,7 +187,7 @@
<input type="hidden" name="dst_repo" value="" /> <input type="hidden" name="dst_repo" value="" />
<input type="hidden" name="dst_path" value="" /> <input type="hidden" name="dst_path" value="" />
<p class="error hide">{% trans "Please click and choose a directory."%}</p> <p class="error hide">{% trans "Please click and choose a directory."%}</p>
<input type="submit" value="{% trans "Submit" %}" class="submit" /> <button type="submit" class="submit">{% trans "Submit" %}</button>
<button class="simplemodal-close">{% trans "Cancel"%}</button> <button class="simplemodal-close">{% trans "Cancel"%}</button>
</form> </form>
@@ -662,12 +662,11 @@ $('#mv-dirents, #cp-dirents').click(function() {
'dst_path': dst_path 'dst_path': dst_path
}; };
var after_op_success = function (data) { var after_op_success = function (data) {
var det_text = op == 'mv' ? "{% trans "Moving file %(index)s of %(total)s" %}": "{% trans "Copying file %(index)s of %(total)s" %}";
details.html(det_text.replace('%(index)s', i + 1).replace('%(total)s', op_objs.length)).removeClass('vh');
cancel_btn.removeClass('hide'); cancel_btn.removeClass('hide');
var det_text = op == 'mv' ? "{% trans "Moving %(name)s" %}": "{% trans "Copying %(name)s" %}";
details.html(det_text.replace('%(name)s', trimFilename(obj_name, 20)));
var req_progress = function () { var req_progress = function () {
var task_id = data['task_id']; var task_id = data['task_id'];
var msg = data['msg'];
cancel_btn.data('task_id', task_id); cancel_btn.data('task_id', task_id);
$.ajax({ $.ajax({
url: '{% url "get_cp_progress" %}?task_id=' + e(task_id), url: '{% url "get_cp_progress" %}?task_id=' + e(task_id),
@@ -675,29 +674,22 @@ $('#mv-dirents, #cp-dirents').click(function() {
success: function(data) { success: function(data) {
var bar = $('.ui-progressbar-value', $('#mv-progress')); var bar = $('.ui-progressbar-value', $('#mv-progress'));
if (!data['failed'] && !data['canceled'] && !data['successful']) { if (!data['failed'] && !data['canceled'] && !data['successful']) {
bar.css('width', parseInt(data['done']/data['total']*100, 10) + '%').show();
if (data['done'] == data['total']) {
details.addClass('vh');
cancel_btn.addClass('hide');
other_info.html("{% trans "Saving..." %}").removeClass('hide');
}
setTimeout(req_progress, 1000); setTimeout(req_progress, 1000);
} else { } else {
if (data['successful']) { if (data['successful']) {
bar.css('width', parseInt((i + 1)/op_objs.length*100, 10) + '%').show();
if (op=='mv') { if (op=='mv') {
op_obj.remove(); op_obj.remove();
updateCmt(); updateCmt();
} else {
$('.checkbox', op_obj).removeClass('checkbox-checked');
} }
feedback(msg, 'success'); endOrContinue();
} else { // failed or canceled } else { // failed or canceled
details.addClass('vh'); if (data['failed']) {
var other_msg = data['failed'] ? "{% trans "Failed." %}" : "{% trans "Canceled." %}"; var error_msg = op == 'mv' ? 'Failed to move %(name)s':'Failed to copy %(name)s';
other_info.html(other_msg).removeClass('hide'); cancel_btn.after('<p class="error">' + error_msg.replace('%(name)s', obj_name) + '</p>');
cancel_btn.addClass('hide'); end();
}
} }
endOrContinue();
} }
}, },
error: function(xhr, textStatus, errorThrown) { error: function(xhr, textStatus, errorThrown) {
@@ -707,17 +699,14 @@ $('#mv-dirents, #cp-dirents').click(function() {
} else { } else {
error = "{% trans "Failed. Please check the network." %}"; error = "{% trans "Failed. Please check the network." %}";
} }
details.addClass('vh') cancel_btn.after('<p class="error">' + error + '</p>');
other_info.html(error).removeClass('hide'); end();
cancel_btn.addClass('hide');
endOrContinue();
} }
}); });
}; // 'req_progress' ends }; // 'req_progress' ends
if (i == 0) { if (i == 0) {
$.modal.close(); $.modal.close();
$('#dirents-op').addClass('hide'); $('#dirents-op').addClass('hide');
$('th.select .checkbox').removeClass('checkbox-checked');
setTimeout(function () { setTimeout(function () {
$('#mv-progress-popup').modal({containerCss: { $('#mv-progress-popup').modal({containerCss: {
width: 300, width: 300,
@@ -746,6 +735,9 @@ $('#mv-dirents, #cp-dirents').click(function() {
mvcpDirent(++i); mvcpDirent(++i);
} }
}; };
var end = function () {
setTimeout(function () { $.modal.close(); }, 500);
};
mvcpDirent(); mvcpDirent();
cancel_btn.click(function() { cancel_btn.click(function() {
disable(cancel_btn); disable(cancel_btn);
@@ -754,10 +746,9 @@ $('#mv-dirents, #cp-dirents').click(function() {
url: '{% url "cancel_cp" %}?task_id=' + e(task_id), url: '{% url "cancel_cp" %}?task_id=' + e(task_id),
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
details.addClass('vh')
other_info.html("{% trans "Canceled." %}").removeClass('hide'); other_info.html("{% trans "Canceled." %}").removeClass('hide');
cancel_btn.addClass('hide'); cancel_btn.addClass('hide');
endOrContinue(); end();
}, },
error: function(xhr, textStatus, errorThrown) { error: function(xhr, textStatus, errorThrown) {
var error; var error;
@@ -1772,12 +1763,15 @@ $('#add-new-file-form, #add-new-dir-form, #rename-form, #mv-form').submit(functi
success: function(data) { success: function(data) {
var bar = $('.ui-progressbar-value', $('#mv-progress')); var bar = $('.ui-progressbar-value', $('#mv-progress'));
if (!data['failed'] && !data['canceled'] && !data['successful']) { if (!data['failed'] && !data['canceled'] && !data['successful']) {
bar.css('width', parseInt(data['done']/data['total']*100, 10) + '%').show();
if (data['done'] == data['total']) { if (data['done'] == data['total']) {
bar.css('width', '100%'); // 'done' and 'total' can be both 0
details.addClass('vh'); details.addClass('vh');
cancel_btn.addClass('hide'); cancel_btn.addClass('hide');
other_info.html("{% trans "Saving..." %}").removeClass('hide'); other_info.html("{% trans "Saving..." %}").removeClass('hide');
} else {
bar.css('width', parseInt(data['done']/data['total']*100, 10) + '%');
} }
bar.show();
setTimeout(req_progress, 1000); setTimeout(req_progress, 1000);
} else if (data['successful']) { } else if (data['successful']) {
$.modal.close(); $.modal.close();

View File

@@ -952,7 +952,7 @@ def cancel_cp(request):
result['success'] = True result['success'] = True
return HttpResponse(json.dumps(result), content_type=content_type) return HttpResponse(json.dumps(result), content_type=content_type)
else: else:
result['error'] = _('Failed') result['error'] = _('Cancel failed')
return HttpResponse(json.dumps(result), status=400, return HttpResponse(json.dumps(result), status=400,
content_type=content_type) content_type=content_type)