diff options
| author | Kana <[email protected]> | 2017-04-27 09:14:14 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-04-27 09:14:14 +0200 |
| commit | d2b4d20c36a37c95dba227367106c7e55a667e86 (patch) | |
| tree | ca5111b938b7afc657e45a6095e111cb71c2c65e /public | |
| parent | Keep the bad guys out >:c (#36) (diff) | |
| parent | removed all trailing spaces (I think) (diff) | |
| download | host.fuwn.me-d2b4d20c36a37c95dba227367106c7e55a667e86.tar.xz host.fuwn.me-d2b4d20c36a37c95dba227367106c7e55a667e86.zip | |
Merge pull request #32 from Onestay/onestay-dev
Added upload to album through website
Diffstat (limited to 'public')
| -rw-r--r-- | public/css/style.css | 5 | ||||
| -rw-r--r-- | public/js/home.js | 48 |
2 files changed, 48 insertions, 5 deletions
diff --git a/public/css/style.css b/public/css/style.css index 729b3d4..ac3959d 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -105,3 +105,8 @@ section#dashboard .table { font-size: 12px } section#dashboard div#table div.column { display:flex; width: 200px; height: 200px; margin: 9px; background: #f9f9f9; overflow: hidden; align-items: center; } section#dashboard div#table div.column a { width: 100%; } section#dashboard div#table div.column a img { width:200px; } + +.select-wrapper { + text-align: center; + margin-bottom: 10px; +} diff --git a/public/js/home.js b/public/js/home.js index 6253c10..a9ca41c 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -3,9 +3,10 @@ var upload = {}; upload.isPrivate = true; upload.token = localStorage.token; upload.maxFileSize; +// add the album var to the upload so we can store the album id in there +upload.album; upload.checkIfPublic = function(){ - axios.get('/api/check') .then(function (response) { upload.isPrivate= response.data.private; @@ -16,7 +17,6 @@ upload.checkIfPublic = function(){ return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); console.log(error); }); - } upload.preparePage = function(){ @@ -61,6 +61,33 @@ upload.verifyToken = function(token, reloadOnError){ } upload.prepareUpload = function(){ + // I think this fits best here because we need to check for a valid token before we can get the albums + if (upload.token) { + var select = document.querySelector('select'); + + axios.get('/api/albums', { headers: { token: upload.token }}) + .then(function(res) { + var albums = res.data.albums; + + // if the user doesn't have any albums we don't really need to display + // an album selection + if (albums.length === 0) return; + + // loop through the albums and create an option for each album + for (var i = 0; i < albums.length; i++) { + var opt = document.createElement('option'); + opt.value = albums[i].id; + opt.innerHTML = albums[i].name; + select.appendChild(opt); + } + // display the album selection + document.getElementById('albumDiv').style.display = 'block'; + }) + .catch(function(e) { + return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); + console.log(e); + }) + } div = document.createElement('div'); div.id = 'dropzone'; @@ -74,13 +101,12 @@ upload.prepareUpload = function(){ document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads'; document.getElementById('uploadContainer').appendChild(div); - + upload.prepareDropzone(); } upload.prepareDropzone = function(){ - var previewNode = document.querySelector('#template'); previewNode.id = ''; var previewTemplate = previewNode.parentNode.innerHTML; @@ -105,6 +131,12 @@ upload.prepareDropzone = function(){ myDropzone = this; document.getElementById('uploads').style.display = 'block'; }); + // add the selected albumid, if an album is selected, as a header + this.on('sending', function(file, xhr) { + if (upload.album) { + xhr.setRequestHeader('albumid', upload.album) + } + }); } }); @@ -155,4 +187,10 @@ window.addEventListener('paste', function(event) { window.onload = function () { upload.checkIfPublic(); -};
\ No newline at end of file + + // eventlistener for the album select + document.querySelector('select').addEventListener('change', function() { + upload.album = document.querySelector('select').value; + }); +}; + |