1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 06:33:48 +00:00

[repo] fixed small bugs, improved rename/delete url

This commit is contained in:
llj
2013-07-31 17:00:03 +08:00
parent 8d5e0f66dc
commit 867d174ace
2 changed files with 26 additions and 17 deletions

View File

@@ -526,10 +526,16 @@ $('.hidden-op li').hover(
); );
$('.dir-del, .file-del').click(function() { $('.dir-del, .file-del').click(function() {
var dirent = $(this).parents('tr'), var dirent = $(this).parents('tr'),
dirent_name = dirent.data('name'); dirent_name = dirent.data('name'),
url_main;
if ($(this).hasClass('dir-del')) {
url_main = '{% url 'delete_dir' repo.id %}';
} else {
url_main = '{% url 'delete_file' repo.id %}';
}
$.ajax({ $.ajax({
url: '{% url 'repo_delete_dirent' repo.id %}?parent_dir=' + e(cur_path) + '&name=' + e(dirent_name), url: url_main + '?parent_dir=' + e(cur_path) + '&name=' + e(dirent_name),
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
if (data['success']) { if (data['success']) {
@@ -562,9 +568,9 @@ $('.file-rename, .dir-rename').click(function () {
op_detail.html(op_detail.html().replace('%(name)s', '<span class="op-target">' + orig_name + '</span>')); op_detail.html(op_detail.html().replace('%(name)s', '<span class="op-target">' + orig_name + '</span>'));
$('input[name*="name"]', form).val(orig_name); $('input[name*="name"]', form).val(orig_name);
if (op.hasClass('file-rename')) { if (op.hasClass('file-rename')) {
form.prepend("<h3>{% trans "Rename File" %}</h3>"); form.prepend("<h3>{% trans "Rename File" %}</h3>").data('obj_type', 'file');
} else { } else {
form.prepend("<h3>{% trans "Rename Directory" %}</h3>"); form.prepend("<h3>{% trans "Rename Directory" %}</h3>").data('obj_type', 'dir');
} }
$('#simplemodal-container').css({'width':'auto', 'height':'auto'}); $('#simplemodal-container').css({'width':'auto', 'height':'auto'});
@@ -630,19 +636,18 @@ $('.update-file').click(function() {
$('.file-star').click(function() { $('.file-star').click(function() {
var op = $(this), var op = $(this),
status = op.data('status'), status = op.data('status'),
file_name = op.parents('.file-item').data('name'); file_name = op.parents('.file-item').data('name'),
post_url;
if (status == 'unstarred') { if (status == 'unstarred') {
var post_url = '{% url 'repo_star_file' repo.id %}?file=' + e(cur_path + file_name) post_url = '{% url 'repo_star_file' repo.id %}?file=' + e(cur_path + file_name);
} else { } else {
var post_url = '{% url 'repo_unstar_file' repo.id %}?file=' + e(cur_path + file_name) post_url = '{% url 'repo_unstar_file' repo.id %}?file=' + e(cur_path + file_name);
} }
$.ajax({ $.ajax({
url: post_url, url: post_url,
type: 'POST',
cache: false, cache: false,
beforeSend: prepareCSRFToken,
dataType: 'json', dataType: 'json',
success:function(data) { success:function(data) {
if (data['success']) { if (data['success']) {
@@ -735,7 +740,7 @@ $('#add-new-file-form, #add-new-dir-form, #rename-form, #mv-form').submit(functi
dirent_type; dirent_type;
if (!dirent_name) { if (!dirent_name) {
apply_form_error(form_id, "{% trans "Its required." %}"); apply_form_error(form_id, "{% trans "It is required." %}");
return false; return false;
} }
if (form_id == 'add-new-file-form') { if (form_id == 'add-new-file-form') {
@@ -767,14 +772,18 @@ $('#add-new-file-form, #add-new-dir-form, #rename-form, #mv-form').submit(functi
new_name = $.trim(form.find('input[name="newname"]').val()), new_name = $.trim(form.find('input[name="newname"]').val()),
op_obj = form.data('op_obj'); op_obj = form.data('op_obj');
if (!new_name) { if (!new_name) {
apply_form_error(form_id, "{% trans "It cannot be blank." %}"); apply_form_error(form_id, "{% trans "It is required." %}");
return false; return false;
} }
if (new_name == old_name) { if (new_name == old_name) {
apply_form_error(form_id, "{% trans "You have not renamed it." %}"); apply_form_error(form_id, "{% trans "You have not renamed it." %}");
return false; return false;
} }
post_url = '{% url 'repo_rename_dirent' repo.id %}?parent_dir=' + e(path); if (form.data('obj_type') == 'dir') {
post_url = '{% url 'rename_dir' repo.id %}?parent_dir=' + e(path);
} else {
post_url = '{% url 'rename_file' repo.id %}?parent_dir=' + e(path);
}
post_data['oldname'] = old_name; post_data['oldname'] = old_name;
post_data['newname'] = new_name; post_data['newname'] = new_name;
after_op_success = function(data) { after_op_success = function(data) {
@@ -830,7 +839,7 @@ $('#add-new-file-form, #add-new-dir-form, #rename-form, #mv-form').submit(functi
} }
post_data = { post_data = {
'dst_repo': dst_repo, 'dst_repo': dst_repo,
'dst_path': dst_path, 'dst_path': dst_path
}; };
after_op_success = function(data) { after_op_success = function(data) {
$.modal.close(); $.modal.close();

View File

@@ -110,13 +110,13 @@ urlpatterns = patterns('',
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/$', list_dir, name='repo_dir_data'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/$', list_dir, name='repo_dir_data'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/new/$', new_dir, name='new_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/new/$', new_dir, name='new_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/rename/$', rename_dirent, name='repo_rename_dirent'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/rename/$', rename_dirent, name='rename_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/delete/$', delete_dirent, name='repo_delete_dirent'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/delete/$', delete_dirent, name='delete_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/mv/$', mv_dir, name='mv_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/mv/$', mv_dir, name='mv_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/cp/$', cp_dir, name='cp_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/cp/$', cp_dir, name='cp_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/new/$', new_file, name='new_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/new/$', new_file, name='new_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/rename/$', rename_dirent, name='repo_rename_dirent'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/rename/$', rename_dirent, name='rename_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/delete/$', delete_dirent, name='repo_delete_dirent'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/delete/$', delete_dirent, name='delete_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/mv/$', mv_file, name='mv_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/mv/$', mv_file, name='mv_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/cp/$', cp_file, name='cp_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/cp/$', cp_file, name='cp_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/star_file/$', repo_star_file, name='repo_star_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/star_file/$', repo_star_file, name='repo_star_file'),