1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 07:55:36 +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> <p class="sending-tip hide">{% trans "Sending..."%}</p>
</form> </form>
</div> </div>
<p class="error hide"></p>
</div> </div>
<% } %> <% } %>
<% if (is_dir) { %> <% if (is_dir) { %>
<% if (user_perm == 'rw' && !repo_encrypted && can_generate_upload_link) { %> <% if (user_perm == 'rw' && !repo_encrypted && can_generate_upload_link) { %>
<div id="dir-upload-link-share" class="tabs-panel hide"> <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"> <form id="generate-upload-link-form" action="" class="hide">
<label class="checkbox-label"> <label class="checkbox-label">
<input type="checkbox" name="use_passwd" class="vam" /> <input type="checkbox" name="use_passwd" class="vam" />
@@ -540,6 +541,7 @@
<p class="sending-tip hide">{% trans "Sending..."%}</p> <p class="sending-tip hide">{% trans "Sending..."%}</p>
</form> </form>
</div> </div>
<p class="error hide"></p>
</div> </div>
<% } %> <% } %>
@@ -549,7 +551,7 @@
<% } else { %> <% } else { %>
<div id="dir-user-share" class="tabs-panel"> <div id="dir-user-share" class="tabs-panel">
<% } %> <% } %>
<table> <table class="hide">
<thead> <thead>
<tr> <tr>
<th width="55%">{% trans "User" %}</th> <th width="55%">{% trans "User" %}</th>
@@ -576,7 +578,7 @@
</div> </div>
<div id="dir-group-share" class="tabs-panel hide"> <div id="dir-group-share" class="tabs-panel hide">
<table> <table class="hide">
<thead> <thead>
<tr> <tr>
<th width="55%">{% trans "Group" %}</th> <th width="55%">{% trans "Group" %}</th>

View File

@@ -106,35 +106,51 @@ define([
}, },
downloadLinkPanelInit: function() { downloadLinkPanelInit: function() {
var $panel = $('#download-link-share');
var $loadingTip = this.$('.loading-tip');
var _this = this; var _this = this;
var after_op_success = function(data) { // data is [] or [{...}]
_this.$('.loading-tip').hide();
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
_this.download_link = link; // for 'link send'
_this.download_link_token = link_data.token; // for 'link delete'
_this.$('#download-link').html(link);
_this.$('#direct-dl-link').html(link + '?raw=1');
if (link_data.is_expired) {
_this.$('#send-download-link').addClass('hide');
_this.$('#download-link, #direct-dl-link').append(' <span class="error">(' + gettext('Expired') + ')</span>');
}
_this.$('#download-link-operations').removeClass('hide');
} else {
_this.$('#generate-download-link-form').removeClass('hide');
}
};
// check if downloadLink exists // check if downloadLink exists
Common.ajaxGet({ $.ajax({
'get_url': Common.getUrl({name: 'share_admin_share_links'}), url: Common.getUrl({name: 'share_admin_share_links'}),
'data': { data: {
'repo_id': this.repo_id, 'repo_id': this.repo_id,
'path': this.dirent_path 'path': this.dirent_path
}, },
'after_op_success': after_op_success cache: false,
dataType: 'json',
success: function(data) { // data is [] or [{...}]
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
_this.download_link = link; // for 'link send'
_this.download_link_token = link_data.token; // for 'link delete'
_this.$('#download-link').html(link);
_this.$('#direct-dl-link').html(link + '?raw=1');
if (link_data.is_expired) {
_this.$('#send-download-link').addClass('hide');
_this.$('#download-link, #direct-dl-link').append(' <span class="error">(' + gettext('Expired') + ')</span>');
}
_this.$('#download-link-operations').removeClass('hide');
} else {
_this.$('#generate-download-link-form').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();
}
}); });
}, },
@@ -395,27 +411,47 @@ define([
}, },
uploadLinkPanelInit: function() { uploadLinkPanelInit: function() {
var $panel = $('#dir-upload-link-share');
var $loadingTip = this.$('.loading-tip').show();
var _this = this; var _this = this;
var after_op_success = function(data) { // data is [] or [{...}]
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
_this.upload_link_token = link_data.token;
_this.upload_link = link;
_this.$('#upload-link').html(link);
_this.$('#upload-link-operations').removeClass('hide');
} else {
_this.$('#generate-upload-link-form').removeClass('hide');
}
};
// check if upload link exists // check if upload link exists
Common.ajaxGet({ $.ajax({
'get_url': Common.getUrl({name: 'share_admin_upload_links'}), url: Common.getUrl({name: 'share_admin_upload_links'}),
'data': { data: {
'repo_id': this.repo_id, 'repo_id': this.repo_id,
'path': this.dirent_path 'path': this.dirent_path
}, },
'after_op_success': after_op_success cache: false,
dataType: 'json',
success: function(data) { // data is [] or [{...}]
if (data.length == 1) {
var link_data = data[0],
link = link_data.link;
_this.upload_link_token = link_data.token;
_this.upload_link = link;
_this.$('#upload-link').html(link);
_this.$('#upload-link-operations').removeClass('hide');
} else {
_this.$('#generate-upload-link-form').removeClass('hide');
}
$('.tip', $panel).show();
},
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() { dirUserSharePanelInit: function() {
var form = this.$('#dir-user-share'); var $loadingTip = this.$('.loading-tip').show();
var $panel = this.$('#dir-user-share');
$('[name="emails"]', form).select2($.extend({ var $table = $('table', $panel);
//width: '292px' // the container will copy class 'w100' from the original element to get width
},Common.contactInputOptionsForSelect2()));
// show existing items
var $add_item = $('#add-dir-user-share-item'); var $add_item = $('#add-dir-user-share-item');
var repo_id = this.repo_id, var repo_id = this.repo_id,
path = this.dirent_path; path = this.dirent_path;
Common.ajaxGet({
'get_url': Common.getUrl({ $.ajax({
url: Common.getUrl({
name: 'dir_shared_items', name: 'dir_shared_items',
repo_id: repo_id repo_id: repo_id
}), }),
'data': { data: {
'p': path, 'p': path,
'share_type': 'user' 'share_type': 'user'
}, },
'after_op_success': function (data) { cache: false,
dataType: 'json',
success: function(data) {
$(data).each(function(index, item) { $(data).each(function(index, item) {
var new_item = new FolderShareItemView({ var new_item = new FolderShareItemView({
'repo_id': repo_id, 'repo_id': repo_id,
@@ -510,40 +545,50 @@ define([
}); });
$add_item.after(new_item.el); $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() { dirGroupSharePanelInit: function() {
var form = this.$('#dir-group-share'); var $loadingTip = this.$('.loading-tip').show();
var $panel = this.$('#dir-group-share');
var groups = app.pageOptions.groups || []; var $table = $('table', $panel);
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 $add_item = $('#add-dir-group-share-item'); var $add_item = $('#add-dir-group-share-item');
var repo_id = this.repo_id, var repo_id = this.repo_id,
path = this.dirent_path; path = this.dirent_path;
Common.ajaxGet({
'get_url': Common.getUrl({ $.ajax({
url: Common.getUrl({
name: 'dir_shared_items', name: 'dir_shared_items',
repo_id: repo_id repo_id: repo_id
}), }),
'data': { data: {
'p': path, 'p': path,
'share_type': 'group' 'share_type': 'group'
}, },
'after_op_success': function (data) { cache: false,
dataType: 'json',
success: function(data) {
$(data).each(function(index, item) { $(data).each(function(index, item) {
var new_item = new FolderShareItemView({ var new_item = new FolderShareItemView({
'repo_id': repo_id, 'repo_id': repo_id,
@@ -557,11 +602,36 @@ define([
}); });
$add_item.after(new_item.el); $add_item.after(new_item.el);
}); });
}
});
form.removeClass('hide'); var groups = app.pageOptions.groups || [];
this.$('.loading-tip').hide(); 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; }
});
$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 () { dirUserShare: function () {