feat: Небольшой рефакторинг. Ограничение длинны значения в поле ввода
This commit is contained in:
parent
f599a68529
commit
e5e0b6735f
5 changed files with 56 additions and 40 deletions
|
|
@ -203,17 +203,18 @@ class Action
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Генерация ссылки c учетом прав пользователя на ссылки
|
* Генерация ссылки c учетом прав пользователя на ссылки
|
||||||
* @param string $name Действие
|
* @param string $actionName Действие
|
||||||
* @param array $param Дополнительные параметры
|
* @param array $param Дополнительные параметры
|
||||||
* 'mode' означает что элемент до отправки обрабатывается javascript
|
* 'mode' означает что элемент до отправки обрабатывается javascript
|
||||||
* @return Url|null
|
* @return Url|null
|
||||||
*/
|
*/
|
||||||
public function nUrl($name, array $param = [])
|
public function nUrl($actionName, array $param = [])
|
||||||
{
|
{
|
||||||
$access/*: ActionAccess*/ = $this->access;
|
$access/*: ActionAccess*/ = $this->access;
|
||||||
$url = new Url();
|
$url = new Url();
|
||||||
|
|
||||||
if ($access == null || $access->checkAction($name)) {
|
//print_r([$name, $param]);
|
||||||
|
if ($access == null || $access->checkAction($actionName)) {
|
||||||
$moduleName = explode("\\", strtolower(get_class($this)));
|
$moduleName = explode("\\", strtolower(get_class($this)));
|
||||||
if (count($moduleName) > 2) {
|
if (count($moduleName) > 2) {
|
||||||
array_shift($moduleName);
|
array_shift($moduleName);
|
||||||
|
|
@ -221,7 +222,7 @@ class Action
|
||||||
array_shift($moduleName);
|
array_shift($moduleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$param = array_merge(['module' => implode("\\", $moduleName), "action" => $name], $param);
|
$param = array_merge(['module' => implode("\\", $moduleName), "action" => $actionName], $param);
|
||||||
|
|
||||||
$url->setParent($this->part);
|
$url->setParent($this->part);
|
||||||
$url->setQuery($param);
|
$url->setQuery($param);
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,9 @@ class Component
|
||||||
$view->component_title = $settings['title'];
|
$view->component_title = $settings['title'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Обьеденить с ComponentFactory
|
||||||
|
*/
|
||||||
static function loadComponent($expression, $site/*: SiteInterface*/)
|
static function loadComponent($expression, $site/*: SiteInterface*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -289,6 +292,7 @@ class Component
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Вынести в отдельную функцию
|
||||||
$db = $site->getDatabase();
|
$db = $site->getDatabase();
|
||||||
|
|
||||||
$component->db = $db;
|
$component->db = $db;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace ctiso\Form;
|
namespace ctiso\Form;
|
||||||
use ctiso\Form\Field;
|
use ctiso\Form\Field;
|
||||||
|
|
||||||
class Checkbox extends Field
|
class CheckBox extends Field
|
||||||
{
|
{
|
||||||
public $checked = false;
|
public $checked = false;
|
||||||
function setValue($value)
|
function setValue($value)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class Field
|
||||||
public $error = false;
|
public $error = false;
|
||||||
public $require = false;
|
public $require = false;
|
||||||
public $hint = null;
|
public $hint = null;
|
||||||
|
public $maxlength = null;
|
||||||
public $fieldset = null;
|
public $fieldset = null;
|
||||||
// Блоки (Убрать в отдельный класс!!!)
|
// Блоки (Убрать в отдельный класс!!!)
|
||||||
public $_title = array();
|
public $_title = array();
|
||||||
|
|
@ -33,7 +34,7 @@ class Field
|
||||||
$this->fieldset = $input['fieldset'];
|
$this->fieldset = $input['fieldset'];
|
||||||
}
|
}
|
||||||
// Инициализация свойст обьетка
|
// Инициализация свойст обьетка
|
||||||
foreach (['label', 'name', 'type', 'description'] as $name) {
|
foreach (['label', 'name', 'type', 'description', 'maxlength'] as $name) {
|
||||||
if (isset($input[$name])) {
|
if (isset($input[$name])) {
|
||||||
$this->$name = $input[$name];
|
$this->$name = $input[$name];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,41 +29,41 @@ class Form extends View {
|
||||||
public $_title = array();
|
public $_title = array();
|
||||||
public $alias = array();
|
public $alias = array();
|
||||||
public $constructor = array();
|
public $constructor = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Строим форму по ее структуре. Каждому типу соответствует определенный класс.
|
* Строим форму по ее структуре. Каждому типу соответствует определенный класс.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->constructor = [
|
$this->constructor = [
|
||||||
'input' => 'ctiso\\Form\\Input',
|
'input' => Input::class,
|
||||||
// input с проверкой на заполненность
|
// input с проверкой на заполненность
|
||||||
'inputreq' => 'ctiso\\Form\\Input',
|
'inputreq' => Input::class,
|
||||||
|
|
||||||
'date' => 'ctiso\\Form\\Date',
|
'date' => Date::class,
|
||||||
'datereq' => 'ctiso\\Form\\Date',
|
'datereq' => Date::class,
|
||||||
'datetime' => 'ctiso\\Form\\DateTime',
|
'datetime' => DateTime::class,
|
||||||
|
|
||||||
'color' => 'ctiso\\Form\\Color',
|
'color' => Color::class,
|
||||||
'textarea' => 'ctiso\\Form\\TextArea',
|
'textarea' => TextArea::class,
|
||||||
'text' => 'ctiso\\Form\\TextArea',
|
'text' => TextArea::class,
|
||||||
'multiselect' => 'ctiso\\Form\\SelectMany',
|
'multiselect' => SelectMany::class,
|
||||||
'select1' => 'ctiso\\Form\\SelectOne',
|
'select1' => SelectOne::class,
|
||||||
'select' => 'ctiso\\Form\\SelectOne',
|
'select' => SelectOne::class,
|
||||||
|
|
||||||
'questiontype'=> 'ctiso\\Form\\QuestionType',
|
'questiontype'=> QuestionType::class,
|
||||||
'secret' => 'ctiso\\Form\\Secret',
|
'secret' => Secret::class,
|
||||||
'upload' => 'ctiso\\Form\\Upload',
|
'upload' => Upload::class,
|
||||||
'image' => 'ctiso\\Form\\Upload',
|
'image' => Upload::class,
|
||||||
'checkbox' => 'ctiso\\Form\\CheckBox',
|
'checkbox' => CheckBox::class,
|
||||||
'checkmany' => 'ctiso\\Form\\SelectMany',
|
'checkmany' => SelectMany::class,
|
||||||
'hidden' => 'ctiso\\Form\\Hidden',
|
'hidden' => Hidden::class,
|
||||||
'radio' => 'ctiso\\Form\\SelectOne',
|
'radio' => SelectOne::class,
|
||||||
'filebrowser' => 'ctiso\\Form\\BrowserInput',
|
'filebrowser' => BrowserInput::class,
|
||||||
'documents' => 'ctiso\\Form\\BrowserInput',
|
'documents' => BrowserInput::class,
|
||||||
'chooser' => 'ctiso\\Form\\Input',
|
'chooser' => Input::class,
|
||||||
'select_chooser' => 'ctiso\\Form\\SelectOne',
|
'select_chooser' => SelectOne::class,
|
||||||
'html_text' => 'ctiso\\Form\\HtmlText'
|
'html_text' => HtmlText::class
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +77,7 @@ class Form extends View {
|
||||||
{
|
{
|
||||||
$this->constructor [$name] = $class;
|
$this->constructor [$name] = $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет одно поле ввода на форму
|
* Добавляет одно поле ввода на форму
|
||||||
*/
|
*/
|
||||||
|
|
@ -95,7 +95,7 @@ class Form extends View {
|
||||||
if(isset($init['hint'])) {
|
if(isset($init['hint'])) {
|
||||||
$el->hint = $init['hint'];
|
$el->hint = $init['hint'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->field[$init['name']] = $el;
|
$this->field[$init['name']] = $el;
|
||||||
return $el;
|
return $el;
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ class Form extends View {
|
||||||
/**
|
/**
|
||||||
* Добавление массива fieldset на форму
|
* Добавление массива fieldset на форму
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function addFieldSetList(array $list)
|
public function addFieldSetList(array $list)
|
||||||
{
|
{
|
||||||
foreach ($list as $fieldset) {
|
foreach ($list as $fieldset) {
|
||||||
|
|
@ -122,7 +122,7 @@ class Form extends View {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет список полей для формы
|
* Добавляет список полей для формы
|
||||||
* @param array $list
|
* @param array $list
|
||||||
*/
|
*/
|
||||||
public function addFieldList(array $list, $factory = null)
|
public function addFieldList(array $list, $factory = null)
|
||||||
{
|
{
|
||||||
|
|
@ -151,7 +151,7 @@ class Form extends View {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Устанавливает значения из масива
|
* Устанавливает значения из масива
|
||||||
*/
|
*/
|
||||||
function setValues(HttpRequest $request) {
|
function setValues(HttpRequest $request) {
|
||||||
foreach ($this->field as $key => $_) {
|
foreach ($this->field as $key => $_) {
|
||||||
$value = $request->getRawData($this->method, $key);
|
$value = $request->getRawData($this->method, $key);
|
||||||
|
|
@ -160,9 +160,9 @@ class Form extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Заполняет форму данными из обьекта
|
* Заполняет форму данными из обьекта
|
||||||
* @param object $data
|
* @param object $data
|
||||||
* @param array $schema Связь между элементами формы и свойствами обьекта
|
* @param array $schema Связь между элементами формы и свойствами обьекта
|
||||||
*/
|
*/
|
||||||
public function fill($data, array $schema)
|
public function fill($data, array $schema)
|
||||||
{
|
{
|
||||||
|
|
@ -177,7 +177,17 @@ class Form extends View {
|
||||||
$this->field[$name]->setValue($value);
|
$this->field[$name]->setValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute()
|
public function getSchema() {
|
||||||
|
return [
|
||||||
|
'field' => $this->field,
|
||||||
|
'fieldset' => $this->fieldsets,
|
||||||
|
'method' => $this->method,
|
||||||
|
'action' => $this->action,
|
||||||
|
'header' => $this->header
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute()
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue