Commit 4ba3248f authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Mise en place d'Axios pour l'AJAX

parent 45b8b75e
Loading
Loading
Loading
Loading
+8 −12
Changes for front/components/Mission/Mission.vue: 8 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -66,22 +66,18 @@ export default {
    },
    data()
    {
        return {};
        return {
            mission: this.mission
        };
    },
    methods: {
        submitForm(event)
        {
            var that = this
            $.ajax({
                type: 'POST',
                submitter: event.submitter,
                msg: 'Enregistrement en cours',
                successMsg: 'Enregistrement effectué',
                url: Util.url('mission/modifier'),
                data: this.mission,
                success: function (response) {
                    that.mission = response.data;
                }
            axios.post(
                Util.url('mission/modifier'),
                this.mission
            ).then((response) => {
                this.mission = response.data.data;
            });
        },
        deleteMission(mission)
+1
Changes for module/Application/config/aaa_module.config.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ $config = [
    'controller_plugins' => [
        'factories' => [
            'context' => Controller\Plugin\ContextFactory::class,
            'axios'   => Controller\Plugin\AxiosFactory::class,
        ],
    ],
    'view_manager'       => [
+1
Changes for module/Application/src/Controller/AbstractController.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Laminas\Mvc\Controller\AbstractActionController;
 * Description of AbstractController
 *
 * @method \Application\Controller\Plugin\Context context()
 * @method \Application\Controller\Plugin\Axios axios()
 * @method \Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger flashMessenger()
 * @method \BjyAuthorize\Controller\Plugin\IsAllowed isAllowed($resource, $privilege = null)
 *
+x+29
Changes for module/Application/src/Controller/Plugin/Axios.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Plugin;

use Laminas\Mvc\Controller\Plugin\AbstractPlugin;

/**
 * Description of Axios
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class Axios extends AbstractPlugin
{

    public function fromPost(?string $param = null, $default = null)
    {
        $post = (array)json_decode(file_get_contents('php://input'));
        if ($param) {
            if (array_key_exists($param, $post)) {
                return $post[$param];
            } else {
                return $default;
            }
        } else {
            return $post;
        }
    }

}
 No newline at end of file
+x+31
Changes for module/Application/src/Controller/Plugin/AxiosFactory.php: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Plugin;

use Psr\Container\ContainerInterface;


/**
 * Description of AxiosFactory
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class AxiosFactory
{

    /**
     * @param ContainerInterface $container
     * @param string             $requestedName
     * @param array|null         $options
     *
     * @return Axios
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null): Axios
    {
        $plugin = new Axios;

        /* Injectez vos dépendances ICI */

        return $plugin;
    }
}
 No newline at end of file
Loading