init
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?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\FileManager\Block\Adminhtml\Upload" name="esun.filemanager.upload"
|
||||
template="Esun_FileManager::upload.phtml" before="-">
|
||||
<arguments>
|
||||
<argument name="view_model" xsi:type="object">Esun\FileManager\ViewModel\Config</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
<uiComponent name="esun_filemanager_file_listing"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Esun\FileManager\Block\Adminhtml\Upload $block
|
||||
* @var \Magento\Framework\Escaper $escaper
|
||||
* @var \Esun\FileManager\ViewModel\Config $viewModel
|
||||
*/
|
||||
$viewModel = $block->getData('view_model');
|
||||
?>
|
||||
<div class="vendor-filemanager-upload" data-role="filemanager-upload">
|
||||
<?php if (!$viewModel->isEnabled()): ?>
|
||||
<div class="message message-warning">
|
||||
<?= $escaper->escapeHtml(__('File Manager is disabled in Stores > Configuration > General > File Manager.')) ?>
|
||||
</div>
|
||||
<?php elseif ($block->canUpload()): ?>
|
||||
<form action="<?= $escaper->escapeUrl($block->getUploadUrl()) ?>"
|
||||
method="post" enctype="multipart/form-data" data-role="upload-form">
|
||||
<?= $block->getBlockHtml('formkey') ?>
|
||||
<input type="file" name="files[]" multiple required
|
||||
accept="<?= $escaper->escapeHtmlAttr('.' . str_replace(', ', ',.', $viewModel->getAllowedExtensions())) ?>"/>
|
||||
<button type="submit" class="action-primary">
|
||||
<span><?= $escaper->escapeHtml(__('Upload Files')) ?></span>
|
||||
</button>
|
||||
<span class="note">
|
||||
<?= $escaper->escapeHtml(
|
||||
__('Maximum: %1 MB. Formats: %2', $viewModel->getMaximumFileSizeMb(), $viewModel->getAllowedExtensions())
|
||||
) ?>
|
||||
</span>
|
||||
<div data-role="upload-progress" hidden>
|
||||
<progress data-role="upload-progress-bar" max="100" value="0"></progress>
|
||||
<span data-role="upload-progress-label">0%</span>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php if ($viewModel->isEnabled()): ?>
|
||||
<div class="message message-info">
|
||||
<strong><?= $escaper->escapeHtml(__('Page Builder Usage')) ?></strong>
|
||||
<div>
|
||||
<?= $escaper->escapeHtml(
|
||||
__('Copy the Media Directive from the grid and use it in a Page Builder HTML Code block.')
|
||||
) ?>
|
||||
</div>
|
||||
<div>
|
||||
<code><?= $escaper->escapeHtml(
|
||||
'<a href=\'{{media url="uploads/YYYY/MM/file.pdf"}}\'>Download attachment</a>'
|
||||
) ?></code>
|
||||
</div>
|
||||
<div>
|
||||
<code><?= $escaper->escapeHtml(
|
||||
'<img src=\'{{media url="uploads/YYYY/MM/image.jpg"}}\' alt="">'
|
||||
) ?></code>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($viewModel->isEnabled() && $block->canUpload()): ?>
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
"[data-role=filemanager-upload]": {
|
||||
"Esun_FileManager/js/upload": {}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0"?>
|
||||
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="js_config" xsi:type="array">
|
||||
<item name="provider" xsi:type="string">esun_filemanager_file_listing.esun_filemanager_file_listing_data_source</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<spinner>esun_filemanager_file_columns</spinner>
|
||||
<deps>
|
||||
<dep>esun_filemanager_file_listing.esun_filemanager_file_listing_data_source</dep>
|
||||
</deps>
|
||||
</settings>
|
||||
<dataSource name="esun_filemanager_file_listing_data_source" component="Magento_Ui/js/grid/provider">
|
||||
<settings>
|
||||
<storageConfig>
|
||||
<param name="indexField" xsi:type="string">id</param>
|
||||
</storageConfig>
|
||||
<updateUrl path="mui/index/render"/>
|
||||
</settings>
|
||||
<aclResource>Esun_FileManager::filemanager</aclResource>
|
||||
<dataProvider class="Esun\FileManager\Ui\DataProvider\File\ListingDataProvider"
|
||||
name="esun_filemanager_file_listing_data_source">
|
||||
<settings>
|
||||
<requestFieldName>id</requestFieldName>
|
||||
<primaryFieldName>id</primaryFieldName>
|
||||
</settings>
|
||||
</dataProvider>
|
||||
</dataSource>
|
||||
<listingToolbar name="listing_top">
|
||||
<settings>
|
||||
<sticky>true</sticky>
|
||||
</settings>
|
||||
<bookmark name="bookmarks"/>
|
||||
<columnsControls name="columns_controls"/>
|
||||
<filterSearch name="fulltext">
|
||||
<settings>
|
||||
<placeholder translate="true">Search file name</placeholder>
|
||||
</settings>
|
||||
</filterSearch>
|
||||
<filters name="listing_filters"/>
|
||||
<paging name="listing_paging">
|
||||
<settings>
|
||||
<options>
|
||||
<option name="20" xsi:type="array">
|
||||
<item name="value" xsi:type="number">20</item>
|
||||
<item name="label" xsi:type="string">20</item>
|
||||
</option>
|
||||
<option name="50" xsi:type="array">
|
||||
<item name="value" xsi:type="number">50</item>
|
||||
<item name="label" xsi:type="string">50</item>
|
||||
</option>
|
||||
<option name="100" xsi:type="array">
|
||||
<item name="value" xsi:type="number">100</item>
|
||||
<item name="label" xsi:type="string">100</item>
|
||||
</option>
|
||||
</options>
|
||||
<pageSize>20</pageSize>
|
||||
</settings>
|
||||
</paging>
|
||||
</listingToolbar>
|
||||
<columns name="esun_filemanager_file_columns">
|
||||
<column name="filename">
|
||||
<settings>
|
||||
<filter>text</filter>
|
||||
<label translate="true">File Name</label>
|
||||
</settings>
|
||||
</column>
|
||||
<column name="extension" component="Magento_Ui/js/grid/columns/select">
|
||||
<settings>
|
||||
<options class="Esun\FileManager\Model\Source\ExtensionOptions"/>
|
||||
<filter>select</filter>
|
||||
<dataType>select</dataType>
|
||||
<label translate="true">Type</label>
|
||||
</settings>
|
||||
</column>
|
||||
<column name="size" class="Esun\FileManager\Ui\Component\Listing\Column\Size">
|
||||
<settings>
|
||||
<filter>false</filter>
|
||||
<label translate="true">Size</label>
|
||||
</settings>
|
||||
</column>
|
||||
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date"
|
||||
component="Magento_Ui/js/grid/columns/date">
|
||||
<settings>
|
||||
<filter>dateRange</filter>
|
||||
<dataType>date</dataType>
|
||||
<sorting>desc</sorting>
|
||||
<label translate="true">Uploaded At</label>
|
||||
</settings>
|
||||
</column>
|
||||
<column name="url">
|
||||
<settings>
|
||||
<filter>false</filter>
|
||||
<sortable>false</sortable>
|
||||
<label translate="true">URL</label>
|
||||
</settings>
|
||||
</column>
|
||||
<column name="media_directive">
|
||||
<settings>
|
||||
<filter>false</filter>
|
||||
<sortable>false</sortable>
|
||||
<label translate="true">Media Directive</label>
|
||||
</settings>
|
||||
</column>
|
||||
<actionsColumn name="actions" class="Esun\FileManager\Ui\Component\Listing\Column\Actions"
|
||||
component="Esun_FileManager/js/grid/columns/actions">
|
||||
<settings>
|
||||
<indexField>id</indexField>
|
||||
<resizeEnabled>false</resizeEnabled>
|
||||
<resizeDefaultWidth>170</resizeDefaultWidth>
|
||||
</settings>
|
||||
</actionsColumn>
|
||||
</columns>
|
||||
</listing>
|
||||
@@ -0,0 +1,58 @@
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/grid/columns/actions',
|
||||
'mage/translate',
|
||||
'mage/backend/notification'
|
||||
], function ($, Actions) {
|
||||
'use strict';
|
||||
|
||||
function notify(message, isError) {
|
||||
$('body').notification('clear').notification('add', {
|
||||
error: isError,
|
||||
message: message,
|
||||
insertMethod: function (renderedMessage) {
|
||||
$('.page-main-actions').after(renderedMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fallbackCopy(value) {
|
||||
var input = $('<textarea>')
|
||||
.css({position: 'fixed', opacity: 0})
|
||||
.val(value)
|
||||
.appendTo('body');
|
||||
|
||||
input[0].select();
|
||||
document.execCommand('copy');
|
||||
input.remove();
|
||||
}
|
||||
|
||||
return Actions.extend({
|
||||
defaultCallback: function (actionIndex, recordId, action) {
|
||||
var promise;
|
||||
|
||||
if (actionIndex !== 'copy') {
|
||||
return this._super(actionIndex, recordId, action);
|
||||
}
|
||||
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
promise = navigator.clipboard.writeText(action.url);
|
||||
promise.then(function () {
|
||||
notify($.mage.__('URL copied successfully.'), false);
|
||||
}).catch(function () {
|
||||
fallbackCopy(action.url);
|
||||
notify($.mage.__('URL copied successfully.'), false);
|
||||
});
|
||||
} else {
|
||||
fallbackCopy(action.url);
|
||||
notify($.mage.__('URL copied successfully.'), false);
|
||||
}
|
||||
} catch (error) {
|
||||
notify($.mage.__('The URL could not be copied.'), true);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
define([
|
||||
'jquery',
|
||||
'uiRegistry',
|
||||
'mage/translate',
|
||||
'mage/backend/notification'
|
||||
], function ($, registry) {
|
||||
'use strict';
|
||||
|
||||
function notify(message, isError) {
|
||||
$('body').notification('add', {
|
||||
error: isError,
|
||||
message: message,
|
||||
insertMethod: function (renderedMessage) {
|
||||
$('.page-main-actions').after(renderedMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return function (config, element) {
|
||||
var $container = $(element),
|
||||
$form = $container.find('[data-role=upload-form]'),
|
||||
$button = $form.find('button[type=submit]'),
|
||||
$progress = $form.find('[data-role=upload-progress]'),
|
||||
$progressBar = $form.find('[data-role=upload-progress-bar]'),
|
||||
$progressLabel = $form.find('[data-role=upload-progress-label]');
|
||||
|
||||
function setProgress(percent) {
|
||||
$progressBar.val(percent);
|
||||
$progressLabel.text(percent + '%');
|
||||
}
|
||||
|
||||
$form.on('submit', function (event) {
|
||||
var data;
|
||||
|
||||
event.preventDefault();
|
||||
if (!$form.find('input[type=file]')[0].files.length) {
|
||||
notify($.mage.__('Please select at least one file.'), true);
|
||||
return;
|
||||
}
|
||||
|
||||
data = new FormData($form[0]);
|
||||
$button.prop('disabled', true);
|
||||
setProgress(0);
|
||||
$progress.prop('hidden', false);
|
||||
$.ajax({
|
||||
url: $form.attr('action'),
|
||||
method: 'POST',
|
||||
data: data,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
dataType: 'json',
|
||||
xhr: function () {
|
||||
var xhr = $.ajaxSettings.xhr();
|
||||
|
||||
if (xhr.upload) {
|
||||
xhr.upload.addEventListener('progress', function (progressEvent) {
|
||||
if (progressEvent.lengthComputable) {
|
||||
setProgress(Math.round(
|
||||
progressEvent.loaded / progressEvent.total * 100
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return xhr;
|
||||
}
|
||||
}).done(function (response) {
|
||||
setProgress(100);
|
||||
if (response.ajaxExpired && response.ajaxRedirect) {
|
||||
window.location.href = response.ajaxRedirect;
|
||||
return;
|
||||
}
|
||||
$('body').notification('clear');
|
||||
if (response.message) {
|
||||
notify(response.message, response.error);
|
||||
}
|
||||
$.each(response.errors || [], function (index, message) {
|
||||
notify(message, true);
|
||||
});
|
||||
if ((response.files || []).length) {
|
||||
$form[0].reset();
|
||||
registry.async(
|
||||
'esun_filemanager_file_listing.esun_filemanager_file_listing_data_source'
|
||||
)(function (provider) {
|
||||
provider.reload({refresh: true});
|
||||
});
|
||||
}
|
||||
}).fail(function () {
|
||||
notify($.mage.__('The upload request failed.'), true);
|
||||
}).always(function () {
|
||||
$button.prop('disabled', false);
|
||||
$progress.prop('hidden', true);
|
||||
setProgress(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user