1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 00:20:07 +00:00

[share.js] show error msg

This commit is contained in:
llj
2016-11-17 11:53:43 +08:00
parent e25b28e8f6
commit 2d26c57a66
2 changed files with 151 additions and 79 deletions

View File

@@ -500,13 +500,14 @@
<p class="sending-tip hide">{% trans "Sending..."%}</p>
</form>
</div>
<p class="error hide"></p>
</div>
<% } %>
<% if (is_dir) { %>
<% if (user_perm == 'rw' && !repo_encrypted && can_generate_upload_link) { %>
<div id="dir-upload-link-share" class="tabs-panel hide">
<p class="tip">{% trans "You can share the generated link to others and then they can upload files to this directory via the link." %}</p>
<p class="tip hide">{% trans "You can share the generated link to others and then they can upload files to this directory via the link." %}</p>
<form id="generate-upload-link-form" action="" class="hide">
<label class="checkbox-label">
<input type="checkbox" name="use_passwd" class="vam" />
@@ -540,6 +541,7 @@
<p class="sending-tip hide">{% trans "Sending..."%}</p>
</form>
</div>
<p class="error hide"></p>
</div>
<% } %>
@@ -549,7 +551,7 @@
<% } else { %>
<div id="dir-user-share" class="tabs-panel">
<% } %>
<table>
<table class="hide">
<thead>
<tr>
<th width="55%">{% trans "User" %}</th>
@@ -576,7 +578,7 @@
</div>
<div id="dir-group-share" class="tabs-panel hide">
<table>
<table class="hide">
<thead>
<tr>
<th width="55%">{% trans "Group" %}</th>

View File

@@ -106,11 +106,19 @@ define([
},
downloadLinkPanelInit: function() {
var $panel = $('#download-link-share');
var $loadingTip = this.$('.loading-tip');
var _this = this;
var after_op_success = function(data) { // data is [] or [{...}]
_this.$('.loading-tip').hide();
// check if downloadLink exists
$.ajax({
url: Common.getUrl({name: 'share_admin_share_links'}),
data: {
'repo_id': this.repo_id,
'path': this.dirent_path
},
cache: false,
dataType: 'json',
success: function(data) { // data is [] or [{...}]
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
@@ -126,15 +134,23 @@ define([
} else {
_this.$('#generate-download-link-form').removeClass('hide');
}
};
// check if downloadLink exists
Common.ajaxGet({
'get_url': Common.getUrl({name: 'share_admin_share_links'}),
'data': {
'repo_id': this.repo_id,
'path': this.dirent_path
},
'after_op_success': after_op_success
error: function(xhr, textStatus, errorThrown) {
var err_msg;
if (xhr.responseText) {
if (xhr.status == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = xhr.responseJSON.error_msg ? xhr.responseJSON.error_msg : gettext('Error');
}
} else {
err_msg = gettext('Please check the network.');
}
$('.error', $panel).html(err_msg).show();
},
complete: function() {
$loadingTip.hide();
}
});
},
@@ -395,8 +411,19 @@ define([
},
uploadLinkPanelInit: function() {
var $panel = $('#dir-upload-link-share');
var $loadingTip = this.$('.loading-tip').show();
var _this = this;
var after_op_success = function(data) { // data is [] or [{...}]
// check if upload link exists
$.ajax({
url: Common.getUrl({name: 'share_admin_upload_links'}),
data: {
'repo_id': this.repo_id,
'path': this.dirent_path
},
cache: false,
dataType: 'json',
success: function(data) { // data is [] or [{...}]
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
@@ -407,15 +434,24 @@ define([
} else {
_this.$('#generate-upload-link-form').removeClass('hide');
}
};
// check if upload link exists
Common.ajaxGet({
'get_url': Common.getUrl({name: 'share_admin_upload_links'}),
'data': {
'repo_id': this.repo_id,
'path': this.dirent_path
$('.tip', $panel).show();
},
'after_op_success': after_op_success
error: function(xhr, textStatus, errorThrown) {
var err_msg;
if (xhr.responseText) {
if (xhr.status == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = xhr.responseJSON.error_msg ? xhr.responseJSON.error_msg : gettext('Error');
}
} else {
err_msg = gettext('Please check the network.');
}
$('.error', $panel).html(err_msg).show();
},
complete: function() {
$loadingTip.hide();
}
});
},
@@ -477,26 +513,25 @@ define([
},
dirUserSharePanelInit: function() {
var form = this.$('#dir-user-share');
$('[name="emails"]', form).select2($.extend({
//width: '292px' // the container will copy class 'w100' from the original element to get width
},Common.contactInputOptionsForSelect2()));
// show existing items
var $loadingTip = this.$('.loading-tip').show();
var $panel = this.$('#dir-user-share');
var $table = $('table', $panel);
var $add_item = $('#add-dir-user-share-item');
var repo_id = this.repo_id,
path = this.dirent_path;
Common.ajaxGet({
'get_url': Common.getUrl({
$.ajax({
url: Common.getUrl({
name: 'dir_shared_items',
repo_id: repo_id
}),
'data': {
data: {
'p': path,
'share_type': 'user'
},
'after_op_success': function (data) {
cache: false,
dataType: 'json',
success: function(data) {
$(data).each(function(index, item) {
var new_item = new FolderShareItemView({
'repo_id': repo_id,
@@ -510,40 +545,50 @@ define([
});
$add_item.after(new_item.el);
});
$('[name="emails"]', $add_item).select2($.extend({
//width: '292px' // the container will copy class 'w100' from the original element to get width
},Common.contactInputOptionsForSelect2()));
$table.removeClass('hide');
},
error: function(xhr, textStatus, errorThrown) {
var err_msg;
if (xhr.responseText) {
if (xhr.status == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = xhr.responseJSON.error_msg ? xhr.responseJSON.error_msg : gettext('Error');
}
} else {
err_msg = gettext('Please check the network.');
}
$('.error', $panel).html(err_msg).show();
},
complete: function() {
$loadingTip.hide();
}
});
form.removeClass('hide');
this.$('.loading-tip').hide();
},
dirGroupSharePanelInit: function() {
var form = this.$('#dir-group-share');
var groups = app.pageOptions.groups || [];
var g_opts = '';
for (var i = 0, len = groups.length; i < len; i++) {
g_opts += '<option value="' + groups[i].id + '" data-index="' + i + '">' + groups[i].name + '</option>';
}
$('[name="groups"]', form).html(g_opts).select2({
placeholder: gettext("Select groups"),
escapeMarkup: function(m) { return m; }
});
// show existing items
var $loadingTip = this.$('.loading-tip').show();
var $panel = this.$('#dir-group-share');
var $table = $('table', $panel);
var $add_item = $('#add-dir-group-share-item');
var repo_id = this.repo_id,
path = this.dirent_path;
Common.ajaxGet({
'get_url': Common.getUrl({
$.ajax({
url: Common.getUrl({
name: 'dir_shared_items',
repo_id: repo_id
}),
'data': {
data: {
'p': path,
'share_type': 'group'
},
'after_op_success': function (data) {
cache: false,
dataType: 'json',
success: function(data) {
$(data).each(function(index, item) {
var new_item = new FolderShareItemView({
'repo_id': repo_id,
@@ -557,11 +602,36 @@ define([
});
$add_item.after(new_item.el);
});
var groups = app.pageOptions.groups || [];
var g_opts = '';
for (var i = 0, len = groups.length; i < len; i++) {
g_opts += '<option value="' + groups[i].id + '" data-index="' + i + '">' + groups[i].name + '</option>';
}
$('[name="groups"]', $add_item).html(g_opts).select2({
placeholder: gettext("Select groups"),
escapeMarkup: function(m) { return m; }
});
form.removeClass('hide');
this.$('.loading-tip').hide();
$table.removeClass('hide');
},
error: function(xhr, textStatus, errorThrown) {
var err_msg;
if (xhr.responseText) {
if (xhr.status == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = xhr.responseJSON.error_msg ? xhr.responseJSON.error_msg : gettext('Error');
}
} else {
err_msg = gettext('Please check the network.');
}
$('.error', $panel).html(err_msg).show();
},
complete: function() {
$loadingTip.hide();
}
});
},
dirUserShare: function () {