Skip to content

Commit

Permalink
Improve button visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar65 committed Aug 28, 2020
1 parent dd9bdda commit 989139f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 27 deletions.
Expand Up @@ -36,15 +36,17 @@ public function __construct(
*/
public function getButtonData()
{
if (!$this->authorization->isAllowed(self::ACL_CREATE_FOLDER)) {
return [];
}

return [
$buttonData = [
'label' => __('Create Folder'),
'on_click' => 'jQuery("#create_folder").trigger("create_folder");',
'class' => 'action-default scalable add media-gallery-actions-buttons',
'sort_order' => 10,
];

if (!$this->authorization->isAllowed(self::ACL_CREATE_FOLDER)) {
$buttonData['disabled'] = 'disabled';
}

return $buttonData;
}
}
Expand Up @@ -34,17 +34,19 @@ public function __construct(
/**
* @return array
*/
public function getButtonData()
public function getButtonData(): array
{
if (!$this->authorization->isAllowed(self::ACL_DELETE_ASSETS)) {
return [];
}

return [
$buttonData = [
'label' => __('Delete Images...'),
'on_click' => 'jQuery(window).trigger("massAction.MediaGallery")',
'class' => 'action-default scalable add media-gallery-actions-buttons',
'sort_order' => 50,
];

if (!$this->authorization->isAllowed(self::ACL_DELETE_ASSETS)) {
$buttonData['disabled'] = 'disabled';
}

return $buttonData;
}
}
Expand Up @@ -36,16 +36,17 @@ public function __construct(
*/
public function getButtonData()
{
if (!$this->authorization->isAllowed(self::ACL_DELETE_FOLDER)) {
return [];
}

return [
$buttonData = [
'label' => __('Delete Folder'),
'disabled' => 'disabled',
'on_click' => 'jQuery("#delete_folder").trigger("delete_folder");',
'class' => 'action-default scalable add media-gallery-actions-buttons',
'sort_order' => 30,
];
if (!$this->authorization->isAllowed(self::ACL_DELETE_FOLDER)) {
$buttonData['disabled'] = 'disabled';
}

return $buttonData;
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\MediaGalleryUi\Ui\Component\Control;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Framework\AuthorizationInterface;

/**
* Add selected button
*/
class InsertAsstes implements ButtonProviderInterface
{
private const ACL_INSERT_ASSETS = 'Magento_MediaGallery::insert_assets';

/**
* @var AuthorizationInterface
*/
private $authorization;

/**
* Constructor.
*
* @param AuthorizationInterface $authorization
*/
public function __construct(
AuthorizationInterface $authorization
) {
$this->authorization = $authorization;
}

/**
* @inheritdoc
*/
public function getButtonData()
{
$buttonData = [
'label' => __('Add Selected'),
'on_click' => 'return false;");',
'class' => 'action-primary no-display media-gallery-add-selected',
'sort_order' => 110,
];

if (!$this->authorization->isAllowed(self::ACL_INSERT_ASSETS)) {
$buttonData['disabled'] = 'disabled';
}

return $buttonData;
}
}
Expand Up @@ -36,16 +36,18 @@ public function __construct(
*/
public function getButtonData()
{
if (!$this->authorization->isAllowed(self::ACL_UPLOAD_ASSETS)) {
return [];
}

return [
$buttonData = [
'label' => __('Upload Image'),
'disabled' => 'disabled',
'on_click' => 'jQuery("#image-uploader-input").click();',
'class' => 'action-default scalable add media-gallery-actions-buttons',
'sort_order' => 20,
];

if (!$this->authorization->isAllowed(self::ACL_UPLOAD_ASSETS)) {
$buttonData['disabled'] = 'disabled';
}

return $buttonData;
}
}
Expand Up @@ -50,6 +50,7 @@ public function prepare(): void
array_replace_recursive(
(array) $this->getData('config'),
[
'allowedActions' => [],
'getDirectoryTreeUrl' => $this->url->getUrl("media_gallery/directories/gettree"),
'deleteDirectoryUrl' => $this->url->getUrl("media_gallery/directories/delete"),
'createDirectoryUrl' => $this->url->getUrl("media_gallery/directories/create")
Expand Down
Expand Up @@ -16,12 +16,7 @@
</argument>
<settings>
<buttons>
<button name="add_selected">
<param name="on_click" xsi:type="string">return false;</param>
<param name="sort_order" xsi:type="number">110</param>
<class>action-primary no-display media-gallery-add-selected</class>
<label translate="true">Add Selected</label>
</button>
<button name="add_selected" class="Magento\MediaGalleryUi\Ui\Component\Control\InsertAsstes"/>
<button name="cancel">
<param name="on_click" xsi:type="string">MediabrowserUtility.closeDialog();</param>
<param name="sort_order" xsi:type="number">1</param>
Expand Down
Expand Up @@ -179,6 +179,10 @@ define([
* @param {String} folderId
*/
setActive: function (folderId) {
if (!$.inArray('delete_folder', this.allowedActions)) {
return;
}

this.selectedFolder(folderId);
$(this.deleteButtonSelector).removeAttr('disabled').removeClass('disabled');
}
Expand Down
Expand Up @@ -16,6 +16,7 @@ define([

return Component.extend({
defaults: {
allowedActions: [],
deleteButtonSelector: '#delete_selected_massaction',
deleteImagesSelector: '#delete_massaction',
mediaGalleryImageDetailsName: 'mediaGalleryImageDetails',
Expand Down Expand Up @@ -106,6 +107,10 @@ define([
* If images records less than one, disable "delete images" button
*/
checkButtonVisibility: function () {
if (!$.inArray('delete_assets', this.allowedActions)) {
return;
}

if (this.imageItems.length < 1) {
$(this.deleteImagesSelector).addClass('disabled');
} else {
Expand Down

0 comments on commit 989139f

Please sign in to comment.