2013-07-23 18:56:52 +08:00
|
|
|
{% load i18n avatar_tags %}
|
2013-01-03 19:28:57 +08:00
|
|
|
{% load url from future %}
|
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
var share_list = [], contacts = [], contact_email;
|
2013-01-03 19:28:57 +08:00
|
|
|
{% for contact in contacts %}
|
2013-09-13 17:57:39 +08:00
|
|
|
contact_email = '{{ contact.contact_email }}';
|
|
|
|
share_list.push({value: contact_email, label: contact_email});
|
|
|
|
contacts.push({value:contact_email, avatar:'{% avatar contact.contact_email 16 %}'});
|
2013-01-03 19:28:57 +08:00
|
|
|
{% endfor %}
|
2013-07-23 18:56:52 +08:00
|
|
|
|
|
|
|
function showSharePopup(op, name, aj_url, type, cur_path) {
|
2013-08-12 15:28:55 +08:00
|
|
|
var path;
|
|
|
|
if (op.attr('id') == 'share-cur-dir') {
|
|
|
|
path = cur_path.substr(0, cur_path.length - 1); // rm the last '/' as seafile_api treats '/xx' and '/xx/' as different
|
|
|
|
} else {
|
|
|
|
path = cur_path + name;
|
|
|
|
}
|
2013-10-25 19:21:01 +08:00
|
|
|
$('#file-share').modal({appendTo: "#main",'focus':false, containerCss:{"padding":0}});
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
var hd = $('#file-share .hd');
|
|
|
|
hd.html(hd.html().replace('%(name)s', '<span class="op-target">' + trimFilename(name, 30) + '</span>'));
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
if (type == 'd') {
|
|
|
|
$('#private-share-tab, #private-share').remove();
|
|
|
|
} else {
|
|
|
|
$('#syncable-share-tab, #syncable-share').remove();
|
2013-07-23 18:56:52 +08:00
|
|
|
}
|
2013-09-13 17:57:39 +08:00
|
|
|
$("#file-share-tabs").tabs();
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
// share link
|
|
|
|
if (op.data('link')) {
|
2013-07-23 18:56:52 +08:00
|
|
|
$('#gen-link-btn').addClass('hide');
|
|
|
|
$('#share-link-body').removeClass('hide');
|
|
|
|
var link = op.data('link');
|
|
|
|
$('#shared-link-text, #link-send-form input[name="file_shared_link"]').val(link);
|
|
|
|
$('#main').append('<p id="linkwidth" class="hide">' + link + '</p>');
|
|
|
|
$('#shared-link-text').css({'width':$('#linkwidth').width() + 25});
|
|
|
|
$('#linkwidth').remove();
|
|
|
|
} else {
|
|
|
|
$('#gen-link-btn').removeClass('hide');
|
|
|
|
$('#share-link-body').addClass('hide');
|
|
|
|
}
|
|
|
|
$('#gen-link-btn').data('url', aj_url).data('obj', op);
|
2013-07-24 15:02:13 +08:00
|
|
|
$('#rm-shared-link').data('obj', op);
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
// 'private share' for file
|
|
|
|
if ($('#private-share').length == 1) {
|
|
|
|
$('#private-share-tab a').click(function() {
|
|
|
|
var form = $('#private-share-form');
|
|
|
|
$("input[name=s_type]", form).val(type);
|
|
|
|
$("input[name=path]", form).val(path);
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
var opts = '', email, avatar;
|
|
|
|
for (var i = 0, len = contacts.length; i < len; i++) {
|
|
|
|
email = contacts[i].value;
|
|
|
|
opts += '<option value="' + email + '" data-index="' + i + '">' + email + '</option>';
|
|
|
|
}
|
|
|
|
var format = function(item) {
|
|
|
|
return contacts[$(item.element).data('index')].avatar + '<span class="vam">' + item.text + '</span>';
|
|
|
|
}
|
|
|
|
$('[name="emails"]', form).html(opts).select2({
|
|
|
|
placeholder: "{% trans "Select contacts" %}",
|
|
|
|
formatResult: format,
|
|
|
|
formatSelection: format,
|
|
|
|
escapeMarkup: function(m) { return m; }
|
|
|
|
});
|
|
|
|
});
|
2013-08-12 15:28:55 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
// syncable share for dir
|
2013-08-12 15:28:55 +08:00
|
|
|
if ($('#syncable-share').length == 1) {
|
2013-09-13 11:25:22 +08:00
|
|
|
$('#syncable-share-tab a').click(function() {
|
2013-09-13 17:57:39 +08:00
|
|
|
var loading_tip = $('#syncable-share .loading-tip');
|
2013-09-13 11:25:22 +08:00
|
|
|
|
2013-09-13 17:57:39 +08:00
|
|
|
// check if a sub-lib exists, if not, create one
|
|
|
|
$.ajax({
|
2013-09-16 14:12:15 +08:00
|
|
|
url: '{% url 'sub_repo' repo.id %}?p=' + e(path) + '&name=' + e(name),
|
2013-09-13 17:57:39 +08:00
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
loading_tip.hide();
|
2013-09-13 11:25:22 +08:00
|
|
|
var form = $("#repo-share-form");
|
2013-10-25 19:21:01 +08:00
|
|
|
form.removeClass('hide').css({'width':'auto', 'padding-top':0});
|
|
|
|
$('[name="repo_id"]', form).val(data['sub_repo_id']);
|
2013-09-13 11:25:22 +08:00
|
|
|
$("h3", form).remove();
|
|
|
|
$('.checkbox-label', form).css({'margin-right':'3px'}); // make it not show on top of the scrollbar when hover
|
|
|
|
$("#repo-share-tabs").tabs();
|
2013-10-25 19:21:01 +08:00
|
|
|
$('#repo-share-tabs .ui-tabs-nav').removeClass('tab-popup-tabs-nav').addClass('tab-tabs-nav').css({'padding-left': '1.4em'});
|
2013-09-13 17:57:39 +08:00
|
|
|
$(window).resize(); // to reposition the popup, as this panel is 'taller'
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
loading_tip.hide();
|
|
|
|
var err;
|
|
|
|
if (xhr.responseText) {
|
|
|
|
err = jQuery.parseJSON(xhr.responseText).error;
|
|
|
|
} else {
|
|
|
|
err = "{% trans "Failed. Please check the network." %}";
|
|
|
|
}
|
|
|
|
$('#syncable-share').append('<p class="error">' + err + '</p>');
|
2013-08-12 15:28:55 +08:00
|
|
|
}
|
2013-09-13 17:57:39 +08:00
|
|
|
});
|
2013-08-12 15:28:55 +08:00
|
|
|
});
|
2013-07-23 18:56:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#simplemodal-container').css({'height':'auto', 'width':'auto'});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#send-link').click(function() {
|
2013-01-07 15:34:25 +08:00
|
|
|
$(this).addClass('hide');
|
2013-07-23 18:56:52 +08:00
|
|
|
$('#rm-shared-link').addClass('hide');
|
2013-01-07 15:34:25 +08:00
|
|
|
var input = $('#link-send-input');
|
2013-07-19 20:05:18 +08:00
|
|
|
input.css({'width': $('#link-share').width() - parseInt(input.css('padding-left')) - parseInt(input.css('padding-right')) - parseInt(input.css('border-left-width')) - parseInt(input.css('border-right-width'))});
|
2013-01-07 15:34:25 +08:00
|
|
|
$('#link-send-form').removeClass('hide');
|
|
|
|
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
|
|
|
});
|
2013-01-03 19:28:57 +08:00
|
|
|
|
2013-07-23 18:56:52 +08:00
|
|
|
$("#link-send-form .cancel").click(function() {
|
|
|
|
$('#link-send-form, #send-link, #rm-shared-link').toggleClass('hide');
|
|
|
|
});
|
|
|
|
|
2013-01-03 19:28:57 +08:00
|
|
|
$("#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,
|
|
|
|
beforeSend: prepareCSRFToken,
|
|
|
|
data: {file_shared_link: file_shared_link, email: email},
|
|
|
|
success: function(data) {
|
|
|
|
$.modal.close();
|
2013-01-07 15:34:25 +08:00
|
|
|
feedback(data['msg'], "success");
|
2013-01-03 19:28:57 +08:00
|
|
|
},
|
2013-01-07 15:34:25 +08:00
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
2013-01-03 19:28:57 +08:00
|
|
|
$('#sending').addClass('hide');
|
|
|
|
enable(submit_btn);
|
2013-01-07 15:34:25 +08:00
|
|
|
var err_str = '';
|
|
|
|
if (xhr.responseText) {
|
|
|
|
var err = jQuery.parseJSON(xhr.responseText);
|
|
|
|
if (err.error) {
|
|
|
|
err_str = err.error;
|
2013-01-03 19:28:57 +08:00
|
|
|
} else {
|
2013-01-07 15:34:25 +08:00
|
|
|
for (var i in err) {
|
|
|
|
err_str += err[i];
|
|
|
|
}
|
2013-01-03 19:28:57 +08:00
|
|
|
}
|
2013-01-07 15:34:25 +08:00
|
|
|
} else {
|
|
|
|
err_str = '{% trans "Failed. Please check the network." %}';
|
|
|
|
}
|
|
|
|
apply_form_error('link-send-form', err_str);
|
2013-01-03 19:28:57 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2013-07-23 18:56:52 +08:00
|
|
|
|
|
|
|
$('#shared-link-text').click(function() {
|
2013-01-03 19:28:57 +08:00
|
|
|
$(this).select();
|
|
|
|
});
|
2013-07-23 18:56:52 +08:00
|
|
|
|
2013-07-04 16:25:21 +08:00
|
|
|
$('#gen-link-btn').click(function() {
|
2013-07-23 18:56:52 +08:00
|
|
|
var gen_link_btn = $(this),
|
|
|
|
obj = gen_link_btn.data('obj');
|
2013-07-04 16:25:21 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2013-07-19 20:05:18 +08:00
|
|
|
url: gen_link_btn.data('url'),
|
2013-07-04 16:25:21 +08:00
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
success: function(data) {
|
|
|
|
var link = data['shared_link'];
|
|
|
|
// hide gen-link button, and show link
|
2013-07-19 20:05:18 +08:00
|
|
|
gen_link_btn.addClass('hide');
|
2013-07-04 16:25:21 +08:00
|
|
|
$('#shared-link-text, #link-send-form input[name="file_shared_link"]').val(link);
|
|
|
|
$('#main').append('<p id="linkwidth" class="hide">' + link + '</p>');
|
|
|
|
$('#shared-link-text').css({'width':$('#linkwidth').width() + 25});
|
2013-07-19 20:05:18 +08:00
|
|
|
$('#linkwidth').remove();
|
|
|
|
$('#share-link-body').removeClass('hide');
|
2013-07-24 15:02:13 +08:00
|
|
|
obj.data('link', link).data('token', data['token']);
|
2013-07-04 16:25:21 +08:00
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
if (xhr.responseText) {
|
|
|
|
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
|
|
|
|
} else {
|
|
|
|
feedback("{% trans "Failed. Please check the network." %}", 'error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2013-07-23 18:56:52 +08:00
|
|
|
|
|
|
|
$('#rm-shared-link').click(function() {
|
2013-07-24 15:02:13 +08:00
|
|
|
var obj = $(this).data('obj'),
|
|
|
|
token = obj.data('token');
|
2013-07-23 18:56:52 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2013-07-24 15:02:13 +08:00
|
|
|
url: '{% url 'remove_shared_link' %}?t=' + token,
|
2013-07-23 18:56:52 +08:00
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
success: function(data) {
|
|
|
|
$('#share-link-body').addClass('hide');
|
|
|
|
$('#gen-link-btn').removeClass('hide');
|
|
|
|
obj.data('link', '').data('token', '');
|
|
|
|
},
|
2013-07-24 15:02:13 +08:00
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
if (xhr.responseText) {
|
|
|
|
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
|
|
|
|
} else {
|
|
|
|
feedback("{% trans "Failed. Please check the network." %}", 'error');
|
|
|
|
}
|
2013-07-23 18:56:52 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|