mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-18 15:08:22 +00:00
133 lines
4.5 KiB
HTML
133 lines
4.5 KiB
HTML
{% load i18n %}
|
|
{% load url from future %}
|
|
function showLink() {
|
|
$('#get-shared-link').addClass('hide');
|
|
$('#shared-link, #send-shared-link, #rm-shared-link').removeClass('hide');
|
|
}
|
|
function hideLink() {
|
|
$('#shared-link, #send-shared-link, #rm-shared-link').addClass('hide');
|
|
$('#get-shared-link').removeClass('hide');
|
|
}
|
|
function setLinkWidth() {
|
|
var link = $('#shared-link');
|
|
$('#main').append('<p id="linkcp" class="hide">' + link.val() + '</p>');
|
|
link.css('width', $('#linkcp').width() + 2);
|
|
$('#linkcp').remove();
|
|
}
|
|
{% if fileshare.token %}
|
|
setLinkWidth();
|
|
showLink();
|
|
{% else %}
|
|
hideLink();
|
|
{% endif %}
|
|
|
|
$('#get-shared-link').click(function() {
|
|
var url = $(this).attr('data');
|
|
$.ajax({
|
|
url: url,
|
|
dataType: 'json',
|
|
cache: false,
|
|
contentType: 'application/json; charset=utf-8',
|
|
success: function(data) {
|
|
$('#rm-shared-link').attr('data', '{% url 'remove_shared_link' %}?t=' + data['token']);
|
|
$('#shared-link, input[name="file_shared_link"]').val(data['shared_link']);
|
|
setLinkWidth();
|
|
showLink();
|
|
},
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
if (xhr.responseText) {
|
|
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
|
|
} else {
|
|
feedback('{% trans "Failed. Please check the network." %}', 'error');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#rm-shared-link').click(function() {
|
|
var url = $(this).attr('data');
|
|
$.ajax({
|
|
url: url,
|
|
dataType: 'json',
|
|
cache: false,
|
|
contentType: 'application/json; charset=utf-8',
|
|
success: function(data) {
|
|
hideLink();
|
|
feedback(data['msg'], 'success');
|
|
$('#shared-link').val('');
|
|
},
|
|
error: function() {
|
|
feedback('{% trans "Failed. Please check the network." %}', 'error');
|
|
}
|
|
});
|
|
});
|
|
|
|
var share_list = [];
|
|
{% for contact in contacts %}
|
|
share_list.push({value:'{{ contact.contact_email }}', label:'{{ contact.contact_email }}'});
|
|
{% endfor %}
|
|
$('#send-shared-link').click(function() { // for file_view.html and subdir page
|
|
$("#link-send-form").modal({appendTo: "#main", focus: false});
|
|
$('#simplemodal-container').css('height', 'auto');
|
|
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({'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) {
|
|
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"]');
|
|
|
|
if (!email) {
|
|
apply_form_error('link-send-form', '{% trans "Please input at least an email." %}');
|
|
return false;
|
|
}
|
|
|
|
disable(submit_btn);
|
|
$('#link-send-form .error').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(data['msg'], "success");
|
|
},
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
$('#sending').addClass('hide');
|
|
enable(submit_btn);
|
|
var err_str = '';
|
|
if (xhr.responseText) {
|
|
var err = jQuery.parseJSON(xhr.responseText);
|
|
if (err.error) {
|
|
err_str = err.error;
|
|
} else {
|
|
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;
|
|
});
|
|
$('#shared-link, #shared-link-text').click(function() {
|
|
$(this).select();
|
|
});
|