Better file upload handling, add touch target
This commit is contained in:
parent
6149400ced
commit
da92796ca1
3 changed files with 28 additions and 18 deletions
|
@ -49,6 +49,10 @@ class FileManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#internal_alert').slideUp();
|
$('#internal_alert').slideUp();
|
||||||
|
|
||||||
|
if (typeof Siofu === 'object') {
|
||||||
|
Siofu.listenOnInput(document.getElementById("files_touch_target"));
|
||||||
|
}
|
||||||
}).fail(jqXHR => {
|
}).fail(jqXHR => {
|
||||||
this.loader(false);
|
this.loader(false);
|
||||||
if (_.isFunction(next)) {
|
if (_.isFunction(next)) {
|
||||||
|
|
|
@ -18,18 +18,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
(function initUploader() {
|
(function initUploader() {
|
||||||
var uploadInProgress = false;
|
|
||||||
var notifyUploadSocketError = false;
|
var notifyUploadSocketError = false;
|
||||||
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, {
|
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, {
|
||||||
'query': 'token=' + Pterodactyl.server.daemonSecret,
|
'query': 'token=' + Pterodactyl.server.daemonSecret,
|
||||||
});
|
});
|
||||||
|
|
||||||
window.onbeforeunload = function () {
|
|
||||||
if (uploadInProgress) {
|
|
||||||
return "An upload is in progress. Navigating away will abort this upload, are you sure you want to continue?";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadSocket.io.on('connect_error', function (err) {
|
uploadSocket.io.on('connect_error', function (err) {
|
||||||
if(typeof notifyUploadSocketError !== 'object') {
|
if(typeof notifyUploadSocketError !== 'object') {
|
||||||
notifyUploadSocketError = $.notify({
|
notifyUploadSocketError = $.notify({
|
||||||
|
@ -42,7 +35,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadSocket.on('error', err => {
|
uploadSocket.on('error', err => {
|
||||||
siofu.destroy();
|
Siofu.destroy();
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,8 +46,12 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var siofu = new SocketIOFileUpload(uploadSocket);
|
window.Siofu = new SocketIOFileUpload(uploadSocket);
|
||||||
siofu.listenOnDrop(document.getElementById("load_files"));
|
Siofu.listenOnDrop(document.getElementById("load_files"));
|
||||||
|
|
||||||
|
if (document.getElementById("files_touch_target")) {
|
||||||
|
Siofu.listenOnInput(document.getElementById("files_touch_target"));
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('dragover', function (event) {
|
window.addEventListener('dragover', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -83,8 +80,10 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
siofu.addEventListener('start', function (event) {
|
Siofu.addEventListener('start', function (event) {
|
||||||
uploadInProgress = true;
|
window.onbeforeunload = function () {
|
||||||
|
return 'A file upload in in progress, are you sure you want to continue?';
|
||||||
|
};
|
||||||
event.file.meta.path = $('#headerTableRow').attr('data-currentdir');
|
event.file.meta.path = $('#headerTableRow').attr('data-currentdir');
|
||||||
event.file.meta.identifier = Math.random().toString(36).slice(2);
|
event.file.meta.identifier = Math.random().toString(36).slice(2);
|
||||||
|
|
||||||
|
@ -102,7 +101,10 @@
|
||||||
');
|
');
|
||||||
});
|
});
|
||||||
|
|
||||||
siofu.addEventListener('progress', function(event) {
|
Siofu.addEventListener('progress', function(event) {
|
||||||
|
window.onbeforeunload = function () {
|
||||||
|
return 'A file upload in in progress, are you sure you want to continue?';
|
||||||
|
};
|
||||||
var percent = event.bytesLoaded / event.file.size * 100;
|
var percent = event.bytesLoaded / event.file.size * 100;
|
||||||
if (percent >= 100) {
|
if (percent >= 100) {
|
||||||
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-success').parent().removeClass('active');
|
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-success').parent().removeClass('active');
|
||||||
|
@ -112,8 +114,8 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// Do something when a file is uploaded:
|
// Do something when a file is uploaded:
|
||||||
siofu.addEventListener('complete', function(event) {
|
Siofu.addEventListener('complete', function(event) {
|
||||||
uploadInProgress = false;
|
window.onbeforeunload = function () {};
|
||||||
if (!event.success) {
|
if (!event.success) {
|
||||||
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
|
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
|
||||||
$.notify({
|
$.notify({
|
||||||
|
@ -125,8 +127,8 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
siofu.addEventListener('error', function(event) {
|
Siofu.addEventListener('error', function(event) {
|
||||||
uploadInProgress = false;
|
window.onbeforeunload = function () {};
|
||||||
console.error(event);
|
console.error(event);
|
||||||
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
|
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
|
||||||
$.notify({
|
$.notify({
|
||||||
|
|
|
@ -24,7 +24,11 @@
|
||||||
<th style="width:55%">@lang('server.files.file_name')</th>
|
<th style="width:55%">@lang('server.files.file_name')</th>
|
||||||
<th style="width:15%">@lang('server.files.size')</th>
|
<th style="width:15%">@lang('server.files.size')</th>
|
||||||
<th style="width:20%">@lang('server.files.last_modified')</th>
|
<th style="width:20%">@lang('server.files.last_modified')</th>
|
||||||
<th style="width:8%"></th>
|
<th style="width:8%">
|
||||||
|
<label class="btn btn-primary btn-xs btn-file">
|
||||||
|
Upload <input type="file" id="files_touch_target" style="display: none;"/>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="headerTableRow" data-currentdir="{{ $directory['header'] }}">
|
<tr id="headerTableRow" data-currentdir="{{ $directory['header'] }}">
|
||||||
<th><i class="fa fa-folder-open"></i></th>
|
<th><i class="fa fa-folder-open"></i></th>
|
||||||
|
|
Loading…
Reference in a new issue