From: Andrey Kutejko Date: Sun, 14 Dec 2014 12:43:53 +0000 (+0200) Subject: admin fields and widgets X-Git-Tag: 0.6~121 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=f2f9d290166e6c2386819b5f6d54fcc7065727fd;p=ipf.git admin fields and widgets --- diff --git a/ipf/admin/form/fields/html.php b/ipf/admin/form/fields/html.php new file mode 100644 index 0000000..52a5f01 --- /dev/null +++ b/ipf/admin/form/fields/html.php @@ -0,0 +1,7 @@ +orderBy; + return parent::createWidget($args); + } +} + diff --git a/ipf/admin/form/layout.php b/ipf/admin/form/layout.php new file mode 100644 index 0000000..97072db --- /dev/null +++ b/ipf/admin/form/layout.php @@ -0,0 +1,57 @@ +commonErrors($form); + return $this->errors($errors) . + $this->hiddenWidgets($form); + } + + public function startGroup($label) + { + if ($label) + return Tag::div(array('class' => 'form-group-title'), $label)->html(); + else + return ''; + } + + public function field($boundField, $errors) + { + if ($boundField->help_text) { + $help_text = Tag::p(array('class' => 'help')) + ->raw($boundField->help_text); + } else { + $help_text = ''; + } + + if ($boundField->field instanceof IPF_Form_Field_Set) { + return $this->errors($errors) . + Tag::div() + ->raw($boundField->renderWidget()) + ->append($help_text); + } else { + return $this->errors($errors) . + Tag::div(array('class' => 'form-row')) + ->raw($boundField->renderLabel()) + ->append(Tag::div() + ->raw($boundField->renderWidget()) + ->append($help_text)); + } + } + + private function errors($errors) + { + if (!count($errors)) + return ''; + + $ul = Tag::ul(array('class' => 'errorlist')); + foreach ($errors as $err) + $ul->append(Tag::li(null, $err->message)); + return Tag::div(array('class' => 'form-row'), $ul); + } +} + diff --git a/ipf/admin/form/widgets/htmlinput.php b/ipf/admin/form/widgets/htmlinput.php new file mode 100644 index 0000000..30d17b8 --- /dev/null +++ b/ipf/admin/form/widgets/htmlinput.php @@ -0,0 +1,113 @@ +tinymce_url = \PFF\Arr::pop($attrs, 'tinymce_url', + IPF::get('tiny_mce_url', + IPF::get('static_url').'admin/tinymce/')); + + $this->force_absolute_urls = \PFF\Arr::pop($attrs, 'force_absolute_urls', false); + $this->editor_config = \PFF\Arr::pop($attrs, 'editor_config', array()); + + parent::__construct($attrs); + } + + public function render($name, $value, $extra_attrs=array()) + { + if ($value === null) $value = ''; + + $extra_config = ''; + foreach ($this->editor_config as $key => $val) { + $extra_config .= ",\n{$key} : "; + if (is_bool($val)) { + $extra_config .= $val ? 'true' : 'false'; + } else { + $extra_config .= '"'.$val.'"'; + } + } + + return Tag::textarea() + ->attr('cols', 70) + ->attr('rows', 20) + ->attrs($this->attrs) + ->attrs($extra_attrs) + ->attr('name', $name) + ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor') + ->append($value) + ->html(); + } + + public function extra_js() + { + $filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/')); + return array( + '', + '', + ); + } +} + diff --git a/ipf/admin/form/widgets/orderedsettable.php b/ipf/admin/form/widgets/orderedsettable.php new file mode 100644 index 0000000..1bbd432 --- /dev/null +++ b/ipf/admin/form/widgets/orderedsettable.php @@ -0,0 +1,80 @@ +orderBy = \PFF\Arr::pop($attrs, 'orderBy'); + parent::__construct($attrs); + } + + public function render($name, $value, $extra_attrs=array()) + { + if (array_key_exists('class', $extra_attrs)) + $extra_attrs['class'] .= ' orderable-set-table'; + else + $extra_attrs['class'] = 'orderable-set-table'; + + $extra_attrs['data-reorder'] = $name.'[reorder]'; + + return parent::render($name, $value, $extra_attrs); + } + + protected function renderRow($prefix, $obj, $errors, $index) + { + $tr = parent::renderRow($prefix, $obj, $errors, $index); + + if (array_key_exists('id', $obj)) + $tr->attr('data-id', $obj['id']); + else + $tr->addClass('nodrag')->addClass('nodrop'); + + return $tr; + } + + public function extra_js() + { + $js = parent::extra_js(); + + $js[] = ''; + $js[] = ''; + return $js; + } + + public function valueFromFormData($name, $data) + { + if (!isset($data[$name])) + return null; + + $value = $data[$name]; + $reorder = \PFF\Arr::pop($value, 'reorder'); + $data[$name] = $value; + + $value = parent::valueFromFormData($name, $data); + $value['reorder'] = $reorder; + + return $value; + } +} + diff --git a/ipf/admin/formlayout.php b/ipf/admin/formlayout.php deleted file mode 100644 index 97072db..0000000 --- a/ipf/admin/formlayout.php +++ /dev/null @@ -1,57 +0,0 @@ -commonErrors($form); - return $this->errors($errors) . - $this->hiddenWidgets($form); - } - - public function startGroup($label) - { - if ($label) - return Tag::div(array('class' => 'form-group-title'), $label)->html(); - else - return ''; - } - - public function field($boundField, $errors) - { - if ($boundField->help_text) { - $help_text = Tag::p(array('class' => 'help')) - ->raw($boundField->help_text); - } else { - $help_text = ''; - } - - if ($boundField->field instanceof IPF_Form_Field_Set) { - return $this->errors($errors) . - Tag::div() - ->raw($boundField->renderWidget()) - ->append($help_text); - } else { - return $this->errors($errors) . - Tag::div(array('class' => 'form-row')) - ->raw($boundField->renderLabel()) - ->append(Tag::div() - ->raw($boundField->renderWidget()) - ->append($help_text)); - } - } - - private function errors($errors) - { - if (!count($errors)) - return ''; - - $ul = Tag::ul(array('class' => 'errorlist')); - foreach ($errors as $err) - $ul->append(Tag::li(null, $err->message)); - return Tag::div(array('class' => 'form-row'), $ul); - } -} - diff --git a/ipf/form/field/html.php b/ipf/form/field/html.php deleted file mode 100644 index 6c44320..0000000 --- a/ipf/form/field/html.php +++ /dev/null @@ -1,7 +0,0 @@ -orderBy; - return parent::createWidget($args); - } -} - diff --git a/ipf/form/field/varchar.php b/ipf/form/field/varchar.php index 57078d6..4ff45b4 100644 --- a/ipf/form/field/varchar.php +++ b/ipf/form/field/varchar.php @@ -24,7 +24,7 @@ class IPF_Form_Field_Varchar extends IPF_Form_Field protected function createWidget($args) { - if ($this->max_length > 255 && $this->widget !== 'IPF_Form_Widget_HTMLInput') { + if ($this->max_length > 255 && $this->widget === 'IPF_Form_Widget_TextInput') { $widgetClass = 'IPF_Form_Widget_TextareaInput'; } else { $widgetClass = $this->widget; diff --git a/ipf/form/widget/htmlinput.php b/ipf/form/widget/htmlinput.php deleted file mode 100644 index e872198..0000000 --- a/ipf/form/widget/htmlinput.php +++ /dev/null @@ -1,113 +0,0 @@ -tinymce_url = \PFF\Arr::pop($attrs, 'tinymce_url', - IPF::get('tiny_mce_url', - IPF::get('static_url').'admin/tinymce/')); - - $this->force_absolute_urls = \PFF\Arr::pop($attrs, 'force_absolute_urls', false); - $this->editor_config = \PFF\Arr::pop($attrs, 'editor_config', array()); - - parent::__construct($attrs); - } - - public function render($name, $value, $extra_attrs=array()) - { - if ($value === null) $value = ''; - - $extra_config = ''; - foreach ($this->editor_config as $key => $val) { - $extra_config .= ",\n{$key} : "; - if (is_bool($val)) { - $extra_config .= $val ? 'true' : 'false'; - } else { - $extra_config .= '"'.$val.'"'; - } - } - - return Tag::textarea() - ->attr('cols', 70) - ->attr('rows', 20) - ->attrs($this->attrs) - ->attrs($extra_attrs) - ->attr('name', $name) - ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor') - ->append($value) - ->html(); - } - - public function extra_js() - { - $filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/')); - return array( - '', - '', - ); - } -} - diff --git a/ipf/form/widget/orderedsettable.php b/ipf/form/widget/orderedsettable.php deleted file mode 100644 index 60ca43c..0000000 --- a/ipf/form/widget/orderedsettable.php +++ /dev/null @@ -1,80 +0,0 @@ -orderBy = \PFF\Arr::pop($attrs, 'orderBy'); - parent::__construct($attrs); - } - - public function render($name, $value, $extra_attrs=array()) - { - if (array_key_exists('class', $extra_attrs)) - $extra_attrs['class'] .= ' orderable-set-table'; - else - $extra_attrs['class'] = 'orderable-set-table'; - - $extra_attrs['data-reorder'] = $name.'[reorder]'; - - return parent::render($name, $value, $extra_attrs); - } - - protected function renderRow($prefix, $obj, $errors, $index) - { - $tr = parent::renderRow($prefix, $obj, $errors, $index); - - if (array_key_exists('id', $obj)) - $tr->attr('data-id', $obj['id']); - else - $tr->addClass('nodrag')->addClass('nodrop'); - - return $tr; - } - - public function extra_js() - { - $js = parent::extra_js(); - - $js[] = ''; - $js[] = ''; - return $js; - } - - public function valueFromFormData($name, $data) - { - if (!isset($data[$name])) - return null; - - $value = $data[$name]; - $reorder = \PFF\Arr::pop($value, 'reorder'); - $data[$name] = $value; - - $value = parent::valueFromFormData($name, $data); - $value['reorder'] = $reorder; - - return $value; - } -} -