Skip to content

Commit

Permalink
refactor(fileupload.js): use config.yaml even in js
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Feb 9, 2022
1 parent c2b6eff commit 95e2339
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion tools/attach/handlers/page/__edit.php
@@ -1,2 +1,11 @@
<?php
$this->AddJavascriptFile('tools/attach/libs/fileuploader.js');

use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Core\Service\AssetsManager;

$this->services->get(AssetsManager::class)->AddJavascript(
"var fileUploaderConfig = {attach_config:{ext_images:"
.json_encode(explode("|", $this->services->get(ParameterBagInterface::class)->get("attach_config")["ext_images"]))
."}};"
);
$this->services->get(AssetsManager::class)->AddJavascriptFile('tools/attach/libs/fileuploader.js');
2 changes: 1 addition & 1 deletion tools/attach/libs/fileuploader.js
Expand Up @@ -1416,7 +1416,7 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
UploadModal.find('.modal-title').append(fileuploaded).append(filesize);

// If it's an image
if ((responseJSON.extension === 'jpg') || (responseJSON.extension === 'jpeg') || (responseJSON.extension === 'gif') || (responseJSON.extension === 'png')) {
if (typeof fileUploaderConfig !== "undefined" && fileUploaderConfig.attach_config.ext_images.indexOf(responseJSON.extension) > -1) {
imageinput.show();
hiddenfilenameinput.val(responseJSON.simplefilename);
UploadModal.find('.attach_alt').val('image ' + responseJSON.simplefilename + ' (' + filesize.text() + ')');
Expand Down
4 changes: 3 additions & 1 deletion tools/bazar/fields/TextareaField.php
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use DateTimeZone;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Core\Service\DbService;

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ protected function renderInput($entry)
ob_start();
include_once 'tools/aceditor/actions/actions_builder.php';
$output = ob_get_contents();
ob_end_clean();
ob_end_clean();
}
}

Expand All @@ -113,6 +114,7 @@ protected function renderInput($entry)
'value' => $this->getValue($entry),
'entryId' => $entry['id_fiche'] ?? null,
'tempTag' => $tempTag,
'attachConfigExtImages' => explode("|", $this->getService(ParameterBagInterface::class)->get("attach_config")["ext_images"])
]);
}

Expand Down
3 changes: 3 additions & 0 deletions tools/bazar/templates/inputs/textarea.twig
Expand Up @@ -29,6 +29,9 @@
<div style="display:none;">{{ include('@attach/attach-file-uploader-button.twig',
{fileUploaderAnchor:'#' ~ field.name ~ 'Container .aceditor-toolbar',
fileUploaderSelector:'#' ~ field.name }) }}</div>
<script>
var fileUploaderConfig = {attach_config:{ext_images:{{ attachConfigExtImages|json_encode()|raw }}}};
</script>
{{ include_javascript('tools/attach/libs/fileuploader.js') }}
<!-- include_javascript('tools/attach/libs/fileuploader.js') -->
{% endif %}
Expand Down

0 comments on commit 95e2339

Please sign in to comment.