init
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceContainer name="content">
|
||||
<block class="Esun\Video\Block\Adminhtml\Video\EditBlock"
|
||||
name="esun.video.edit"
|
||||
template="Esun_Video::video/edit.phtml"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceContainer name="content">
|
||||
<block class="Esun\Video\Block\Adminhtml\Video\ListBlock"
|
||||
name="esun.video.list"
|
||||
template="Esun_Video::video/list.phtml"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,9 @@
|
||||
var config = {
|
||||
config: {
|
||||
mixins: {
|
||||
'Magento_ProductVideo/js/new-video-dialog': {
|
||||
'Esun_Video/js/new-video-dialog-mixin': true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Extends the native Magento Add Video dialog with Esun managed-video controls.
|
||||
*
|
||||
* @var \Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo $block
|
||||
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
|
||||
*/
|
||||
?>
|
||||
<div id="<?= $block->escapeHtmlAttr($block->getNameInLayout()) ?>"
|
||||
data-modal-info='<?= /* @noEscape */ $block->getWidgetOptions() ?>'>
|
||||
<?= $block->getFormHtml() ?>
|
||||
<?= $block->getChildHtml('esun-video-upload') ?>
|
||||
<div id="video-player-preview-location" class="video-player-sidebar">
|
||||
<div class="video-player-container"></div>
|
||||
<div class="video-information title">
|
||||
<label><?= $block->escapeHtml(__('Title:')) ?> </label><span></span>
|
||||
</div>
|
||||
<div class="video-information uploaded">
|
||||
<label><?= $block->escapeHtml(__('Uploaded:')) ?> </label><span></span>
|
||||
</div>
|
||||
<div class="video-information uploader">
|
||||
<label><?= $block->escapeHtml(__('Uploader:')) ?> </label><span></span>
|
||||
</div>
|
||||
<div class="video-information duration">
|
||||
<label><?= $block->escapeHtml(__('Duration:')) ?> </label><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
|
||||
'display:none',
|
||||
'div#' . $block->escapeJs($block->getNameInLayout())
|
||||
) ?>
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/** @var \Esun\Video\Block\Adminhtml\Product\Upload $block */
|
||||
?>
|
||||
<div id="esun-product-video-integration"
|
||||
data-mage-init='{"Esun_Video/js/product-video-id-upload":{}}'
|
||||
data-options="<?= $block->escapeHtmlAttr($block->getOptionsJson()) ?>">
|
||||
<fieldset class="admin__fieldset">
|
||||
<legend class="admin__legend"><span><?= $block->escapeHtml(__('Video Management')) ?></span></legend>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label">
|
||||
<span><?= $block->escapeHtml(__('Video ID')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<div class="esun-video-library-actions"
|
||||
style="display:flex;align-items:center;gap:1rem;width:100%">
|
||||
<input type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
class="admin__control-text"
|
||||
data-role="esun-video-id-input-v2"
|
||||
placeholder="<?= $block->escapeHtmlAttr(__('Enter video ID')) ?>"
|
||||
style="flex:0 0 55%;width:55%;min-width:20rem">
|
||||
<button type="button"
|
||||
class="action-secondary"
|
||||
data-role="esun-add-video-by-id-v2"
|
||||
style="flex:0 0 auto">
|
||||
<span><?= $block->escapeHtml(__('Add Video')) ?></span>
|
||||
</button>
|
||||
</div>
|
||||
<div style="margin-top:1rem">
|
||||
<button type="button" class="action-secondary" data-role="open-mp4-upload">
|
||||
<span><?= $block->escapeHtml(__('Upload New MP4')) ?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div data-role="mp4-upload-dialog" hidden>
|
||||
<form class="admin__fieldset" data-role="esun-video-form">
|
||||
<div class="admin__field _required">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Title')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input class="admin__control-text" name="title" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Description')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<textarea class="admin__control-textarea" name="description"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field _required">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('MP4 Video')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input type="file" name="video" accept="video/mp4,.mp4" required>
|
||||
<progress data-role="progress" max="100" value="0" hidden style="width:100%;margin-top:1rem"></progress>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Cover Image')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input type="file"
|
||||
name="cover"
|
||||
accept="image/jpeg,image/png,image/gif"
|
||||
data-role="cover-image-input">
|
||||
<p class="note" data-role="cover-image-empty-note">
|
||||
<?= $block->escapeHtml(__('The system will use the video frame at the 1-second mark if left empty.')) ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Status')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<select class="admin__control-select" name="status">
|
||||
<option value="1"><?= $block->escapeHtml(__('Enabled')) ?></option>
|
||||
<option value="0"><?= $block->escapeHtml(__('Disabled')) ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/** @var \Esun\Video\Block\Adminhtml\Video\EditBlock $block */
|
||||
$video = $block->getVideo();
|
||||
?>
|
||||
<form method="post"
|
||||
action="<?= $block->escapeUrl($block->getSaveUrl()) ?>"
|
||||
enctype="multipart/form-data">
|
||||
<?= $block->getBlockHtml('formkey') ?>
|
||||
<input type="hidden" name="video_id" value="<?= (int)$video->getId() ?>">
|
||||
|
||||
<div class="page-main-actions">
|
||||
<div class="page-actions">
|
||||
<a class="action-secondary" href="<?= $block->escapeUrl($block->getBackUrl()) ?>">
|
||||
<span><?= $block->escapeHtml(__('Back')) ?></span>
|
||||
</a>
|
||||
<button type="submit" class="action-primary">
|
||||
<span><?= $block->escapeHtml(__('Save Video')) ?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="admin__fieldset">
|
||||
<div class="admin__field _required">
|
||||
<label class="admin__field-label" for="esun-video-title">
|
||||
<span><?= $block->escapeHtml(__('Title')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<input id="esun-video-title"
|
||||
type="text"
|
||||
name="title"
|
||||
class="admin__control-text"
|
||||
required
|
||||
value="<?= $block->escapeHtmlAttr((string)$video->getData('title')) ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label" for="esun-video-description">
|
||||
<span><?= $block->escapeHtml(__('Description')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<textarea id="esun-video-description"
|
||||
name="description"
|
||||
class="admin__control-textarea"
|
||||
rows="6"><?= $block->escapeHtml((string)$video->getData('description')) ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label" for="esun-video-status">
|
||||
<span><?= $block->escapeHtml(__('Status')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<select id="esun-video-status" name="status" class="admin__control-select">
|
||||
<option value="1" <?= (int)$video->getData('status') === 1 ? 'selected' : '' ?>>
|
||||
<?= $block->escapeHtml(__('Enabled')) ?>
|
||||
</option>
|
||||
<option value="0" <?= (int)$video->getData('status') === 0 ? 'selected' : '' ?>>
|
||||
<?= $block->escapeHtml(__('Disabled')) ?>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label">
|
||||
<span><?= $block->escapeHtml(__('Current Cover')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<?php if ($video->getData('cover_path')): ?>
|
||||
<img src="<?= $block->escapeUrl($block->getMediaUrl((string)$video->getData('cover_path'))) ?>"
|
||||
alt=""
|
||||
style="display:block;max-width:32rem;max-height:20rem;margin-bottom:1rem">
|
||||
<?php else: ?>
|
||||
<span><?= $block->escapeHtml(__('No cover image')) ?></span>
|
||||
<?php endif; ?>
|
||||
<input type="file" name="cover" accept="image/jpeg,image/png,image/gif,image/webp">
|
||||
<p class="note">
|
||||
<?= $block->escapeHtml(__('Leave empty to keep the current cover image.')) ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label">
|
||||
<span><?= $block->escapeHtml(__('Video Metadata')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control">
|
||||
<p>
|
||||
<?= $block->escapeHtml(__(
|
||||
'%1 × %2, %3, %4 seconds, %5 MB',
|
||||
(int)$video->getData('width'),
|
||||
(int)$video->getData('height'),
|
||||
(string)$video->getData('resolution'),
|
||||
number_format((float)$video->getData('duration'), 2),
|
||||
number_format((int)$video->getData('size') / 1048576, 2)
|
||||
)) ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/** @var \Esun\Video\Block\Adminhtml\Video\ListBlock $block */
|
||||
$missingBinaries = $block->getMissingBinaries();
|
||||
?>
|
||||
<?php if ($missingBinaries): ?>
|
||||
<div class="messages">
|
||||
<div class="message message-error error"
|
||||
style="font-size:1.5rem;font-weight:600;border-left-width:5px">
|
||||
<div>
|
||||
<?= $block->escapeHtml(__(
|
||||
'Video processing tools are unavailable: %1. Install them or correct their binary paths under Stores → Configuration → Esun → Video Management.',
|
||||
implode(', ', array_map(
|
||||
static fn(string $name, string $binary): string => $name . ' (' . $binary . ')',
|
||||
array_keys($missingBinaries),
|
||||
array_values($missingBinaries)
|
||||
))
|
||||
)) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="page-main-actions">
|
||||
<div class="page-actions">
|
||||
<button type="button"
|
||||
class="action-primary"
|
||||
data-role="open-video-upload"
|
||||
<?= $block->isUploadEnabled() ? '' : 'disabled' ?>>
|
||||
<span><?= $block->escapeHtml(__('Upload Video')) ?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin__data-grid-header" style="margin-bottom:2rem">
|
||||
<form method="get"
|
||||
action="<?= $block->escapeUrl($block->getFilterUrl()) ?>"
|
||||
style="display:flex;align-items:flex-end;gap:1.5rem;flex-wrap:wrap">
|
||||
<div class="admin__field" style="margin:0;min-width:28rem">
|
||||
<label class="admin__field-label" for="esun-video-filter-title" style="float:none;width:auto;text-align:left">
|
||||
<span><?= $block->escapeHtml(__('Title')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control" style="float:none;width:auto">
|
||||
<input id="esun-video-filter-title"
|
||||
type="text"
|
||||
name="title"
|
||||
class="admin__control-text"
|
||||
value="<?= $block->escapeHtmlAttr($block->getTitleFilter()) ?>"
|
||||
placeholder="<?= $block->escapeHtmlAttr(__('Filter by title')) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field" style="margin:0;min-width:18rem">
|
||||
<label class="admin__field-label" for="esun-video-filter-status" style="float:none;width:auto;text-align:left">
|
||||
<span><?= $block->escapeHtml(__('Status')) ?></span>
|
||||
</label>
|
||||
<div class="admin__field-control" style="float:none;width:auto">
|
||||
<select id="esun-video-filter-status" name="status" class="admin__control-select">
|
||||
<option value=""><?= $block->escapeHtml(__('All Statuses')) ?></option>
|
||||
<option value="1" <?= $block->getStatusFilter() === '1' ? 'selected' : '' ?>>
|
||||
<?= $block->escapeHtml(__('Enabled')) ?>
|
||||
</option>
|
||||
<option value="0" <?= $block->getStatusFilter() === '0' ? 'selected' : '' ?>>
|
||||
<?= $block->escapeHtml(__('Disabled')) ?>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;gap:1rem">
|
||||
<button type="submit" class="action-secondary">
|
||||
<span><?= $block->escapeHtml(__('Filter')) ?></span>
|
||||
</button>
|
||||
<a class="action-secondary" href="<?= $block->escapeUrl($block->getFilterUrl()) ?>">
|
||||
<span><?= $block->escapeHtml(__('Reset')) ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="esun-video-management-upload"
|
||||
data-options="<?= $block->escapeHtmlAttr($block->getUploadOptionsJson()) ?>"
|
||||
hidden>
|
||||
<form class="admin__fieldset" data-role="video-upload-form">
|
||||
<div class="admin__field _required">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Title')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input type="text" class="admin__control-text" name="title" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Description')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<textarea class="admin__control-textarea" name="description"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field _required">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('MP4 Video')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input type="file" name="video" accept="video/mp4,.mp4" required>
|
||||
<div style="margin-top: 1rem;">
|
||||
<progress data-role="upload-progress" max="100" value="0" hidden
|
||||
style="width: 100%;"></progress>
|
||||
<div data-role="upload-status"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Cover Image')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<input type="file"
|
||||
name="cover"
|
||||
accept="image/jpeg,image/png,image/gif"
|
||||
data-role="cover-image-input">
|
||||
<p class="note" data-role="cover-image-empty-note">
|
||||
<?= $block->escapeHtml(__('The system will use the video frame at the 1-second mark if left empty.')) ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin__field">
|
||||
<label class="admin__field-label"><span><?= $block->escapeHtml(__('Status')) ?></span></label>
|
||||
<div class="admin__field-control">
|
||||
<select class="admin__control-select" name="status">
|
||||
<option value="1"><?= $block->escapeHtml(__('Enabled')) ?></option>
|
||||
<option value="0"><?= $block->escapeHtml(__('Disabled')) ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin__data-grid-wrap">
|
||||
<table class="data-grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('ID')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Cover')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Title')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Description')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Status')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Duration')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Size')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Dimensions')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Resolution')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Created')) ?></th>
|
||||
<th class="data-grid-th"><?= $block->escapeHtml(__('Action')) ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $videos = $block->getVideos(); ?>
|
||||
<?php if ($videos->getSize() === 0): ?>
|
||||
<tr>
|
||||
<td colspan="11" class="empty-text">
|
||||
<?= $block->escapeHtml(__('No videos have been uploaded yet.')) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($videos as $video): ?>
|
||||
<tr>
|
||||
<td><?= (int)$video->getId() ?></td>
|
||||
<td><img src="<?= $block->escapeUrl($block->getMediaUrl((string)$video->getData('cover_path'))) ?>"
|
||||
alt="" width="100"></td>
|
||||
<td>
|
||||
<a href="<?= $block->escapeUrl($block->getMediaUrl((string)$video->getData('video_path'))) ?>"
|
||||
target="_blank" rel="noopener"><?= $block->escapeHtml($video->getData('title')) ?></a>
|
||||
</td>
|
||||
<td style="max-width:32rem;white-space:normal;overflow-wrap:anywhere"
|
||||
title="<?= $block->escapeHtmlAttr((string)$video->getData('description')) ?>">
|
||||
<?= $block->escapeHtml((string)$video->getData('description')) ?>
|
||||
</td>
|
||||
<td><?= $video->getData('status') ? $block->escapeHtml(__('Enabled')) : $block->escapeHtml(__('Disabled')) ?></td>
|
||||
<td><?= $block->escapeHtml(number_format((float)$video->getData('duration'), 2)) ?>s</td>
|
||||
<td><?= $block->escapeHtml(number_format((int)$video->getData('size') / 1048576, 2)) ?> MB</td>
|
||||
<td><?= (int)$video->getData('width') ?> × <?= (int)$video->getData('height') ?></td>
|
||||
<td><?= $block->escapeHtml($video->getData('resolution')) ?></td>
|
||||
<td><?= $block->escapeHtml($video->getData('created_at')) ?></td>
|
||||
<td>
|
||||
<a href="<?= $block->escapeUrl($block->getEditUrl((int)$video->getId())) ?>">
|
||||
<?= $block->escapeHtml(__('Edit')) ?>
|
||||
</a>
|
||||
<span aria-hidden="true"> | </span>
|
||||
<a href="<?= $block->escapeUrl($block->getDeleteUrl((int)$video->getId())) ?>"
|
||||
onclick="return confirm('<?= $block->escapeJs(__('Delete this video?')) ?>')">
|
||||
<?= $block->escapeHtml(__('Delete')) ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
"#esun-video-management-upload": {
|
||||
"Esun_Video/js/video-management-upload": {}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
|
||||
<htmlContent name="gallery" sortOrder="22">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="wrapper" xsi:type="array">
|
||||
<item name="label" xsi:type="string" translate="true">Images And Videos</item>
|
||||
<item name="collapsible" xsi:type="boolean">true</item>
|
||||
<item name="opened" xsi:type="boolean">false</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<wrapper>
|
||||
<canShow>true</canShow>
|
||||
<componentType>fieldset</componentType>
|
||||
</wrapper>
|
||||
</settings>
|
||||
<block name="gallery" class="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery">
|
||||
<arguments>
|
||||
<argument name="config" xsi:type="array">
|
||||
<item name="label" xsi:type="string" translate="true">Images And Videos</item>
|
||||
<item name="collapsible" xsi:type="boolean">true</item>
|
||||
<item name="opened" xsi:type="boolean">false</item>
|
||||
<item name="sortOrder" xsi:type="string">22</item>
|
||||
<item name="canShow" xsi:type="boolean">true</item>
|
||||
<item name="componentType" xsi:type="string">fieldset</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
<block class="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content" as="content">
|
||||
<arguments>
|
||||
<argument name="config" xsi:type="array">
|
||||
<item name="parentComponent" xsi:type="string">product_form.product_form.block_gallery.block_gallery</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
<block class="Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo"
|
||||
name="new-video"
|
||||
template="Esun_Video::product/edit/slideout/form.phtml">
|
||||
<block class="Esun\Video\Block\Adminhtml\Product\Upload"
|
||||
name="esun-video-upload"
|
||||
as="esun-video-upload"
|
||||
template="Esun_Video::product/upload.phtml"/>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</htmlContent>
|
||||
</form>
|
||||
@@ -0,0 +1,122 @@
|
||||
define([
|
||||
'jquery',
|
||||
'Esun_Video/js/product-video-id-upload'
|
||||
], function ($, initProductVideoUpload) {
|
||||
'use strict';
|
||||
|
||||
return function (Widget) {
|
||||
return $.widget('mage.newVideoDialog', Widget, {
|
||||
/**
|
||||
* HtmlContent can be inserted after Magento's data-mage-init scan,
|
||||
* so initialize managed-video controls when the native dialog exists.
|
||||
*/
|
||||
_create: function () {
|
||||
var integration;
|
||||
|
||||
this._super();
|
||||
integration = this.element.find('#esun-product-video-integration');
|
||||
if (integration.length) {
|
||||
initProductVideoUpload({}, integration.get(0));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Managed MP4 videos do not require YouTube/Vimeo metadata lookup.
|
||||
*/
|
||||
_onGetVideoInformationEditClick: function () {
|
||||
if (this._isHtml5Video()) {
|
||||
this._videoRequestComplete = true;
|
||||
this._renderHtml5Preview();
|
||||
return;
|
||||
}
|
||||
this._super();
|
||||
},
|
||||
|
||||
/**
|
||||
* Prevent focus-out validation of an existing managed MP4 URL.
|
||||
*/
|
||||
_onGetVideoInformationFocusOut: function () {
|
||||
if (this._isHtml5Video()) {
|
||||
this._videoRequestComplete = true;
|
||||
return;
|
||||
}
|
||||
this._super();
|
||||
},
|
||||
|
||||
/**
|
||||
* Keep native form validation, but skip provider URL validation for MP4.
|
||||
*
|
||||
* @param {Function} callback
|
||||
*/
|
||||
isValid: function (callback) {
|
||||
var videoForm;
|
||||
|
||||
if (!this._isHtml5Video()) {
|
||||
this._super(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
videoForm = this.element.find(this._videoFormSelector);
|
||||
this._blockActionButtons(true);
|
||||
videoForm.mage('validation', {
|
||||
errorPlacement: function (error, input) {
|
||||
error.insertAfter(input);
|
||||
}
|
||||
});
|
||||
videoForm.validation();
|
||||
this._videoRequestComplete = true;
|
||||
callback(videoForm.valid());
|
||||
this._blockActionButtons(false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Render an HTML5 preview when opening a managed MP4 gallery item.
|
||||
*/
|
||||
_onOpenDialog: function (event, imageData) {
|
||||
this._super(event, imageData);
|
||||
if (imageData && (
|
||||
imageData.video_provider === 'html5' ||
|
||||
/\.mp4(?:$|\?)/i.test(imageData.video_url || '')
|
||||
)) {
|
||||
this._videoRequestComplete = true;
|
||||
this._renderHtml5Preview(imageData.video_url);
|
||||
}
|
||||
},
|
||||
|
||||
_isHtml5Video: function () {
|
||||
var provider = this.element.find('[name="video_provider"]').val(),
|
||||
url = this.element.find(this._videoUrlSelector).val();
|
||||
|
||||
return provider === 'html5' || /\.mp4(?:$|\?)/i.test(url || '');
|
||||
},
|
||||
|
||||
_renderHtml5Preview: function (url) {
|
||||
var container = this.element.find('.video-player-container'),
|
||||
metadata;
|
||||
|
||||
url = url || this.element.find(this._videoUrlSelector).val();
|
||||
container.empty();
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('<video controls preload="metadata" playsinline></video>')
|
||||
.attr('src', url)
|
||||
.css({width: '100%', maxHeight: '360px'})
|
||||
.appendTo(container);
|
||||
|
||||
try {
|
||||
metadata = JSON.parse(this.element.find('[name="video_metadata"]').val() || '{}');
|
||||
} catch (error) {
|
||||
metadata = {};
|
||||
}
|
||||
this.element.find('.video-information.title span')
|
||||
.text(this.element.find('[name="video_title"]').val());
|
||||
this.element.find('.video-information.duration span')
|
||||
.text(metadata.duration ? metadata.duration + 's' : '');
|
||||
this.element.find('.video-information.uploaded, .video-information.uploader').hide();
|
||||
this.element.find('.video-information.title, .video-information.duration').show();
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,210 @@
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/modal/modal',
|
||||
'mage/translate'
|
||||
], function ($, modal) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $element = $(element),
|
||||
options = $element.data('options'),
|
||||
$dialog = $element.find('[data-role="mp4-upload-dialog"]'),
|
||||
$form = $element.find('[data-role="esun-video-form"]'),
|
||||
$progress = $element.find('[data-role="progress"]'),
|
||||
$openUpload = $element.find('[data-role="open-mp4-upload"]'),
|
||||
$coverInput = $element.find('[data-role="cover-image-input"]'),
|
||||
$coverNote = $element.find('[data-role="cover-image-empty-note"]'),
|
||||
$libraryId = $element.find('[data-role="esun-video-id-input-v2"]'),
|
||||
$addLibraryVideo = $element.find('[data-role="esun-add-video-by-id-v2"]'),
|
||||
libraryItems = {},
|
||||
modalOptions;
|
||||
|
||||
if ($element.data('esunVideoInitialized')) {
|
||||
return;
|
||||
}
|
||||
$element.data('esunVideoInitialized', true);
|
||||
|
||||
if (!options.enabled) {
|
||||
$openUpload.prop('disabled', true)
|
||||
.attr('title', $.mage.__('Video upload is disabled in configuration.'));
|
||||
}
|
||||
|
||||
setLibraryItems(options.libraryItems || []);
|
||||
|
||||
$coverInput.on('change', function () {
|
||||
$coverNote.toggle(!(this.files && this.files.length));
|
||||
});
|
||||
|
||||
$libraryId.on('keydown', function (event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
addLibraryVideo();
|
||||
}
|
||||
});
|
||||
|
||||
modalOptions = {
|
||||
type: 'slide',
|
||||
title: $.mage.__('Upload MP4 Video'),
|
||||
buttons: [{
|
||||
text: $.mage.__('Upload and Add'),
|
||||
class: 'action-primary',
|
||||
click: upload
|
||||
}, {
|
||||
text: $.mage.__('Cancel'),
|
||||
click: function () {
|
||||
$dialog.modal('closeModal');
|
||||
}
|
||||
}]
|
||||
};
|
||||
modal(modalOptions, $dialog);
|
||||
|
||||
$openUpload.on('click', function () {
|
||||
if (!options.enabled) {
|
||||
return;
|
||||
}
|
||||
$dialog.modal('openModal');
|
||||
});
|
||||
|
||||
$addLibraryVideo.on('click', addLibraryVideo);
|
||||
|
||||
function addLibraryVideo() {
|
||||
var selectedId = $.trim($libraryId.val()),
|
||||
item;
|
||||
|
||||
if (!/^[1-9]\d*$/.test(selectedId)) {
|
||||
alert($.mage.__('Please enter a valid video ID.'));
|
||||
return;
|
||||
}
|
||||
item = libraryItems[selectedId];
|
||||
if (!item) {
|
||||
$.getJSON(options.libraryUrl).done(function (response) {
|
||||
setLibraryItems(response.items || []);
|
||||
addLibraryItem(selectedId);
|
||||
}).fail(function () {
|
||||
alert($.mage.__('Unable to load the video library.'));
|
||||
});
|
||||
return;
|
||||
}
|
||||
addLibraryItem(selectedId);
|
||||
}
|
||||
|
||||
function addLibraryItem(selectedId) {
|
||||
var item = libraryItems[selectedId];
|
||||
|
||||
if (!item) {
|
||||
alert($.mage.__('No enabled video was found for this ID.'));
|
||||
return;
|
||||
}
|
||||
item.metadata = {
|
||||
duration: item.duration,
|
||||
size: item.size,
|
||||
width: item.width,
|
||||
height: item.height,
|
||||
resolution: item.resolution
|
||||
};
|
||||
item.disabled = 0;
|
||||
addToGallery(item);
|
||||
closeDialogs();
|
||||
$libraryId.val('');
|
||||
}
|
||||
|
||||
function setLibraryItems(items) {
|
||||
libraryItems = {};
|
||||
$.each(items, function (index, item) {
|
||||
libraryItems[String(item.id)] = item;
|
||||
});
|
||||
}
|
||||
|
||||
function upload() {
|
||||
var title = $.trim($form.find('[name="title"]').val()),
|
||||
file = $form.find('[name="video"]')[0].files[0],
|
||||
cover = $form.find('[name="cover"]')[0].files[0],
|
||||
uploadId = Date.now().toString(36) + Math.random().toString(36).slice(2),
|
||||
total,
|
||||
index = 0;
|
||||
|
||||
if (!title || !file) {
|
||||
alert($.mage.__('Title and MP4 video are required.'));
|
||||
return;
|
||||
}
|
||||
if (!/\.mp4$/i.test(file.name) || (file.type && file.type !== 'video/mp4')) {
|
||||
alert($.mage.__('Only MP4 video files are supported.'));
|
||||
return;
|
||||
}
|
||||
total = Math.ceil(file.size / options.chunkSize);
|
||||
$progress.attr('hidden', false).val(0);
|
||||
sendNext();
|
||||
|
||||
function sendNext() {
|
||||
var start = index * options.chunkSize,
|
||||
data = new FormData();
|
||||
data.append('form_key', window.FORM_KEY);
|
||||
data.append('upload_id', uploadId);
|
||||
data.append('index', index);
|
||||
data.append('total', total);
|
||||
data.append('name', file.name);
|
||||
data.append('title', title);
|
||||
data.append('description', $form.find('[name="description"]').val());
|
||||
data.append('status', $form.find('[name="status"]').val());
|
||||
data.append('chunk', file.slice(start, Math.min(start + options.chunkSize, file.size)), file.name);
|
||||
if (cover && index + 1 === total) {
|
||||
data.append('cover', cover, cover.name);
|
||||
}
|
||||
$.ajax({
|
||||
url: options.uploadUrl,
|
||||
method: 'POST',
|
||||
data: data,
|
||||
processData: false,
|
||||
contentType: false
|
||||
}).done(function (response) {
|
||||
index++;
|
||||
$progress.val(Math.round(index / total * 100));
|
||||
if (!response.completed) {
|
||||
sendNext();
|
||||
return;
|
||||
}
|
||||
addToGallery(response.video);
|
||||
closeDialogs();
|
||||
$form[0].reset();
|
||||
$progress.attr('hidden', true).val(0);
|
||||
}).fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
alert(response.message || $.mage.__('Video upload failed.'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function addToGallery(video) {
|
||||
var widget = $('#new-video').data('mageNewVideoDialog'),
|
||||
metadata = $.extend({esun_video_id: video.id}, video.metadata),
|
||||
imageData = {
|
||||
file: video.gallery_file,
|
||||
file_id: 'esun_video_' + video.id,
|
||||
value_id: '',
|
||||
label: video.title,
|
||||
position: 0,
|
||||
disabled: video.disabled,
|
||||
removed: '',
|
||||
url: video.cover_url,
|
||||
media_type: 'external-video',
|
||||
video_provider: 'html5',
|
||||
video_url: video.video_url,
|
||||
video_title: video.title,
|
||||
video_description: video.description,
|
||||
video_metadata: JSON.stringify(metadata),
|
||||
sizeLabel: ''
|
||||
};
|
||||
|
||||
if (!widget || typeof widget._setImage !== 'function') {
|
||||
alert($.mage.__('The video was uploaded, but the product gallery could not be updated. Reload the page and select it from Video Management.'));
|
||||
return;
|
||||
}
|
||||
widget._setImage(imageData.file, imageData);
|
||||
}
|
||||
|
||||
function closeDialogs() {
|
||||
$dialog.modal('closeModal');
|
||||
$('#new-video').modal('closeModal');
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/modal/modal',
|
||||
'mage/translate'
|
||||
], function ($, modal) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $element = $(element),
|
||||
options = $element.data('options'),
|
||||
$form = $element.find('[data-role="video-upload-form"]'),
|
||||
$progress = $element.find('[data-role="upload-progress"]'),
|
||||
$status = $element.find('[data-role="upload-status"]'),
|
||||
$coverInput = $element.find('[data-role="cover-image-input"]'),
|
||||
$coverNote = $element.find('[data-role="cover-image-empty-note"]'),
|
||||
uploading = false;
|
||||
|
||||
$coverInput.on('change', function () {
|
||||
$coverNote.toggle(!(this.files && this.files.length));
|
||||
});
|
||||
|
||||
modal({
|
||||
type: 'slide',
|
||||
title: $.mage.__('Upload Video'),
|
||||
buttons: [{
|
||||
text: $.mage.__('Upload'),
|
||||
class: 'action-primary',
|
||||
click: upload
|
||||
}, {
|
||||
text: $.mage.__('Cancel'),
|
||||
click: function () {
|
||||
if (!uploading) {
|
||||
$element.modal('closeModal');
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, $element);
|
||||
|
||||
$('[data-role="open-video-upload"]').on('click', function () {
|
||||
if (!options.enabled) {
|
||||
alert($.mage.__('Video upload is disabled in configuration.'));
|
||||
return;
|
||||
}
|
||||
$element.modal('openModal');
|
||||
});
|
||||
|
||||
function upload() {
|
||||
var title = $.trim($form.find('[name="title"]').val()),
|
||||
fileInput = $form.find('[name="video"]')[0],
|
||||
coverInput = $form.find('[name="cover"]')[0],
|
||||
file = fileInput.files[0],
|
||||
cover = coverInput.files[0],
|
||||
uploadId,
|
||||
total,
|
||||
index = 0;
|
||||
|
||||
if (uploading) {
|
||||
return;
|
||||
}
|
||||
if (!title || !file) {
|
||||
alert($.mage.__('Title and MP4 video are required.'));
|
||||
return;
|
||||
}
|
||||
if (!/\.mp4$/i.test(file.name) || (file.type && file.type !== 'video/mp4')) {
|
||||
alert($.mage.__('Only MP4 video files are supported.'));
|
||||
return;
|
||||
}
|
||||
|
||||
uploading = true;
|
||||
uploadId = Date.now().toString(36) + Math.random().toString(36).slice(2);
|
||||
total = Math.ceil(file.size / options.chunkSize);
|
||||
$progress.attr('hidden', false).val(0);
|
||||
$status.text($.mage.__('Uploading...'));
|
||||
sendNext();
|
||||
|
||||
function sendNext() {
|
||||
var start = index * options.chunkSize,
|
||||
data = new FormData();
|
||||
|
||||
data.append('form_key', window.FORM_KEY);
|
||||
data.append('upload_id', uploadId);
|
||||
data.append('index', index);
|
||||
data.append('total', total);
|
||||
data.append('name', file.name);
|
||||
data.append('title', title);
|
||||
data.append('description', $form.find('[name="description"]').val());
|
||||
data.append('status', $form.find('[name="status"]').val());
|
||||
data.append(
|
||||
'chunk',
|
||||
file.slice(start, Math.min(start + options.chunkSize, file.size)),
|
||||
file.name
|
||||
);
|
||||
if (cover && index + 1 === total) {
|
||||
data.append('cover', cover, cover.name);
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: options.uploadUrl,
|
||||
method: 'POST',
|
||||
data: data,
|
||||
processData: false,
|
||||
contentType: false
|
||||
}).done(function (response) {
|
||||
index++;
|
||||
$progress.val(Math.round(index / total * 100));
|
||||
if (!response.completed) {
|
||||
sendNext();
|
||||
return;
|
||||
}
|
||||
$status.text($.mage.__('Upload completed. Refreshing...'));
|
||||
window.location.replace(options.indexUrl);
|
||||
}).fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
uploading = false;
|
||||
$status.text(response.message || $.mage.__('Video upload failed.'));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user