diff --git a/Controller.js b/Controller.js index 81d133a..3c57d82 100644 --- a/Controller.js +++ b/Controller.js @@ -1,6 +1,9 @@ import { Autoloader } from '../../jsOMS/Autoloader.js'; import { Application } from '../../Web/Backend/js/backend.js'; import { Upload } from './Models/Upload.js'; +import { NotificationMessage } from '../../jsOMS/Message/Notification/NotificationMessage.js'; +import { NotificationLevel } from '../../jsOMS/Message/Notification/NotificationLevel.js'; +import { NotificationType } from '../../jsOMS/Message/Notification/NotificationType.js'; Autoloader.defineNamespace('jsOMS.Modules'); @@ -53,11 +56,18 @@ jsOMS.Modules.Media = class { uploader.setSuccess(e.id, function (type, response) { - document.querySelector('input[form=' + e.id + '][type=file]+input[form=' + e.id + '][type=hidden]').value = JSON.stringify(response); + self.app.notifyManager.send( + new NotificationMessage(response[0].status, response[0].title, response[0].message), NotificationType.APP_NOTIFICATION + ); + + document.querySelector( + '#' + e.id + ' input[type=file]+input[type=hidden], ' + + 'input[form=' + e.id + '][type=file]+input[type=hidden]' + ).value = response[0].response; self.app.eventManager.trigger(form.id, requestId); }); - uploader.setUri('{/base}/{/lang}/api/media'); + uploader.setUri('api/media'); const length = fileFields.length; let fileLength = 0; diff --git a/Controller/ApiController.php b/Controller/ApiController.php index b5da2e8..bfacd54 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -20,6 +20,7 @@ use Modules\Media\Models\Collection; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\UploadFile; use Modules\Media\Models\UploadStatus; +use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -88,25 +89,7 @@ final class ApiController extends Controller $ids[] = $file->getId(); } - $this->fillJsonRawResponse($request, $response, $ids); - } - - /** - * Shows api content. - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param mixed $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void - { - // todo: change database entry for files if has write permission + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully created.', $ids); } /** diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 04cdd68..a20f716 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -98,8 +98,7 @@ final class BackendController extends Controller { /** @var \phpOMS\Model\Html\Head $head */ $head = $response->get('Content')->getData('head'); - $head->addAsset(AssetType::JSLATE, 'Modules/Media/Models/Upload.js'); - $head->addAsset(AssetType::JSLATE, 'Modules/Media/Controller.js'); + $head->addAsset(AssetType::JSLATE, 'Modules/Media/Controller.js', ['type' => 'module']); } /** diff --git a/Models/Upload.js b/Models/Upload.js index 9c58f4a..b2eb8ce 100644 --- a/Models/Upload.js +++ b/Models/Upload.js @@ -1,3 +1,8 @@ +import { Request } from '../../../jsOMS/Message/Request/Request.js'; +import { RequestType } from '../../../jsOMS/Message/Request/RequestType.js'; +import { RequestMethod } from '../../../jsOMS/Message/Request/RequestMethod.js'; +import { Logger } from '../../../jsOMS/Log/Logger.js'; + /** * Media uploader. * @@ -157,6 +162,7 @@ export class Upload { request.setSuccess(function (xhr) { try { + console.log(xhr.response); const response = JSON.parse(xhr.response); if (!self.success[formId]) { diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 4341208..d7ec169 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -180,11 +180,13 @@ class UploadFile } if ($this->isInterlaced && \in_array($extension, FileUtils::IMAGE_EXTENSION)) { - $this->interlace($extension, $dest); + // todo: interlacing somehow messes up some images (tested with logo.png from assets) + //$this->interlace($extension, $dest); } if ($encoding !== '') { - FileUtils::changeFileEncoding($dest, $encoding); + // changing encoding bugs out image files + //FileUtils::changeFileEncoding($dest, $encoding); } $result[$key]['path'] = \realpath($this->outputDir); @@ -255,7 +257,7 @@ class UploadFile return; } - \imageinterlace($img, (int) $this->isInterlaced); + \imageinterlace($img, $this->isInterlaced ? 1 : 0); if ($extension === 'png') { \imagepng($img, $path); diff --git a/Theme/Backend/media-create.tpl.php b/Theme/Backend/media-create.tpl.php index 7a1f3ff..1d1b1a6 100644 --- a/Theme/Backend/media-create.tpl.php +++ b/Theme/Backend/media-create.tpl.php @@ -20,12 +20,8 @@ echo $this->getData('nav')->render(); ?>

getHtml('Upload') ?>

-
+ -
-
-
-
diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index ebfd1c4..a8c3d36 100644 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -99,7 +99,7 @@ echo $this->getData('nav')->render(); $path = $this->filePathFunction($media, $this->request->getData('sub') ?? ''); if ($this->isImageFunction($media, $path)) : ?> -
+