From 72255a17c6fd8ec8ca7ef028399afee25f0aa61f Mon Sep 17 00:00:00 2001 From: Jochen Mandl Date: Mon, 27 Jul 2015 23:19:00 +0200 Subject: [PATCH 1/2] Colorpicker label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue xForm value für input color fields. --- lib/label/label.php | 5 ++ lib/label/label_screen.php | 15 +++- .../value/class.xform.pz_color_screen.inc.php | 88 +++++++++++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 xform/value/class.xform.pz_color_screen.inc.php diff --git a/lib/label/label.php b/lib/label/label.php index 5df892d..6e70770 100644 --- a/lib/label/label.php +++ b/lib/label/label.php @@ -2,7 +2,12 @@ class pz_label extends pz_model { + const COLOR = '#23b3db'; + + const BORDER = '#1699d6'; + public $vars = []; + public $isLabel = false; public static $var_labels = 6; diff --git a/lib/label/label_screen.php b/lib/label/label_screen.php index 872d7e3..0797307 100644 --- a/lib/label/label_screen.php +++ b/lib/label/label_screen.php @@ -91,10 +91,10 @@ public function getEditForm($p = []) $xform->setValueField('text', ['name', pz_i18n::msg('label_name')]); $xform->setValidateField('empty', ['name', pz_i18n::msg('error_label_name_empty')]); - $xform->setValueField('text', ['color', pz_i18n::msg('label_color')]); + $xform->setValueField('pz_color_screen', ['color', pz_i18n::msg('label_color')]); $xform->setValidateField('empty', ['color', pz_i18n::msg('error_label_color_empty')]); - $xform->setValueField('text', ['border', pz_i18n::msg('label_border')]); + $xform->setValueField('pz_color_screen', ['border', pz_i18n::msg('label_border')]); $xform->setValidateField('empty', ['border', pz_i18n::msg('error_label_bordercolor_empty')]); $xform->setActionField('db', ['pz_label', 'id='.$this->label->getId()]); // array("id"=>$this->label->getId()) @@ -143,9 +143,16 @@ public static function getAddForm($p = []) $xform->setValueField('objparams', ['fragment', 'pz_screen_xform.tpl']); $xform->setValueField('text', ['name', pz_i18n::msg('label_name')]); $xform->setValidateField('empty', ['name', pz_i18n::msg('error_label_name_empty')]); - $xform->setValueField('text', ['color', pz_i18n::msg('label_color')]); + + $xform->setValueField('pz_color_screen', + ['color', pz_i18n::msg('label_color'), 'default_color'=>pz_label::COLOR ] + ); + $xform->setValidateField('empty', ['color', pz_i18n::msg('error_label_color_empty')]); - $xform->setValueField('text', ['border', pz_i18n::msg('label_border')]); + + $xform->setValueField('pz_color_screen', + ['border', pz_i18n::msg('label_border'), 'default_color'=>pz_label::BORDER ] + ); $xform->setValidateField('empty', ['border', pz_i18n::msg('error_label_bordercolor_empty')]); $xform->setActionField('db', []); // array("id"=>$label_id) $return = $xform->getForm(); diff --git a/xform/value/class.xform.pz_color_screen.inc.php b/xform/value/class.xform.pz_color_screen.inc.php new file mode 100644 index 0000000..da8b7aa --- /dev/null +++ b/xform/value/class.xform.pz_color_screen.inc.php @@ -0,0 +1,88 @@ +getValue() == '' && !$this->params['send']) { + $this->setValue($this->getElement(3)); + } + + $class = $this->getHTMLClass(); + $classes = $class; + + if ($this->getElement(5) != '') { + $classes .= ' '.$this->getElement(5); + } + + if (isset($this->params['warning'][$this->getId()])) { + $classes .= ' '.$this->params['warning'][$this->getId()]; + } + + $classes = (trim($classes) != '') ? ' class="'.trim($classes).'"' : ''; + + if ($this->getElement('disabled')) { + $disabled = ' disabled="disabled"'; + } + + $value = htmlspecialchars(stripslashes($this->getValue())); + if ($this->getElement('default_color') && !$this->getValue()) { + $value = htmlspecialchars(stripslashes($this->getElement('default_color'))); + } + + + $label = ($this->getElement(2) == '')?: + '' . pz_i18n::translate($this->getElement(2)) . ''; + + $field = 'getFieldName().'" value="'.$value.'"'.$disabled.' />'; + + $html_id = $this->getHTMLId(); + $name = $this->getName(); + + $f = new pz_fragment(); + + $f->setVar('before', $before, false); + $f->setVar('after', $after, false); + $f->setVar('label', $label, false); + $f->setVar('field', $field, false); + $f->setVar('extra', $extra, false); + $f->setVar('html_id', $html_id, false); + $f->setVar('name', $name, false); + $f->setVar('class', $class, false); + + $fragment = $this->params['fragment']; + $this->params['form_output'][$this->getId()] = $f->parse($fragment); + + $this->params['form_output'][$this->getId()] .= ''; + + $this->params['value_pool']['email'][$this->getElement(1)] = stripslashes($this->getValue()); + if ($this->getElement(4) != 'no_db') { + $this->params['value_pool']['sql'][$this->getElement(1)] = $this->getValue(); + } + } + + /** + * @see rex_xform_pz_color_screen::getDescription() + */ + public function getDescription() + { + // do nothing + } +} From 5184cd8c36aed73e7e7baded9de18533cad27c6e Mon Sep 17 00:00:00 2001 From: Jochen Mandl Date: Mon, 27 Jul 2015 23:19:39 +0200 Subject: [PATCH 2/2] =?UTF-8?q?label=20default=20f=C3=BCr=20edit=20Form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/label/label_screen.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/label/label_screen.php b/lib/label/label_screen.php index 0797307..6d3d8ad 100644 --- a/lib/label/label_screen.php +++ b/lib/label/label_screen.php @@ -91,10 +91,16 @@ public function getEditForm($p = []) $xform->setValueField('text', ['name', pz_i18n::msg('label_name')]); $xform->setValidateField('empty', ['name', pz_i18n::msg('error_label_name_empty')]); - $xform->setValueField('pz_color_screen', ['color', pz_i18n::msg('label_color')]); + $xform->setValueField('pz_color_screen', + ['color', pz_i18n::msg('label_color'), 'default_color'=>pz_label::COLOR] + ); + $xform->setValidateField('empty', ['color', pz_i18n::msg('error_label_color_empty')]); - $xform->setValueField('pz_color_screen', ['border', pz_i18n::msg('label_border')]); + $xform->setValueField('pz_color_screen', + ['border', pz_i18n::msg('label_border'), 'default_color'=>pz_label::BORDER] + ); + $xform->setValidateField('empty', ['border', pz_i18n::msg('error_label_bordercolor_empty')]); $xform->setActionField('db', ['pz_label', 'id='.$this->label->getId()]); // array("id"=>$this->label->getId())