# File Links:
# Makes a list of files for download.
#
# CType: uploads

tt_content.uploads = COA
tt_content.uploads {
    10 = < lib.stdheader
    20 = FILES
    20 {
        # get from file references:
        references {
            table = tt_content
            fieldName = media
        }
        collections.field = file_collections
        # get from path (backwards compatibility, contains strings like "fileadmin/user_uploads/")
        folders.field = select_key
        sorting.field = filelink_sorting
        # render the files
        renderObj = COA
        renderObj {
            10 = IMAGE
            10 {
                file.import.data = file:current:originalUid // file:current:uid
                file.width = 150
                stdWrap {
                    if {
                        value = 2
                        equals.field = uploads_type
                    }
                    typolink {
                        parameter.data = file:current:originalUid // file:current:uid
                        parameter.wrap = file:|
                        fileTarget < lib.parseTarget
                        fileTarget =
                        fileTarget.override = {$styles.content.uploads.target}
                        fileTarget.override.override.field = target
                        removePrependedNumbers = 1

                        title {
                            data = file:current:title
                            htmlSpecialChars = 1
                        }
                        /*
                        jumpurl = {$styles.content.uploads.jumpurl}
                        jumpurl {
                            secure = {$styles.content.uploads.jumpurl_secure}
                            secure.mimeTypes = {$styles.content.uploads.jumpurl_secure_mimeTypes}
                        }
                        */
                    }
                }
            }
            # icon
            15 = IMAGE
            15 {
                file.import.data = file:current:extension
                file.import.case = lower
                file.import.dataWrap = {path:EXT:frontend/Resources/Public/Icons/FileIcons/}|.gif
                stdWrap {
                    if {
                        value = 1,2
                        isInList.field = uploads_type
                        # only show the icon if we don't have a thumbnail:
                        isFalse.cObject = IMG_RESOURCE
                        isFalse.cObject.file < tt_content.uploads.20.renderObj.10.file
                        isFalse.cObject.stdWrap.if < tt_content.uploads.20.renderObj.10.stdWrap.if
                    }
                    typolink < tt_content.uploads.20.renderObj.10.stdWrap.typolink
                }
            }
            # filename
            20 = TEXT
            20 {
                data = file:current:title // file:current:name
                htmlSpecialChars = 1
                required = 1
                replacement {
                    # equivalent to former useSpacesInLinkText = 0; remove using > to disable it
                    10 {
                        search = _
                        replace.char = 32
                    }
                    # equivalent to former stripFileExtensionFromLinkText = 0; move "_20" to "20" to enable it. Disabled by default.
                    _20 {
                        search = /(.*)(\..*)/
                        replace = \1
                        useRegExp = 1
                    }
                }
                typolink < tt_content.uploads.20.renderObj.10.stdWrap.typolink
                wrap = <span class="ce-uploads-fileName">|</span>
            }
            # description
            30 = TEXT
            30 {
                if.isTrue.field = uploads_description
                data = file:current:description
                htmlSpecialChars = 1
                wrap = <span class="ce-uploads-description">|</span>
                required = 1
            }
            # file size
            40 = TEXT
            40 {
                if.isTrue.field = filelink_size
                data = file:current:size
                wrap = <span class="ce-uploads-filesize">|</span>
                bytes = 1
                bytes.labels = {$styles.content.uploads.filesizeBytesLabels}
            }
            # wrap of each listed file with odd/even class
            wrap.cObject = COA
            wrap.cObject {
                10 = LOAD_REGISTER
                10 {
                    elementClass = ce-uploads-element ce-uploads-element-{file:current:extension}
                    elementClass.insertData = 1
                }
                20 = TEXT
                20 {
                    value = <li class="{register:elementClass}">|</li>
                    insertData = 1
                }
                30 = RESTORE_REGISTER
            }
        }
        # wrap around whole content element with <ul> and editIcons
        stdWrap {
            editIcons = tt_content: media, filelink_size, uploads_description, uploads_type
            editIcons.iconTitle.data = LLL:EXT:css_styled_content/Resources/Private/Language/locallang.xlf:eIcon.filelist
            prefixComment = 2 | Filelist:
            dataWrap = <ul class="ce-uploads">|</ul>
        }
    }
}
