mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 01:28:47 +02:00
poc form SDK (extends to form)
This commit is contained in:
@@ -64,11 +64,14 @@ const Collection = function(oForm, objectFormUrl, objectSaveUrl){
|
||||
*/
|
||||
function addFormToCollection(e){
|
||||
|
||||
alert('addFormToCollection');
|
||||
|
||||
// retrieve link set container
|
||||
const oContainer = e.currentTarget.closest('.link_set_widget_container');
|
||||
|
||||
// retrieve collection holder
|
||||
const collectionHolder = oContainer.querySelector('.' + e.currentTarget.dataset.collectionHolderClass);
|
||||
const exp = e.currentTarget.dataset.collectionHolderClass.replaceAll(/:/g, '\\:');
|
||||
const collectionHolder = oContainer.querySelector('.' + exp);
|
||||
|
||||
// compute template
|
||||
const text = collectionHolder
|
||||
@@ -141,6 +144,7 @@ const Collection = function(oForm, objectFormUrl, objectSaveUrl){
|
||||
oModalBody.html(data.template);
|
||||
oModalBody[0].querySelectorAll('form').forEach((formEl) => {
|
||||
oForm.handleElement(formEl);
|
||||
handleElement(formEl);
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
@@ -153,8 +157,10 @@ const Collection = function(oForm, objectFormUrl, objectSaveUrl){
|
||||
*
|
||||
* @param oContainer
|
||||
*/
|
||||
const handleElement = function(oContainer)
|
||||
function handleElement(oContainer)
|
||||
{
|
||||
console.log('collection handleElement ' + oContainer);
|
||||
|
||||
listenAddItem(oContainer);
|
||||
listenCreateItem(oContainer);
|
||||
listenRemoveItem(oContainer);
|
||||
@@ -168,17 +174,12 @@ const Collection = function(oForm, objectFormUrl, objectSaveUrl){
|
||||
|
||||
const oForm = document.querySelector('form[name="new"]');
|
||||
|
||||
|
||||
for(let instanceName in CKEDITOR.instances) {
|
||||
|
||||
CKEDITOR.instances[instanceName].updateElement();
|
||||
}
|
||||
|
||||
const data = new URLSearchParams();
|
||||
for (const pair of new FormData(oForm)) {
|
||||
|
||||
console.log(pair[0] + ' = ' + pair[1]);
|
||||
|
||||
data.append(pair[0], pair[1]);
|
||||
}
|
||||
data.append('locked_attributes', '');
|
||||
|
||||
@@ -8,6 +8,8 @@ use Combodo\iTop\DI\Services\ObjectService;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -161,6 +163,12 @@ class ObjectController extends AbstractController
|
||||
]
|
||||
]);
|
||||
|
||||
// locked attributes
|
||||
$oForm->add('locked_attributes', HiddenType::class, [
|
||||
'mapped' => false,
|
||||
'data' => json_encode($aData['locked_attributes'])
|
||||
]);
|
||||
|
||||
// return object form
|
||||
return new JsonResponse([
|
||||
'template' => $this->renderView('DI/form.html.twig', [
|
||||
@@ -192,6 +200,14 @@ class ObjectController extends AbstractController
|
||||
// handle HTTP request
|
||||
$oForm->handleRequest($request);
|
||||
|
||||
// locked attributes
|
||||
$aValue = $request->get('new');
|
||||
$sLockedAttributes = $aValue['locked_attributes'];
|
||||
$aLockedAttributes = json_decode($sLockedAttributes);
|
||||
foreach($aLockedAttributes as $sKey => $sValue){
|
||||
$oObject->Set($sKey, $sValue);
|
||||
}
|
||||
|
||||
// submitted and valid
|
||||
if ($oForm->isSubmitted() && $oForm->isValid()) {
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ class AttributeBuilder
|
||||
'class' => $bIsLocked ? 'locked' : ''
|
||||
]
|
||||
],
|
||||
'create_hidden' => $bIsLocked
|
||||
];
|
||||
|
||||
// register dependencies
|
||||
|
||||
@@ -6,7 +6,6 @@ use Combodo\iTop\DI\Form\Builder\AttributeBuilder;
|
||||
use Combodo\iTop\DI\Form\Builder\LayoutBuilder;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
@@ -58,10 +57,6 @@ class ObjectPresentationService
|
||||
$level = $this->handleLevel($aPresentation, $class, $lockedAttributes);
|
||||
foreach ($level as $key => $value) {
|
||||
$builder->add($key, $value['type'], $value['options']);
|
||||
|
||||
// if(array_key_exists('create_hidden', $value) && $value['create_hidden'] === true){
|
||||
// $builder->add($key,HiddenType::class);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'Organization', 'id': 1}) }}">Organization</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'Person', 'id': 1}) }}">Person</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'User', 'id': 1}) }}">User</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'UserLocal', 'id': 1}) }}">UserLocal</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'UserRequest', 'id': 1}) }}">UserRequest</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -62,7 +62,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'Organization', 'id': 0}) }}">Organization</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'Person', 'id': 0}) }}">Person</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'User', 'id': 0}) }}">User</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'UserLocal', 'id': 0}) }}">UserLocal</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('object_edit', {'class': 'UserRequest', 'id': 0}) }}">UserRequest</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
|
||||
{%- endblock external_key_widget -%}
|
||||
|
||||
|
||||
{# LinkSetType #}
|
||||
{%- block link_set_widget -%}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user