diff --git a/src/CoursEndingBundle/Controller/MainController.php b/src/CoursEndingBundle/Controller/MainController.php index 355680a..5d19ddb 100644 --- a/src/CoursEndingBundle/Controller/MainController.php +++ b/src/CoursEndingBundle/Controller/MainController.php @@ -2,6 +2,8 @@ namespace CoursEndingBundle\Controller; +use CoursEndingBundle\Form\Type\FormType; +use Doctrine\ORM\Query\Expr\From; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; @@ -19,12 +21,13 @@ class MainController extends Controller */ public function indexAction(Request $request) { + $forms = ['forms' => FormQuery::create()->find()]; $form = $this->createForm(FormsType::class, $forms); if ($form->isValid()) { - die("ok"); + //die("ok"); } return [ diff --git a/src/CoursEndingBundle/Controller/RestController.php b/src/CoursEndingBundle/Controller/RestController.php index d2a5399..c7c0bb7 100644 --- a/src/CoursEndingBundle/Controller/RestController.php +++ b/src/CoursEndingBundle/Controller/RestController.php @@ -2,6 +2,7 @@ namespace CoursEndingBundle\Controller; +use CoursEndingBundle\Model\Form; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle\Controller\Annotations as Rest; @@ -63,7 +64,14 @@ class RestController extends FOSRestController $form->handleRequest($request); - return View::create($form, 400); + if ($form->isValid()) { + $forms['forms']->save(); + echo "Valid"; + print_r($form->isValid()); + die(); + } + + return View::create($form, 200); } // public function postQuestionsAction(Request $request) diff --git a/src/CoursEndingBundle/Form/Type/FormType.php b/src/CoursEndingBundle/Form/Type/FormType.php index a8c4d5d..1404416 100644 --- a/src/CoursEndingBundle/Form/Type/FormType.php +++ b/src/CoursEndingBundle/Form/Type/FormType.php @@ -5,6 +5,7 @@ namespace CoursEndingBundle\Form\Type; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; use Propel\Bundle\PropelBundle\Form\BaseAbstractType; +use Symfony\Component\Validator\Constraints\NotBlank; class FormType extends BaseAbstractType { @@ -20,6 +21,9 @@ class FormType extends BaseAbstractType 'id', TextType::class, array( + 'constraints' => array( + new NotBlank(), + ), ) ); @@ -27,6 +31,9 @@ class FormType extends BaseAbstractType 'label', TextType::class, array( + 'constraints' => array( + new NotBlank(), + ), ) ); @@ -34,6 +41,9 @@ class FormType extends BaseAbstractType 'active', TextType::class, array( +// 'constraints' => array( +// new NotBlank(), +// ), ) ); } diff --git a/src/CoursEndingBundle/Resources/config/propel/schema.xml b/src/CoursEndingBundle/Resources/config/propel/schema.xml index b329e91..8f35ab1 100644 --- a/src/CoursEndingBundle/Resources/config/propel/schema.xml +++ b/src/CoursEndingBundle/Resources/config/propel/schema.xml @@ -7,7 +7,7 @@ - + diff --git a/src/CoursEndingBundle/Resources/public/js/app.js b/src/CoursEndingBundle/Resources/public/js/app.js index 1caf588..af9b73e 100644 --- a/src/CoursEndingBundle/Resources/public/js/app.js +++ b/src/CoursEndingBundle/Resources/public/js/app.js @@ -1,4 +1,6 @@ -new Vue({ +Vue.config.debug = true; +Vue.config.devtools = true; +var x = new Vue({ el: '#forms-render', data: { @@ -12,21 +14,46 @@ new Vue({ methods: { fetchForms: function() { this.$http.get(Routing.generate('api_get_forms'), function(forms) { + for (var i = 0; i < forms.data.length; i++) { + forms.data[i].errors = {}; + } this.$set('forms', forms.data); }); }, save: function() { + var that = this; var data = { forms: { forms: this.forms } }; - this.$http.post( - Routing.generate('api_post_forms'), - data - ); + this.$http.post(Routing.generate('api_post_forms'), data) + .success(function (data) { + console.log(data); + }) + .error(function (data) { + console.log(data); + if (data.hasOwnProperty("code") && data.code === 400 + && data.hasOwnProperty('message') && data.message === "Validation Failed" ) { + var k = 0; + for (var i = 0; i < data.errors.children.forms.children.length; i++) { + var form = data.errors.children.forms.children[i]; + //console.log(form); + for ( var j in form ) { + var errorsInputs = form[j]; + //console.log(errorsInputs); + that.forms[k].errors = errorsInputs; + //that.forms[k].label = 'toto'; + + k++; + } + } + console.log(that.forms); + //that.$set('forms', that.forms); //change rien avec ou sans + } + }); } } }) diff --git a/src/CoursEndingBundle/Resources/views/Main/index.html.twig b/src/CoursEndingBundle/Resources/views/Main/index.html.twig index e36b825..e82cc60 100644 --- a/src/CoursEndingBundle/Resources/views/Main/index.html.twig +++ b/src/CoursEndingBundle/Resources/views/Main/index.html.twig @@ -2,12 +2,13 @@ {% block body %} -{{form_row(form.forms)}} - -{{ form_rest(form) }} - -
+{#{{ form_row(form.forms) }}#} +{##} +{#{{ form_rest(form) }}#} +
+


+
{% raw %} @@ -16,11 +17,20 @@ {{ form.label }}
-
-
- {{ form.active ? 'ACTVITÉ' : 'NON ACTIVÉ' }} +
+
+
+

{{ errors.errors }}

+
+
+ +
{% endraw %}
diff --git a/web/app_dev.php b/web/app_dev.php index 635bf7a..697665f 100644 --- a/web/app_dev.php +++ b/web/app_dev.php @@ -12,7 +12,7 @@ use Symfony\Component\Debug\Debug; // Feel free to remove this, extend it, or make something more sophisticated. if (isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) - || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server') + || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1','192.168.33.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server') ) { header('HTTP/1.0 403 Forbidden'); exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');