Skip to content

Commit

Permalink
magento-engcom/magento2#3: Source Management UI
Browse files Browse the repository at this point in the history
 - Minor refactoring
  • Loading branch information
ishakhsuvarov committed Jun 2, 2017
1 parent 74428b4 commit 01c9698
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 119 deletions.

This file was deleted.

24 changes: 21 additions & 3 deletions app/code/Magento/Inventory/Block/Adminhtml/Edit/Button/Back.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,38 @@
namespace Magento\Inventory\Block\Adminhtml\Edit\Button;

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

/**
* Class Back
* Configures "Back" button on the Source Management Edit form.
*/
class Back extends AbstractButton implements ButtonProviderInterface
class Back implements ButtonProviderInterface
{
/**
* @return array
* @var UrlInterface
*/
private $urlBuilder;

/**
* @param UrlInterface $urlBuilder
*/
public function __construct(
UrlInterface $urlBuilder
) {
$this->urlBuilder = $urlBuilder;
}

/**
* @inheritdoc
*/
public function getButtonData()
{
$backUrl = $this->urlBuilder->getUrl('*/*/');

return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')),
'on_click' => sprintf("location.href = '%s';", $backUrl),
'class' => 'back',
'sort_order' => 10
];
Expand Down
60 changes: 48 additions & 12 deletions app/code/Magento/Inventory/Block/Adminhtml/Edit/Button/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,73 @@
namespace Magento\Inventory\Block\Adminhtml\Edit\Button;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Backend\Block\Context;
use Magento\Framework\UrlInterface;

/**
* Class Delete
* Configures "Delete" button on the Source Management edit form.
*/
class Delete extends AbstractButton implements ButtonProviderInterface
class Delete implements ButtonProviderInterface
{
/**
* @return array
* @var UrlInterface
*/
private $urlBuilder;

/**
* @var Context
*/
private $context;

/**
* @var SourceRepositoryInterface
*/
private $sourceRepository;

/**
* @param UrlInterface $urlBuilder
* @param SourceRepositoryInterface $sourceRepository
* @param Context $context
*/
public function __construct(
UrlInterface $urlBuilder,
SourceRepositoryInterface $sourceRepository,
Context $context
) {
$this->urlBuilder = $urlBuilder;
$this->sourceRepository = $sourceRepository;
$this->context = $context;
}

/**
* @inheritdoc
*/
public function getButtonData()
{
$data = [];
if ($this->isEditMode()) {
// This part should be refactored. Implemented for test purposes.
try {
$sourceId = $this->context->getRequest()->getParam('id');
$sourceId = $this->sourceRepository->get($sourceId)->getSourceId();

} catch (NoSuchEntityException $exception) {
$sourceId = null;
}

if ((bool)$sourceId) {
$deleteUrl = $this->urlBuilder->getUrl('*/*/delete', ['id' => $sourceId]);
$data = [
'label' => __('Delete Entry'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . __(
'Are you sure you want to do this?'
) . '\', \'' . $this->getDeleteUrl() . '\')',
) . '\', \'' . $deleteUrl . '\')',
'sort_order' => 20,
];
}
return $data;
}

/**
* @return string
*/
private function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['id' => $this->getRateId()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
/**
* Class Save
*/
class Save extends AbstractButton implements ButtonProviderInterface
class Save implements ButtonProviderInterface
{
/**
* @return array
* @inheritdoc
*/
public function getButtonData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,50 @@
<item name="label" xsi:type="string"/>
</item>
</argument>
<field name="source_id">
<field name="source_id" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">storelocator_form_data_source</item>
<item name="dataScope" xsi:type="string">source_id</item>
</item>
</argument>
<settings>
<visible>false</visible>
<dataType>text</dataType>
<dataScope>source_id</dataScope>
</settings>
</field>
<field name="status">
<field name="status" sortOrder="10" formElement="select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">storelocator_form_data_source</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">status</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
<item name="validate-number" xsi:type="boolean">false</item>
<item name="validate-no-html-tags" xsi:type="boolean">true</item>
</item>
<item name="options" xsi:type="array">
<item name="0" xsi:type="array">
<item name="value" xsi:type="number">0</item>
<item name="label" xsi:type="string" translate="true">Inactive</item>
</item>
<item name="1" xsi:type="array">
<item name="value" xsi:type="number">1</item>
<item name="label" xsi:type="string" translate="true">Active</item>
</item>
</item>
</item>
</argument>
<settings>
<dataType>text</dataType>
<label translate="true">Status</label>
<dataScope>status</dataScope>
</settings>
<formElements>
<select>
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
<rule name="validate-number" xsi:type="boolean">false</rule>
<rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
</validation>
<options>
<option name="0" xsi:type="array">
<item name="value" xsi:type="number">0</item>
<item name="label" xsi:type="string" translate="true">Inactive</item>
</option>
<option name="1" xsi:type="array">
<item name="value" xsi:type="number">1</item>
<item name="label" xsi:type="string" translate="true">Active</item>
</option>
</options>
</settings>
</select>
</formElements>
</field>
</fieldset>
</form>

0 comments on commit 01c9698

Please sign in to comment.