mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Taxon] Remove drag n drop support
This commit is contained in:
parent
af826a4067
commit
01f4c8d01d
7 changed files with 36 additions and 107 deletions
|
|
@ -7,7 +7,7 @@ Feature: Deleting a taxon
|
||||||
Background:
|
Background:
|
||||||
Given I am logged in as an administrator
|
Given I am logged in as an administrator
|
||||||
|
|
||||||
@ui @javascript
|
@ui
|
||||||
Scenario: Deleted taxon should disappear from the registry
|
Scenario: Deleted taxon should disappear from the registry
|
||||||
Given the store classifies its products as "T-Shirts"
|
Given the store classifies its products as "T-Shirts"
|
||||||
When I delete taxon named "T-Shirts"
|
When I delete taxon named "T-Shirts"
|
||||||
|
|
|
||||||
|
|
@ -67,15 +67,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
$leaves = $this->getLeaves();
|
$leaves = $this->getLeaves();
|
||||||
foreach ($leaves as $leaf) {
|
foreach ($leaves as $leaf) {
|
||||||
if ($leaf->getText() === $name) {
|
if ($leaf->getText() === $name) {
|
||||||
$leaf = $leaf->getParent();
|
$leaf->getParent()->find('css', '.ui.red.button')->press();
|
||||||
$menuButton = $leaf->find('css', '.wrench');
|
|
||||||
$menuButton->click();
|
|
||||||
$deleteButton = $leaf->find('css', '.sylius-delete-resource');
|
|
||||||
$deleteButton->click();
|
|
||||||
|
|
||||||
$deleteButton->waitFor(5, function () use ($leaf) {
|
|
||||||
return null === $leaf->find('css', '.sylius-delete-resource');
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +156,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
$tree = $this->getElement('tree');
|
$tree = $this->getElement('tree');
|
||||||
Assert::notNull($tree);
|
Assert::notNull($tree);
|
||||||
/** @var NodeElement[] $leaves */
|
/** @var NodeElement[] $leaves */
|
||||||
$leaves = $tree->findAll('css', '.item > .content > .header');
|
$leaves = $tree->findAll('css', '.item > .content > .header > a');
|
||||||
|
|
||||||
if (null === $parentTaxon) {
|
if (null === $parentTaxon) {
|
||||||
return $leaves;
|
return $leaves;
|
||||||
|
|
@ -206,13 +198,11 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
$leaves = $this->getLeaves();
|
$leaves = $this->getLeaves();
|
||||||
foreach ($leaves as $leaf) {
|
foreach ($leaves as $leaf) {
|
||||||
if ($leaf->getText() === $taxon->getName()) {
|
if ($leaf->getText() === $taxon->getName()) {
|
||||||
$leaf = $leaf->getParent();
|
$moveButton = $leaf->getParent()->find('css', sprintf('.sylius-taxon-move-%s', $direction));
|
||||||
$menuButton = $leaf->find('css', '.wrench');
|
|
||||||
$menuButton->click();
|
|
||||||
$moveButton = $leaf->find('css', sprintf('.%s', $direction));
|
|
||||||
$moveButton->click();
|
$moveButton->click();
|
||||||
$moveButton->waitFor(5, function () use ($taxon) {
|
|
||||||
return $this->getFirstLeafName() === $taxon->getName();
|
$moveButton->waitFor(5, function () use ($moveButton) {
|
||||||
|
return !$moveButton->hasClass('loading');
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ var paths = {
|
||||||
admin: {
|
admin: {
|
||||||
js: [
|
js: [
|
||||||
'../../../../node_modules/jquery/dist/jquery.min.js',
|
'../../../../node_modules/jquery/dist/jquery.min.js',
|
||||||
'../../../../node_modules/sortablejs/Sortable.js',
|
|
||||||
'../../../../node_modules/sortablejs/jquery.binding.js',
|
'../../../../node_modules/sortablejs/jquery.binding.js',
|
||||||
'../../../../node_modules/semantic-ui-css/semantic.min.js',
|
'../../../../node_modules/semantic-ui-css/semantic.min.js',
|
||||||
'../PromotionBundle/Resources/public/js/sylius-promotion.js',
|
'../PromotionBundle/Resources/public/js/sylius-promotion.js',
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
(function ($) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
|
||||||
$('.sylius-delete-resource').api({
|
|
||||||
method: 'delete',
|
|
||||||
onSuccess: function (response) {
|
|
||||||
var redirectUrl = $(this).data('success-redirect-url');
|
|
||||||
|
|
||||||
if (redirectUrl) {
|
|
||||||
location.replace(redirectUrl);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw 'You need to define data-success-redirect-url on "' + $(this).attr('class') +'"';
|
|
||||||
},
|
|
||||||
onFailure: function (response) {
|
|
||||||
var message = $(this).parent().parent().popup({
|
|
||||||
inline: true,
|
|
||||||
content: response.error.message,
|
|
||||||
on: 'manual'
|
|
||||||
});
|
|
||||||
message.popup('show');
|
|
||||||
setTimeout(function() { message.popup('hide'); }, 3000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})( jQuery );
|
|
||||||
|
|
@ -2,40 +2,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$('.sylius-sortable-list').sortable({
|
|
||||||
forceFallback: true,
|
|
||||||
onStart: function (event) {
|
|
||||||
$(event.item).addClass('dragging-started');
|
|
||||||
},
|
|
||||||
onEnd: function (event) {
|
|
||||||
$(event.item).removeClass('dragging-started');
|
|
||||||
$(this).api({
|
|
||||||
throttle: 500,
|
|
||||||
method: 'PUT',
|
|
||||||
action: 'move taxon',
|
|
||||||
on: 'now',
|
|
||||||
urlData: {
|
|
||||||
id: $(event.item).data('id')
|
|
||||||
},
|
|
||||||
beforeSend: function (settings) {
|
|
||||||
settings.data = {
|
|
||||||
position: event.newIndex
|
|
||||||
};
|
|
||||||
|
|
||||||
return settings;
|
|
||||||
},
|
|
||||||
onSuccess: function (response) {
|
|
||||||
$(event.item).find('.sylius-taxon-move-up').data('position', event.newIndex);
|
|
||||||
$(event.item).find('.sylius-taxon-move-down').data('position', event.newIndex);
|
|
||||||
},
|
|
||||||
onFailure: function (response) {
|
|
||||||
throw 'Something went wrong with api call.';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.sylius-taxon-move-up').api({
|
$('.sylius-taxon-move-up').api({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
on: 'click',
|
on: 'click',
|
||||||
|
|
|
||||||
|
|
@ -13,33 +13,19 @@
|
||||||
<a href="{{ path('sylius_admin_product_index_per_taxon', {'taxonId': taxon.id}) }}">
|
<a href="{{ path('sylius_admin_product_index_per_taxon', {'taxonId': taxon.id}) }}">
|
||||||
{{ taxon.name }}
|
{{ taxon.name }}
|
||||||
</a>
|
</a>
|
||||||
<div class="ui inline dropdown icon button mini">
|
<div class="ui mini buttons">
|
||||||
<i class="wrench icon"></i>
|
{{ buttons.create(path('sylius_admin_taxon_create_for_parent', { 'id': taxon.id }), 'sylius.ui.add'|trans) }}
|
||||||
<div class="menu">
|
{{ buttons.edit(path('sylius_admin_taxon_update', { 'id': taxon.id }), null, null, false) }}
|
||||||
<a class="item" href="{{ path('sylius_admin_taxon_create_for_parent', { 'id': taxon.id }) }}">
|
{{ buttons.delete(path('sylius_admin_taxon_delete', { 'id': taxon.id }), null, null, false) }}
|
||||||
<i class="plus icon"></i>
|
<a class="ui icon button sylius-taxon-move-up" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
||||||
{{ 'sylius.ui.add'|trans }}
|
<i class="icon arrow up"></i>
|
||||||
</a>
|
</a>
|
||||||
<a class="item" href="{{ path('sylius_admin_taxon_update', { 'id': taxon.id }) }}">
|
<a class="ui icon button sylius-taxon-move-down" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
||||||
<i class="edit icon"></i>
|
<i class="icon arrow down"></i>
|
||||||
{{ 'sylius.ui.edit'|trans }}
|
</a>
|
||||||
</a>
|
|
||||||
<div class="item sylius-taxon-move-up" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
|
||||||
<i class="icon arrow up"></i>
|
|
||||||
{{ 'sylius.ui.move_up'|trans }}
|
|
||||||
</div>
|
|
||||||
<div class="item sylius-taxon-move-down" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
|
||||||
<i class="icon arrow down"></i>
|
|
||||||
{{ 'sylius.ui.move_down'|trans }}
|
|
||||||
</div>
|
|
||||||
<div class="item sylius-delete-resource" data-url="{{ path('sylius_admin_taxon_delete', { 'id': taxon.id }) ~ '?_format=json' }}" data-success-redirect-url="{{ path('sylius_admin_taxon_index') }}">
|
|
||||||
<i class="delete icon"></i>
|
|
||||||
{{ 'sylius.ui.delete'|trans }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="list sylius-sortable-list">
|
<div class="list">
|
||||||
{{ tree.render(taxon.children) }}
|
{{ tree.render(taxon.children) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace Sylius\Bundle\TaxonomyBundle\Form\Type;
|
||||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
|
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
|
||||||
|
|
@ -28,10 +29,27 @@ final class TaxonPositionType extends AbstractResourceType
|
||||||
$builder
|
$builder
|
||||||
->add('position', IntegerType::class, [
|
->add('position', IntegerType::class, [
|
||||||
'label' => 'sylius.form.taxon.position',
|
'label' => 'sylius.form.taxon.position',
|
||||||
|
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
parent::configureOptions($resolver);
|
||||||
|
|
||||||
|
$resolver
|
||||||
|
->setDefaults([
|
||||||
|
'csrf_protection' => false,
|
||||||
|
])
|
||||||
|
->setDefined(['position'])
|
||||||
|
->setAllowedTypes('position', 'int')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue