mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 17:28:41 +00:00
Simplify template and improve/fix upload functionality
This commit is contained in:
parent
e084c7004a
commit
011df2a6d1
|
|
@ -1,6 +1,9 @@
|
||||||
import { Autoloader } from '../../jsOMS/Autoloader.js';
|
import { Autoloader } from '../../jsOMS/Autoloader.js';
|
||||||
import { Application } from '../../Web/Backend/js/backend.js';
|
import { Application } from '../../Web/Backend/js/backend.js';
|
||||||
import { Upload } from './Models/Upload.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');
|
Autoloader.defineNamespace('jsOMS.Modules');
|
||||||
|
|
||||||
|
|
@ -53,11 +56,18 @@ jsOMS.Modules.Media = class {
|
||||||
|
|
||||||
uploader.setSuccess(e.id, function (type, response)
|
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);
|
self.app.eventManager.trigger(form.id, requestId);
|
||||||
});
|
});
|
||||||
|
|
||||||
uploader.setUri('{/base}/{/lang}/api/media');
|
uploader.setUri('api/media');
|
||||||
|
|
||||||
const length = fileFields.length;
|
const length = fileFields.length;
|
||||||
let fileLength = 0;
|
let fileLength = 0;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use Modules\Media\Models\Collection;
|
||||||
use Modules\Media\Models\CollectionMapper;
|
use Modules\Media\Models\CollectionMapper;
|
||||||
use Modules\Media\Models\UploadFile;
|
use Modules\Media\Models\UploadFile;
|
||||||
use Modules\Media\Models\UploadStatus;
|
use Modules\Media\Models\UploadStatus;
|
||||||
|
use phpOMS\Message\NotificationLevel;
|
||||||
|
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
|
|
@ -88,25 +89,7 @@ final class ApiController extends Controller
|
||||||
$ids[] = $file->getId();
|
$ids[] = $file->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fillJsonRawResponse($request, $response, $ids);
|
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully created.', $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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,7 @@ final class BackendController extends Controller
|
||||||
{
|
{
|
||||||
/** @var \phpOMS\Model\Html\Head $head */
|
/** @var \phpOMS\Model\Html\Head $head */
|
||||||
$head = $response->get('Content')->getData('head');
|
$head = $response->get('Content')->getData('head');
|
||||||
$head->addAsset(AssetType::JSLATE, 'Modules/Media/Models/Upload.js');
|
$head->addAsset(AssetType::JSLATE, 'Modules/Media/Controller.js', ['type' => 'module']);
|
||||||
$head->addAsset(AssetType::JSLATE, 'Modules/Media/Controller.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.
|
* Media uploader.
|
||||||
*
|
*
|
||||||
|
|
@ -157,6 +162,7 @@ export class Upload {
|
||||||
request.setSuccess(function (xhr)
|
request.setSuccess(function (xhr)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
console.log(xhr.response);
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
|
|
||||||
if (!self.success[formId]) {
|
if (!self.success[formId]) {
|
||||||
|
|
|
||||||
|
|
@ -180,11 +180,13 @@ class UploadFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isInterlaced && \in_array($extension, FileUtils::IMAGE_EXTENSION)) {
|
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 !== '') {
|
if ($encoding !== '') {
|
||||||
FileUtils::changeFileEncoding($dest, $encoding);
|
// changing encoding bugs out image files
|
||||||
|
//FileUtils::changeFileEncoding($dest, $encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[$key]['path'] = \realpath($this->outputDir);
|
$result[$key]['path'] = \realpath($this->outputDir);
|
||||||
|
|
@ -255,7 +257,7 @@ class UploadFile
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
\imageinterlace($img, (int) $this->isInterlaced);
|
\imageinterlace($img, $this->isInterlaced ? 1 : 0);
|
||||||
|
|
||||||
if ($extension === 'png') {
|
if ($extension === 'png') {
|
||||||
\imagepng($img, $path);
|
\imagepng($img, $path);
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,8 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<header><h1><?= $this->getHtml('Upload') ?></h1></header>
|
<header><h1><?= $this->getHtml('Upload') ?></h1></header>
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<form method="POST" id="media-uploader" action="<?= \phpOMS\Uri\UriFactory::build('{/api}media'); ?>">
|
<form method="POST" id="media-uploader" action="">
|
||||||
<table class="layout wf-100">
|
<table class="layout wf-100">
|
||||||
<tr><td><label for="iName"><?= $this->getHtml('Name') ?></label>
|
|
||||||
<tr><td><input type="text" id="iName" name="name" placeholder="">
|
|
||||||
<tr><td><label for="iDescription"><?= $this->getHtml('Description') ?></label>
|
|
||||||
<tr><td><textarea id="iDescription" name="description"></textarea>
|
|
||||||
<tr><td><label for="iFiles"><?= $this->getHtml('Files') ?></label>
|
<tr><td><label for="iFiles"><?= $this->getHtml('Files') ?></label>
|
||||||
<tr><td><input type="file" id="iFiles" name="files" multiple><input name="media" type="hidden">
|
<tr><td><input type="file" id="iFiles" name="files" multiple><input name="media" type="hidden">
|
||||||
<tr><td><input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', 0, 0); ?>">
|
<tr><td><input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', 0, 0); ?>">
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ echo $this->getData('nav')->render();
|
||||||
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||||
|
|
||||||
if ($this->isImageFunction($media, $path)) : ?>
|
if ($this->isImageFunction($media, $path)) : ?>
|
||||||
<div class="h-overflow">
|
<div class="h-overflow centerText">
|
||||||
<img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>">
|
<img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>">
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user