Added the new fields to the part edit form.

This commit is contained in:
Jan Böhmer 2019-08-19 14:07:00 +02:00
parent 7517d83f55
commit 6a0adae8f3
17 changed files with 922 additions and 53 deletions

View file

@ -32,7 +32,7 @@ namespace App\Controller;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use App\Form\PartType;
use App\Form\Part\PartBaseType;
use App\Services\AttachmentFilenameService;
use App\Services\AttachmentHelper;
use Doctrine\ORM\EntityManagerInterface;
@ -70,7 +70,7 @@ class PartController extends AbstractController
{
$this->denyAccessUnlessGranted('edit', $part);
$form = $this->createForm(PartType::class, $part);
$form = $this->createForm(PartBaseType::class, $part);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -79,10 +79,10 @@ class PartController extends AbstractController
$this->addFlash('info', 'part.edited_flash');
}
return $this->render('Parts/edit_part_info.html.twig',
return $this->render('Parts/edit/edit_part_info.html.twig',
[
'part' => $part,
'form' => $form->createView(),
'form_main' => $form->createView(),
]);
}
@ -102,7 +102,7 @@ class PartController extends AbstractController
$category = $em->find(Category::class, $cid);
$new_part->setCategory($category);
$form = $this->createForm(PartType::class, $new_part);
$form = $this->createForm(PartBaseType::class, $new_part);
$form->handleRequest($request);
@ -114,7 +114,7 @@ class PartController extends AbstractController
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
}
return $this->render('Parts/new_part.html.twig',
return $this->render('Parts/edit/new_part.html.twig',
[
'part' => $new_part,
'form' => $form->createView(),
@ -131,7 +131,7 @@ class PartController extends AbstractController
$this->denyAccessUnlessGranted('create', $new_part);
$form = $this->createForm(PartType::class, $new_part);
$form = $this->createForm(PartBaseType::class, $new_part);
$form->handleRequest($request);

View file

@ -745,7 +745,7 @@ class Part extends AttachmentContainingDBElement
*
* @return self
*/
public function setMinAmount(float $new_mininstock): self
public function setMinAmount(float $new_minamount): self
{
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');

View file

@ -1,8 +1,9 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/.
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -25,18 +26,24 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form;
namespace App\Form\Part;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Form\Type\StructuralEntityType;
use Doctrine\DBAL\Types\FloatType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
@ -46,7 +53,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
class PartType extends AbstractType
class PartBaseType extends AbstractType
{
protected $security;
@ -57,40 +64,69 @@ class PartType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Part $part */
$part = $options['data'];
//Select the amount value type based on the
if($part->useFloatAmount()) {
$amount_class = NumberType::class;
} else {
$amount_class = IntegerType::class;
}
//Common section
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'],
'disabled' => !$this->security->isGranted('name.edit', $part), ])
->add('description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'],
'disabled' => !$this->security->isGranted('name.edit', $part), ])
->add('description', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => 'description.label', 'help' => 'bbcode.hint', 'config_name' => 'description_config',
'attr' => ['placeholder' => 'part.description.placeholder', 'rows' => 2],
'disabled' => !$this->security->isGranted('description.edit', $part), 'empty_data' => '' ])
/*->add('instock', IntegerType::class,
['attr' => ['min' => 0, 'placeholder' => 'part.instock.placeholder'], 'label' => 'instock.label',
'disabled' => !$this->security->isGranted('instock.edit', $part), ]) */
->add('mininstock', IntegerType::class,
->add('partUnit', StructuralEntityType::class, ['class'=> MeasurementUnit::class,
'required' => false, 'disable_not_selectable' => true, 'label' => 'part.partUnit'])
->add('minAmount', $amount_class,
['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label',
'disabled' => !$this->security->isGranted('mininstock.edit', $part), ])
->add('category', StructuralEntityType::class, ['class' => Category::class,
'label' => 'category.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part), ])
/*->add('storelocation', EntityType::class, ['class' => Storelocation::class, 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'storelocation.label',
'disabled' => !$this->security->isGranted('storelocation.edit', $part), ]) */
->add('manufacturer', StructuralEntityType::class, ['class' => Manufacturer::class,
'required' => false, 'label' => 'manufacturer.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('footprint', StructuralEntityType::class, ['class' => Footprint::class,
'label' => 'footprint.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('move', $part), ])
->add('tags', TextType::class, ['required' => false, 'label' => 'part.tags',
'attr' => ['data-role' => 'tagsinput'],
'disabled' => !$this->security->isGranted('edit', $part) ])
->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => '']);
//Manufacturer section
$builder->add('manufacturer', StructuralEntityType::class, ['class' => Manufacturer::class,
'required' => false, 'label' => 'manufacturer.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '',
'label' => 'manufacturer_url.label',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => ''])
->add('manufacturer_product_number', TextType::class, ['required' => false,
'empty_data' => '', 'label' => 'part.mpn',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]);
//Options section
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
'required' => false, 'label' => 'part.edit.needs_review'])
->add('favorite', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
'required' => false, 'label' => 'part.edit.is_favorite']);
$builder
//Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save'])
->add('reset', ResetType::class, ['label' => 'part.edit.reset']);
->add('save1', SubmitType::class, ['label' => 'part.edit.save'])
->add('reset1', ResetType::class, ['label' => 'part.edit.reset'])
->add('save2', SubmitType::class, ['label' => 'part.edit.save'])
->add('reset2', ResetType::class, ['label' => 'part.edit.reset'])
->add('save3', SubmitType::class, ['label' => 'part.edit.save'])
->add('reset3', ResetType::class, ['label' => 'part.edit.reset']);
}
public function configureOptions(OptionsResolver $resolver)