|
27 | 27 | @parent |
28 | 28 | {!! Theme::js('js/vendor/async/async.min.js') !!} |
29 | 29 | {!! Theme::js('js/vendor/lodash/lodash.js') !!} |
| 30 | + {!! Theme::js('js/vendor/upload/client.min.js') !!} |
30 | 31 | @endsection |
31 | 32 |
|
32 | 33 | @section('content') |
|
43 | 44 | <div class="ajax_loading_box"><i class="fa fa-refresh fa-spin" id="position_me"></i></div> |
44 | 45 | </div> |
45 | 46 | </div> |
46 | | - <div class="row"> |
| 47 | + <div class="row" id="upload_box"> |
47 | 48 | <div class="col-md-12" id="load_files"></div> |
48 | 49 | <div class="col-md-12"> |
49 | 50 | <div class="panel panel-default"> |
|
63 | 64 | <script> |
64 | 65 | $(window).load(function () { |
65 | 66 | $('.server-files').addClass('active'); |
| 67 | + @can('upload-files', $server) |
| 68 | + var notifyUploadSocketError = false; |
| 69 | + var uploadSocket = io('{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/upload/{{ $server->uuid }}', { |
| 70 | + 'query': 'token={{ $server->daemonSecret }}' |
| 71 | + }); |
| 72 | +
|
| 73 | + socket.io.on('connect_error', function (err) { |
| 74 | + siofu.destroy(); |
| 75 | + $('#applyUpdate').removeClass('fa-circle-o-notch fa-spinner fa-spin').addClass('fa-question-circle').css({ color: '#FF9900' }); |
| 76 | + if(typeof notifyUploadSocketError !== 'object') { |
| 77 | + notifyUploadSocketError = $.notify({ |
| 78 | + message: 'There was an error connecting to the Upload Socket for this server.' |
| 79 | + }, { |
| 80 | + type: 'danger', |
| 81 | + delay: 0 |
| 82 | + }); |
| 83 | + } |
| 84 | + }); |
| 85 | +
|
| 86 | + uploadSocket.on('error', err => { |
| 87 | + siofu.destroy(); |
| 88 | + console.error(err); |
| 89 | + }); |
| 90 | +
|
| 91 | + uploadSocket.on('connect', function () { |
| 92 | + if (notifyUploadSocketError !== false) { |
| 93 | + notifyUploadSocketError.close(); |
| 94 | + notifyUploadSocketError = false; |
| 95 | + } |
| 96 | + }); |
| 97 | +
|
| 98 | + socket.on('error', function (err) { |
| 99 | + console.error('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.'); |
| 100 | + }); |
| 101 | +
|
| 102 | +
|
| 103 | + var siofu = new SocketIOFileUpload(uploadSocket); |
| 104 | + siofu.chunkDelay = 25; |
| 105 | +
|
| 106 | + siofu.listenOnDrop(document.getElementById("upload_box")); |
| 107 | +
|
| 108 | + window.addEventListener('dragover', function (event) { |
| 109 | + event.preventDefault(); |
| 110 | + }, false); |
| 111 | +
|
| 112 | + window.addEventListener('drop', function (event) { |
| 113 | + event.preventDefault(); |
| 114 | + }, false); |
| 115 | +
|
| 116 | + var dropCounter = 0; |
| 117 | + $('#upload_box').bind({ |
| 118 | + dragenter: function (event) { |
| 119 | + event.preventDefault(); |
| 120 | + dropCounter++; |
| 121 | + $(this).addClass('hasFileHover'); |
| 122 | + }, |
| 123 | + dragleave: function (event) { |
| 124 | + dropCounter--; |
| 125 | + if (dropCounter === 0) { |
| 126 | + $(this).removeClass('hasFileHover'); |
| 127 | + } |
| 128 | + }, |
| 129 | + drop: function (event) { |
| 130 | + dropCounter = 0; |
| 131 | + $(this).removeClass('hasFileHover'); |
| 132 | + } |
| 133 | + }); |
| 134 | +
|
| 135 | + siofu.addEventListener('start', function (event) { |
| 136 | + event.file.meta.path = $('#headerTableRow').attr('data-currentdir'); |
| 137 | + event.file.meta.identifier = Math.random().toString(36).slice(2); |
| 138 | +
|
| 139 | + $('#append_files_to').append('<tr id="file-upload-' + event.file.meta.identifier +'"> \ |
| 140 | + <td><i class="fa fa-file-text-o" style="margin-left: 2px;"></i></td> \ |
| 141 | + <td>' + event.file.name + '</td> \ |
| 142 | + <td colspan=2"> </td> \ |
| 143 | + </tr><tr> \ |
| 144 | + <td colspan="4" class="has-progress"> \ |
| 145 | + <div class="progress progress-table-bottom active"> \ |
| 146 | + <div class="progress-bar progress-bar-info prog-bar-' + event.file.meta.identifier +'" style="width: 0%"></div> \ |
| 147 | + </div> \ |
| 148 | + </td> \ |
| 149 | + </tr>\ |
| 150 | + '); |
| 151 | + }); |
| 152 | +
|
| 153 | + siofu.addEventListener('progress', function(event) { |
| 154 | + var percent = event.bytesLoaded / event.file.size * 100; |
| 155 | + if (percent >= 100) { |
| 156 | + $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-success').parent().removeClass('active'); |
| 157 | + } else { |
| 158 | + $('.prog-bar-' + event.file.meta.identifier).css('width', percent + '%'); |
| 159 | + } |
| 160 | + }); |
| 161 | +
|
| 162 | + // Do something when a file is uploaded: |
| 163 | + siofu.addEventListener('complete', function(event){ |
| 164 | + if (!event.success) { |
| 165 | + $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger'); |
| 166 | + $.notify({ |
| 167 | + message: 'An error was encountered while attempting to upload this file.' |
| 168 | + }, { |
| 169 | + type: 'danger', |
| 170 | + delay: 5000 |
| 171 | + }); |
| 172 | + } |
| 173 | + }); |
| 174 | +
|
| 175 | + siofu.addEventListener('error', function(event){ |
| 176 | + $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger'); |
| 177 | + $.notify({ |
| 178 | + message: 'An error was encountered while attempting to upload this file.' |
| 179 | + }, { |
| 180 | + type: 'danger', |
| 181 | + delay: 5000 |
| 182 | + }); |
| 183 | + }); |
| 184 | + @endcan |
66 | 185 | }); |
67 | 186 | </script> |
68 | 187 | @endsection |
0 commit comments