Skip to content

Commit

Permalink
SHARE-299 - disable multi download webview
Browse files Browse the repository at this point in the history
Must be fixed in the future in combined teamwork with the android team
  • Loading branch information
dmetzner committed May 18, 2020
1 parent 5ebc74b commit a366e23
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
81 changes: 52 additions & 29 deletions assets/js/custom/MediaLib.js
Expand Up @@ -7,7 +7,7 @@

// eslint-disable-next-line no-unused-vars
function MediaLib (packageName, mediaSearchPath, flavor, assetsDir,
elementsTranslationSingular, elementsTranslationPlural) {
elementsTranslationSingular, elementsTranslationPlural, isWebView = false) {
$(function () {
// Removing the project navigation items and showing just the category menu items
const element = document.getElementById('project-navigation')
Expand All @@ -22,25 +22,24 @@ function MediaLib (packageName, mediaSearchPath, flavor, assetsDir,
})

function getPackageFiles (packageName, mediaSearchPath, flavor, assetsDir) {
var downloadList = []
let downloadList = []

document.getElementById('top-app-bar__btn-download-selection').onclick = function () {
for (var i = 0; i < downloadList.length; i++) {
for (let i = 0; i < downloadList.length; i++) {
medialibDownloadSelectedFile(downloadList[i])
}
document.getElementById('top-app-bar__btn-cancel-download-selection').click()
}

document.getElementById('top-app-bar__btn-cancel-download-selection').onclick = function () {
for (var i = 0; i < downloadList.length; i++) {
for (let i = 0; i < downloadList.length; i++) {
document.getElementById('mediafile-' + downloadList[i].id).classList.remove('selected')
}
downloadList = []
showTopBarDefault()
}

var url = null

let url
if (mediaSearchPath !== '') {
url = mediaSearchPath
} else {
Expand All @@ -55,30 +54,40 @@ function MediaLib (packageName, mediaSearchPath, flavor, assetsDir,

const mediafileContainer = $('<a class="mediafile" id="mediafile-' + file.id + '"/>')
mediafileContainer.click(function () {
mediafileContainer.toggleClass('selected')
var indexInDownloadList = downloadList.indexOf(file)

if (indexInDownloadList === -1) {
downloadList.push(file)
} else {
downloadList.splice(indexInDownloadList, 1)
}
// !!! Due to missing android web view support the download multiple files feature was "disabled" !!!!!
// For now it is only possible to select one element! ToDo: send zip files if multiple files are downloaded.
if (isWebView) {
mediafileContainer.attr('href', file.download_url)
mediafileContainer.attr('data-extension', file.extension)
mediafileContainer.click(function () {
medialibOnDownload(this)
})
} else { // -- end of disable
mediafileContainer.toggleClass('selected')
const indexInDownloadList = downloadList.indexOf(file)

if (indexInDownloadList === -1) {
downloadList.push(file)
} else {
downloadList.splice(indexInDownloadList, 1)
}

let elementsText = downloadList.length + ' '
// Dispense support for languages where the count would be right.
// This way there is no need to dynamically load the translation. (No delay - Less requests)
if (downloadList.length === 1) {
elementsText += elementsTranslationSingular
} else {
elementsText += elementsTranslationPlural
}
let elementsText = downloadList.length + ' '
// Dispense support for languages where the count would be right.
// This way there is no need to dynamically load the translation. (No delay - Less requests)
if (downloadList.length === 1) {
elementsText += elementsTranslationSingular
} else {
elementsText += elementsTranslationPlural
}

document.getElementById('top-app-bar__download-nr-selected').innerText = elementsText
document.getElementById('top-app-bar__download-nr-selected').innerText = elementsText

if (downloadList.length > 0) {
showTopBarDownload()
} else {
showTopBarDefault()
if (downloadList.length > 0) {
showTopBarDownload()
} else {
showTopBarDefault()
}
}
})

Expand Down Expand Up @@ -310,7 +319,7 @@ function MediaLib (packageName, mediaSearchPath, flavor, assetsDir,
}
})

document.addEventListener('touchend', function (e) {
document.addEventListener('touchend', function () {
reset()
})

Expand All @@ -322,11 +331,25 @@ function MediaLib (packageName, mediaSearchPath, flavor, assetsDir,
}

function medialibDownloadSelectedFile (file) {
var link = document.createElement('a')
const link = document.createElement('a')
link.href = file.download_url
link.download = file.name
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
return false
}

function medialibOnDownload (link) {
if (link.href !== 'javascript:void(0)') {
const downloadHref = link.href
link.href = 'javascript:void(0)'

setTimeout(function () {
link.href = downloadHref
}, 5000)

window.location = downloadHref
}
return false
}
3 changes: 2 additions & 1 deletion templates/MediaLibrary/mediapackage.html.twig
Expand Up @@ -44,7 +44,8 @@
"{{ flavor }}",
"{{ mediaDir }}",
"{{ "element"|trans({}, "catroweb") }}",
"{{ "elements"|trans({}, "catroweb") }}"
"{{ "elements"|trans({}, "catroweb") }}",
"{{ isWebview() }}"
);
</script>
{% endblock %}

0 comments on commit a366e23

Please sign in to comment.