bd 8.0
This commit is contained in:
parent
05cbb7ef43
commit
13dbef5b4f
@ -31,8 +31,9 @@ $router->get("/form-item/{id}", [\itguild\forms\app\controllers\FormController::
|
|||||||
$router->get("/form-delete/{id}", [\itguild\forms\app\controllers\FormController::class, "deleteAction"]);
|
$router->get("/form-delete/{id}", [\itguild\forms\app\controllers\FormController::class, "deleteAction"]);
|
||||||
$router->get("/form-edit/{id}", [\itguild\forms\app\controllers\FormController::class, "editAction"]);
|
$router->get("/form-edit/{id}", [\itguild\forms\app\controllers\FormController::class, "editAction"]);
|
||||||
$router->get("/admin/create-form", [\itguild\forms\app\controllers\AdminController::class, "createAction"]);
|
$router->get("/admin/create-form", [\itguild\forms\app\controllers\AdminController::class, "createAction"]);
|
||||||
$router->post("/admin/save-form", [\itguild\forms\app\controllers\AdminController::class, "saveForm"]);
|
$router->post("/admin/save-form", [\itguild\forms\app\controllers\AdminController::class, "saveFormAction"]);
|
||||||
$router->post("/admin/handler", [\itguild\forms\app\controllers\AdminController::class, "ajax"]);
|
$router->get("/admin/form-add-fields", [\itguild\forms\app\controllers\AdminController::class, "getFormAddFieldsAction"]);
|
||||||
|
$router->get("/admin/set-value-select", [\itguild\forms\app\controllers\AdminController::class, "getSelectValue"]);
|
||||||
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
|
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
|
||||||
|
|
||||||
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
function ajaxRequest() {
|
function ajaxRequest() {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open("POST", "handler");
|
request.open("GET", "/admin/form-add-fields");
|
||||||
request.addEventListener("load", () => {
|
request.addEventListener("load", () => {
|
||||||
const responseText = request.responseText;
|
const responseText = request.responseText;
|
||||||
const targetElement = document.getElementById("buttonAdd");
|
const targetElement = document.getElementById("buttonAdd");
|
||||||
@ -13,3 +13,21 @@ function ajaxRequest() {
|
|||||||
});
|
});
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
|
function getValueSelect(){
|
||||||
|
var selectValue = document.getElementById("selectID").value
|
||||||
|
var inputTags = document.getElementsByTagName('input');
|
||||||
|
var inputCount = inputTags.length - 3;
|
||||||
|
var request = new XMLHttpRequest()
|
||||||
|
request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + inputCount, true)
|
||||||
|
request.addEventListener("load", () => {
|
||||||
|
var responseText = request.responseText;
|
||||||
|
var targetElement = document.getElementById("buttonAdd");
|
||||||
|
var divElement = document.createElement("div");
|
||||||
|
divElement.classList.add("form-control");
|
||||||
|
divElement.style.backgroundColor = "#bbbbbb"; // Задайте здесь свой нужный стиль
|
||||||
|
divElement.innerHTML = responseText;
|
||||||
|
targetElement.insertAdjacentElement("beforebegin", divElement);
|
||||||
|
|
||||||
|
});
|
||||||
|
request.send()
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace itguild\forms\app\controllers;
|
namespace itguild\forms\app\controllers;
|
||||||
|
|
||||||
|
use Illuminate\Database\Events\DatabaseBusy;
|
||||||
use itguild\forms\ActiveForm;
|
use itguild\forms\ActiveForm;
|
||||||
use itguild\forms\app\core\BaseController;
|
use itguild\forms\app\core\BaseController;
|
||||||
use itguild\forms\app\models\FormModel;
|
use itguild\forms\app\models\FormModel;
|
||||||
@ -11,6 +12,8 @@ use itguild\forms\core\cg_view\CgView;
|
|||||||
* @var \itguild\forms\ActiveForm $form ;
|
* @var \itguild\forms\ActiveForm $form ;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\debug\Debug;
|
||||||
|
use itguild\forms\exceptions\FieldTypeNotFound;
|
||||||
use itguild\forms\Form;
|
use itguild\forms\Form;
|
||||||
use itguild\forms\inputs\Select;
|
use itguild\forms\inputs\Select;
|
||||||
use itguild\forms\inputs\TextInput;
|
use itguild\forms\inputs\TextInput;
|
||||||
@ -22,15 +25,11 @@ class AdminController extends BaseController
|
|||||||
|
|
||||||
public function createAction(): void
|
public function createAction(): void
|
||||||
{
|
{
|
||||||
$view = new CgView();
|
$this->cgView->layout = "/layouts/admin_layout.php";
|
||||||
|
|
||||||
$view->viewPath = VIEW_PATH;
|
|
||||||
$view->layout = "/layouts/admin_layout.php";
|
|
||||||
|
|
||||||
$view->render("/admin/index.php", ['title' => "Создать форму", 'form' => new ActiveForm()]);
|
|
||||||
|
|
||||||
|
$this->cgView->render("/admin/index.php", ['title' => "Создать форму", 'form' => new ActiveForm()]);
|
||||||
}
|
}
|
||||||
public function saveForm()
|
public function saveFormAction(): void
|
||||||
{
|
{
|
||||||
$title = $_POST["title"];
|
$title = $_POST["title"];
|
||||||
$params = $_POST["params"];
|
$params = $_POST["params"];
|
||||||
@ -39,33 +38,33 @@ class AdminController extends BaseController
|
|||||||
echo "Форма сохранена!";
|
echo "Форма сохранена!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function ajax()
|
public function getFormAddFieldsAction(): void
|
||||||
{
|
{
|
||||||
|
$this->cgView->render("/admin/_form_add_fields_ajax.php", ['form' => new ActiveForm()]);
|
||||||
|
}
|
||||||
|
public function getSelectValue(): void
|
||||||
|
{
|
||||||
|
$selectValue = $_GET["value"];
|
||||||
|
$countInput = $_GET["count"];
|
||||||
|
Debug::prn($countInput);
|
||||||
$form = new ActiveForm();
|
$form = new ActiveForm();
|
||||||
|
|
||||||
$form->field(Select::class, name: "selectItem", params: [
|
$fields = [
|
||||||
'class' => "form-control", "options" => ["textInput", "textArea", "checkBox", "button", "radioButton", "select", "label"]
|
1 => '_checkBox',
|
||||||
])
|
2 => '_text_input',
|
||||||
->setLabel("Выберите тип инпута")
|
3 => '_textarea',
|
||||||
->render();
|
4 => '_radioButton',
|
||||||
$form->field(TextInput::class, name: "name", params: [
|
5 => '_button',
|
||||||
'class' => "form-control",
|
6 => '_select'
|
||||||
'placeholder' => 'Name'
|
];
|
||||||
])
|
|
||||||
->setLabel("Имя поля")
|
$viewName = $fields[$selectValue] ?? false;
|
||||||
->render();
|
|
||||||
$form->field(TextInput::class, name: "value", params: [
|
if (!$viewName){
|
||||||
'class' => "form-control",
|
throw new FieldTypeNotFound($selectValue);
|
||||||
'placeholder' => 'Значение value'
|
}
|
||||||
])
|
|
||||||
->setLabel("Значение")
|
$this->cgView->render("/admin/field_type/$viewName.php", ['form' => new ActiveForm()]);
|
||||||
->render();
|
|
||||||
$form->field(TextArea::class, name: "value", params: [
|
|
||||||
'class' => "form-control",
|
|
||||||
'placeholder' => 'Параметры поля'
|
|
||||||
])
|
|
||||||
->setLabel("Параметры")
|
|
||||||
->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
namespace itguild\forms\app\core;
|
namespace itguild\forms\app\core;
|
||||||
|
|
||||||
|
use itguild\forms\core\cg_view\CgView;
|
||||||
|
|
||||||
class BaseController
|
class BaseController
|
||||||
{
|
{
|
||||||
protected $view;
|
protected \Twig\Environment $view;
|
||||||
|
|
||||||
|
protected CgView $cgView;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -12,6 +16,9 @@ class BaseController
|
|||||||
$this->view = new \Twig\Environment($loader, [
|
$this->view = new \Twig\Environment($loader, [
|
||||||
'cache' => VIEW_CACHE_PATH,
|
'cache' => VIEW_CACHE_PATH,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->cgView = new CgView();
|
||||||
|
$this->cgView->viewPath = VIEW_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
13
src/exceptions/FieldTypeNotFound.php
Normal file
13
src/exceptions/FieldTypeNotFound.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace itguild\forms\exceptions;
|
||||||
|
|
||||||
|
class FieldTypeNotFound extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct(string $type)
|
||||||
|
{
|
||||||
|
$this->message = "Тип поля $type не найден";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
views/admin/_form_add_fields_ajax.php
Normal file
29
views/admin/_form_add_fields_ajax.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
use itguild\forms\ActiveForm;
|
||||||
|
use itguild\forms\inputs\Select;
|
||||||
|
use itguild\forms\inputs\TextArea;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
|
||||||
|
$form->field(Select::class, name: "selectItem", params: [
|
||||||
|
'class' => "form-control", "options" => ["textInput", "textArea", "checkBox", "button", "radioButton", "select", "label"]
|
||||||
|
])
|
||||||
|
->setLabel("Выберите тип инпута")
|
||||||
|
->render();
|
||||||
|
$form->field(TextInput::class, name: "name", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Name'
|
||||||
|
])
|
||||||
|
->setLabel("Имя поля")
|
||||||
|
->render();
|
||||||
|
$form->field(TextInput::class, name: "value", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Значение value'
|
||||||
|
])
|
||||||
|
->setLabel("Значение")
|
||||||
|
->render();
|
14
views/admin/field_type/_button.php
Normal file
14
views/admin/field_type/_button.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<b><p>Кнопка</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
|
14
views/admin/field_type/_checkBox.php
Normal file
14
views/admin/field_type/_checkBox.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<b><p>Чекбокс</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
|
14
views/admin/field_type/_radioButton.php
Normal file
14
views/admin/field_type/_radioButton.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<b><p>Радио кнопка</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
|
22
views/admin/field_type/_select.php
Normal file
22
views/admin/field_type/_select.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<b><p>Список</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextArea;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование поля"])
|
||||||
|
->setLabel("Наименование поля (например \"Телефон\")")
|
||||||
|
->render();
|
||||||
|
$form->field(TextArea::class, name: "OptionsInput", params: ['class' => "form-control"])
|
||||||
|
->setLabel("Опции выпадающего списка")
|
||||||
|
->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])
|
||||||
|
->setLabel("Обязательное поле")
|
||||||
|
->render();
|
16
views/admin/field_type/_text_input.php
Normal file
16
views/admin/field_type/_text_input.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<b><p>Текстовое поле</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
|
||||||
|
$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render();
|
16
views/admin/field_type/_textarea.php
Normal file
16
views/admin/field_type/_textarea.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<b><p>Описание</p></b>
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \itguild\forms\ActiveForm $form
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\inputs\Checkbox;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
|
||||||
|
$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control",
|
||||||
|
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
|
||||||
|
$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render();
|
@ -6,6 +6,8 @@
|
|||||||
use itguild\forms\inputs\TextInput;
|
use itguild\forms\inputs\TextInput;
|
||||||
use itguild\forms\inputs\TextArea;
|
use itguild\forms\inputs\TextArea;
|
||||||
|
|
||||||
|
$types = \itguild\forms\app\models\InputTypeModel::where("status", 1)->pluck('name', 'id')->toArray();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php echo $form->beginForm("/admin/save-form"); ?>
|
<?php echo $form->beginForm("/admin/save-form"); ?>
|
||||||
@ -16,20 +18,28 @@ use itguild\forms\inputs\TextArea;
|
|||||||
->setLabel("Название формы")
|
->setLabel("Название формы")
|
||||||
->render();
|
->render();
|
||||||
|
|
||||||
$form->field(TextInput::class, name: "title", params: [
|
$form->field(TextInput::class, name: "perPage", params: [
|
||||||
'class' => "form-control",
|
'class' => "form-control",
|
||||||
'placeholder' => 'Perpage'
|
'placeholder' => 'Perpage'
|
||||||
])
|
])
|
||||||
->setLabel("Количество выводимых записей на страницу")
|
->setLabel("Количество выводимых записей на страницу")
|
||||||
->render();
|
->render();
|
||||||
$form->field(TextArea::class, name: "title", params: [
|
$form->field(TextArea::class, name: "paramsForm", params: [
|
||||||
'class' => "form-control",
|
'class' => "form-control",
|
||||||
'placeholder' => 'Параметры'
|
'placeholder' => 'Параметры'
|
||||||
])
|
])
|
||||||
->setLabel("Параметры")
|
->setLabel("Параметры")
|
||||||
->render();
|
->render();
|
||||||
|
$form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [
|
||||||
|
'class' => "form-control-sm",
|
||||||
|
'id' => "selectID",
|
||||||
|
'placeholder' => 'Параметры',
|
||||||
|
'options' => $types
|
||||||
|
])
|
||||||
|
->setLabel("Добавить поле")
|
||||||
|
->render();
|
||||||
?>
|
?>
|
||||||
<button style="margin-top:15px" type="button" id="buttonAdd" class="btn btn-primary form-control" onclick="ajaxRequest()">Добавить поле</button>
|
<button style="margin-top:15px" type="button" id="buttonAdd" class="btn btn-success " onclick="getValueSelect()">Добавить поле</button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user