mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 10:22:46 +00:00
fixed bug and improved code for file/subdir share in repo/file_view
This commit is contained in:
@@ -386,7 +386,7 @@ def get_shared_link(request):
|
|||||||
path = request.GET.get('p', '')
|
path = request.GET.get('p', '')
|
||||||
if not (repo_id and path):
|
if not (repo_id and path):
|
||||||
err = _('Invalid arguments')
|
err = _('Invalid arguments')
|
||||||
data = json.dumps([{'error': err}])
|
data = json.dumps({'error': err})
|
||||||
return HttpResponse(data, status=400, content_type=content_type)
|
return HttpResponse(data, status=400, content_type=content_type)
|
||||||
|
|
||||||
if share_type == 'f':
|
if share_type == 'f':
|
||||||
@@ -394,8 +394,8 @@ def get_shared_link(request):
|
|||||||
path = path[:-1]
|
path = path[:-1]
|
||||||
else:
|
else:
|
||||||
if path == '/': # can not share root dir
|
if path == '/': # can not share root dir
|
||||||
err = _('Can not share root dir.')
|
err = _('You cannot share the repo in this way.')
|
||||||
data = json.dumps([{'error': err}])
|
data = json.dumps({'error': err})
|
||||||
return HttpResponse(data, status=400, content_type=content_type)
|
return HttpResponse(data, status=400, content_type=content_type)
|
||||||
else:
|
else:
|
||||||
if path[-1] != '/': # append '/' at end of path
|
if path[-1] != '/': # append '/' at end of path
|
||||||
@@ -420,12 +420,12 @@ def get_shared_link(request):
|
|||||||
fs.save()
|
fs.save()
|
||||||
except IntegrityError, e:
|
except IntegrityError, e:
|
||||||
err = _('Failed to get the link, please retry later.')
|
err = _('Failed to get the link, please retry later.')
|
||||||
data = json.dumps([{'error': err}])
|
data = json.dumps({'error': err})
|
||||||
return HttpResponse(data, status=500, content_type=content_type)
|
return HttpResponse(data, status=500, content_type=content_type)
|
||||||
|
|
||||||
shared_link = gen_shared_link(request, token, fs.s_type)
|
shared_link = gen_shared_link(request, token, fs.s_type)
|
||||||
|
|
||||||
data = json.dumps([{'token': token, 'shared_link': shared_link}])
|
data = json.dumps({'token': token, 'shared_link': shared_link})
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
return HttpResponse(data, status=200, content_type=content_type)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -449,8 +449,8 @@ def remove_shared_link(request):
|
|||||||
|
|
||||||
FileShare.objects.filter(token=token).delete()
|
FileShare.objects.filter(token=token).delete()
|
||||||
|
|
||||||
msg = _('Removed successfully')
|
msg = _('Deleted successfully')
|
||||||
data = json.dumps([{'msg': msg}])
|
data = json.dumps({'msg': msg})
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
return HttpResponse(data, status=200, content_type=content_type)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -490,10 +490,10 @@ def send_shared_link(request):
|
|||||||
t.render(Context(c)), None, [to_email],
|
t.render(Context(c)), None, [to_email],
|
||||||
fail_silently=False)
|
fail_silently=False)
|
||||||
except:
|
except:
|
||||||
data = json.dumps({'error':_(u'Send failed.')})
|
data = json.dumps({'error':_(u'Internal server error. Send failed.')})
|
||||||
return HttpResponse(data, status=500, content_type=content_type)
|
return HttpResponse(data, status=500, content_type=content_type)
|
||||||
|
|
||||||
data = json.dumps("success")
|
data = json.dumps({"msg": _(u'Successfully sent.')})
|
||||||
return HttpResponse(data, status=200, content_type=content_type)
|
return HttpResponse(data, status=200, content_type=content_type)
|
||||||
else:
|
else:
|
||||||
return HttpResponseBadRequest(json.dumps(form.errors),
|
return HttpResponseBadRequest(json.dumps(form.errors),
|
||||||
|
@@ -661,11 +661,9 @@ $('.file-share').click(function() {
|
|||||||
if ($(this).data('link')) {
|
if ($(this).data('link')) {
|
||||||
showPopup($(this).data('link'));
|
showPopup($(this).data('link'));
|
||||||
} else {
|
} else {
|
||||||
var aj_url = '';
|
var aj_url = '{% url 'get_shared_link' %}?repo_id={{ repo.id }}&p={{ path|urlencode }}' + e(filename);
|
||||||
if ($(this).data('type') == 'd') {
|
if ($(this).data('type') == 'd') {
|
||||||
aj_url = '{% url 'get_shared_link' %}?repo_id={{ repo.id }}&p={{ path|urlencode }}' + e(filename) + '&type=d';
|
aj_url += '&type=d';
|
||||||
} else {
|
|
||||||
aj_url = '{% url 'get_shared_link' %}?repo_id={{ repo.id }}&p={{ path|urlencode }}' + e(filename);
|
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: aj_url,
|
url: aj_url,
|
||||||
@@ -673,13 +671,14 @@ $('.file-share').click(function() {
|
|||||||
cache: false,
|
cache: false,
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data.length > 0) {
|
showPopup(data['shared_link']);
|
||||||
showPopup(data[0]['shared_link']);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error: function(xhr, ajaxOptions, thrownError) {
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
if (xhr.responseText) {
|
||||||
feedback(jsonVal[0]['error'], 'error');
|
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
|
||||||
|
} else {
|
||||||
|
feedback('{% trans "Failed. Please check the network." %}', 'error');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -952,69 +951,10 @@ $('#rename-form').submit(function() {
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// file share form
|
|
||||||
var share_list = [];
|
|
||||||
{% for contact in contacts %}
|
|
||||||
share_list.push({value:'{{ contact.contact_email }}', label:'{{ contact.contact_email }}'});
|
|
||||||
{% endfor %}
|
|
||||||
$('#send-link').click(function() {
|
|
||||||
$(this).addClass('hide');
|
|
||||||
var input = $('#link-send-input');
|
|
||||||
input.css({'min-width':input.css('width'), 'width': $('#file-share').width() - parseInt(input.css('padding-left')) - parseInt(input.css('padding-right')) - parseInt(input.css('border-left-width')) - parseInt(input.css('border-right-width'))});
|
|
||||||
$('#link-send-form').removeClass('hide');
|
|
||||||
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
|
||||||
});
|
|
||||||
$("#link-send-form").submit(function() {
|
|
||||||
var form = $(this),
|
|
||||||
file_shared_link = form.children('input[name="file_shared_link"]').val(),
|
|
||||||
email = $.trim(form.children('textarea[name="email"]').val()),
|
|
||||||
submit_btn = form.children('input[type="submit"]'),
|
|
||||||
err = form.children('.error');
|
|
||||||
|
|
||||||
if (!email) {
|
|
||||||
err.html('{% trans "Please input at least an email." %}').removeClass('hide');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
disable(submit_btn);
|
|
||||||
err.addClass('hide');
|
|
||||||
$('#sending').removeClass('hide');
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "{% url 'send_shared_link' %}",
|
|
||||||
dataType: 'json',
|
|
||||||
cache: false,
|
|
||||||
contentType: 'application/json; charset=utf-8',
|
|
||||||
beforeSend: prepareCSRFToken,
|
|
||||||
data: {file_shared_link: file_shared_link, email: email},
|
|
||||||
success: function(data) {
|
|
||||||
$.modal.close();
|
|
||||||
feedback('{% trans "Successfully shared." %}', "success");
|
|
||||||
},
|
|
||||||
error: function(data, textStatus, jqXHR) {
|
|
||||||
$('#sending').addClass('hide');
|
|
||||||
enable(submit_btn);
|
|
||||||
var errors = $.parseJSON(data.responseText);
|
|
||||||
$.each(errors, function(index, value) {
|
|
||||||
if (index == 'error') {
|
|
||||||
err.html(value);
|
|
||||||
} else {
|
|
||||||
err.html(value[0]);
|
|
||||||
}
|
|
||||||
err.removeClass('hide');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
$('#shared-link-text').click(function() { $(this).select(); });
|
|
||||||
{% if path == '/' %}
|
{% if path == '/' %}
|
||||||
{% include "snippets/list_commit_detail.html" %}
|
{% include "snippets/list_commit_detail.html" %}
|
||||||
{% else %}
|
|
||||||
{% include "snippets/shared_link_js.html" %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% include "snippets/shared_link_js.html" %}
|
||||||
{% include "snippets/bottom_bar.html" %}
|
{% include "snippets/bottom_bar.html" %}
|
||||||
</script>
|
</script>
|
||||||
{% include 'snippets/file_upload_progress_js.html' %}
|
{% include 'snippets/file_upload_progress_js.html' %}
|
||||||
|
@@ -31,17 +31,17 @@ $('#get-shared-link').click(function() {
|
|||||||
cache: false,
|
cache: false,
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data.length > 0) {
|
$('#rm-shared-link').attr('data', '{% url 'remove_shared_link' %}?t=' + data['token']);
|
||||||
var t = data[0]['token'];
|
$('#shared-link, input[name="file_shared_link"]').val(data['shared_link']);
|
||||||
$('#rm-shared-link').attr('data', '{% url 'remove_shared_link' %}?t=' + t);
|
|
||||||
$('#shared-link, input[name="file_shared_link"]').val(data[0]['shared_link']);
|
|
||||||
setLinkWidth();
|
setLinkWidth();
|
||||||
showLink();
|
showLink();
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error: function(xhr, ajaxOptions, thrownError) {
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
if (xhr.responseText) {
|
||||||
feedback(jsonVal[0]['error'], 'error');
|
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
|
||||||
|
} else {
|
||||||
|
feedback('{% trans "Failed. Please check the network." %}', 'error');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -55,7 +55,11 @@ $('#rm-shared-link').click(function() {
|
|||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
hideLink();
|
hideLink();
|
||||||
|
feedback(data['msg'], 'success');
|
||||||
$('#shared-link').val('');
|
$('#shared-link').val('');
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
feedback('{% trans "Failed. Please check the network." %}', 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -64,11 +68,18 @@ var share_list = [];
|
|||||||
{% for contact in contacts %}
|
{% for contact in contacts %}
|
||||||
share_list.push({value:'{{ contact.contact_email }}', label:'{{ contact.contact_email }}'});
|
share_list.push({value:'{{ contact.contact_email }}', label:'{{ contact.contact_email }}'});
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
$('#send-shared-link').click(function() {
|
$('#send-shared-link').click(function() { // for file_view.html and subdir page
|
||||||
$("#link-send-form").modal({appendTo: "#main", focus: false});
|
$("#link-send-form").modal({appendTo: "#main", focus: false});
|
||||||
$('#simplemodal-container').css('height', 'auto');
|
$('#simplemodal-container').css('height', 'auto');
|
||||||
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
||||||
});
|
});
|
||||||
|
$('#send-link').click(function() { // for 'file-share' in repo.html
|
||||||
|
$(this).addClass('hide');
|
||||||
|
var input = $('#link-send-input');
|
||||||
|
input.css({'min-width':input.css('width'), 'width': $('#file-share').width() - parseInt(input.css('padding-left')) - parseInt(input.css('padding-right')) - parseInt(input.css('border-left-width')) - parseInt(input.css('border-right-width'))});
|
||||||
|
$('#link-send-form').removeClass('hide');
|
||||||
|
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
||||||
|
});
|
||||||
|
|
||||||
$("#link-send-form").submit(function(event) {
|
$("#link-send-form").submit(function(event) {
|
||||||
var form = $(this),
|
var form = $(this),
|
||||||
@@ -95,23 +106,29 @@ $("#link-send-form").submit(function(event) {
|
|||||||
data: {file_shared_link: file_shared_link, email: email},
|
data: {file_shared_link: file_shared_link, email: email},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.modal.close();
|
$.modal.close();
|
||||||
feedback('{% trans "Successfully sent." %}', "success");
|
feedback(data['msg'], "success");
|
||||||
},
|
},
|
||||||
error: function(data, textStatus, jqXHR) {
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
$('#sending').addClass('hide');
|
$('#sending').addClass('hide');
|
||||||
enable(submit_btn);
|
enable(submit_btn);
|
||||||
var errors = $.parseJSON(data.responseText);
|
var err_str = '';
|
||||||
$.each(errors, function(index, value) {
|
if (xhr.responseText) {
|
||||||
if (index == 'error') {
|
var err = jQuery.parseJSON(xhr.responseText);
|
||||||
apply_form_error('link-send-form', value);
|
if (err.error) {
|
||||||
|
err_str = err.error;
|
||||||
} else {
|
} else {
|
||||||
apply_form_error('link-send-form', value[0]);
|
for (var i in err) {
|
||||||
|
err_str += err[i];
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
} else {
|
||||||
|
err_str = '{% trans "Failed. Please check the network." %}';
|
||||||
|
}
|
||||||
|
apply_form_error('link-send-form', err_str);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#shared-link').click(function() {
|
$('#shared-link, #shared-link-text').click(function() {
|
||||||
$(this).select();
|
$(this).select();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user