Commit 3becfef7 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Mise en place d'icônes de fichier.

Showing with 69 additions and 4 deletions
+69 -4
......@@ -552,6 +552,7 @@ class UploadedFile implements UploadedFileInterface
'type' => $this->getMimeType(),
'etat' => $this->getEtat(),
'checksum' => $this->getChecksum(),
'icon' => MimeTypeIcon::getMimeTypeIcon($this->getMimeType())
];
}
}
......@@ -103,6 +103,11 @@
.attr('data-url', file.delete_url + csrfQuery);
row.find('input:hidden')
.val(file.id);
if(file.icon && file.icon !== 'file') {
row.find('.icon')
.removeClass('fa-file-o')
.addClass('fa-file-'+file.icon+'-o');
}
}
rows = rows.add(row);
});
......
......@@ -2,7 +2,7 @@
{% block file_upload_progress_prototype %}
<div class="template-upload fileinput-entry">
<div class="progress-text" style="display: none"></div>
<span class="name">Monfichier.com</span>&nbsp;(<span class="size">1.5 Gio</span>)
<i class="fa fa-circle-o-notch fa-spin icon"></i>&nbsp;<span class="name"></span>&nbsp;(<span class="size"></span>)
<span class="error" style="display: none"></span>
<a href="#" class="danger cancel" title="{% trans %}button.cancel{% endtrans %}">
{{- irstea_icon('remove') -}}
......@@ -17,9 +17,9 @@
{%- set file = file|default([]) %}
<div class="template-download fileinput-entry">
<input type="hidden" name="{{ full_name }}{% if multiple %}[]{% endif %}" value="{{ file.id|default }}"/>
<span class="name">
<a{% if file %} href="{{ path('file_upload_get_content', {id: file.id, token: csrf_token}) }}"{% endif %}>{{ file.originalFilename|default }}</a>
</span>
<i class="fa fa-file{% if file.icon|default(false) %}-{{ file.icon }}{% endif %}-o icon"></i>&nbsp;<span class="name">
<a{% if file %} href="{{ path('file_upload_get_content', {id: file.id, token: csrf_token}) }}"{% endif %}>{{ file.name|default }}</a>
</span>
(<span class="size">
{{- file.size|default -}}
</span>)
......
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle\Utils;
/**
* Description of MimeTypeIcon
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
final class MimeTypeIcon
{
private static $icons = [
'application/x-gzip' => 'zip',
'application/vnd.oasis.opendocument.text' => 'word',
'application/vnd.oasis.opendocument.spreadsheet' => 'excel',
'application/vnd.oasis.opendocument.presentation' => 'powerpoint',
'application/vnd.oasis.opendocument.graphics' => 'image',
'application/vnd.ms-excel' => 'excel',
'application/vnd.ms-powerpoint' => 'powerpoint',
'application/msword' => 'word',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'powerpoint',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word',
'application/pdf' => 'pdf',
'application/zip' => 'archive',
'application/x-rar-compressed' => 'archive',
'application/x-gtar' => 'archive',
'application/x-gzip' => 'archive',
'application/x-tar' => 'archive'
];
/**
*
* @param string $mimeType
* @return string|null
*/
public static function getMimeTypeIcon($mimeType)
{
if(!is_string($mimeType)) {
return null;
}
if(isset(self::$icons[$mimeType])) {
return self::$icons[$mimeType];
}
$matches = [];
if(preg_match('@^(text|audio|video|image)/@', $mimeType, $matches)) {
return $matches[1];
}
return null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment