Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Colorpicker label #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/label/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions lib/label/label_screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('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', ['pz_label', 'id='.$this->label->getId()]); // array("id"=>$this->label->getId())
Expand Down Expand Up @@ -143,9 +149,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();
Expand Down
88 changes: 88 additions & 0 deletions xform/value/class.xform.pz_color_screen.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* User: Jochen
* Date: 27.07.15
* Time: 23:03
*/

class rex_xform_pz_color_screen extends rex_xform_abstract
{
/**
* @see rex_xform_pz_color_screen::enterObject()
*
* @throws pz_exception
*/
public function enterObject()
{
$extra = $disabled = $after = $before = '';

if ($this->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) == '')?:
'<label'.$classes.' for="' . $this->getFieldId() . '">' . pz_i18n::translate($this->getElement(2)) . '</label>';

$field = '<input'.$classes.' id="'.$this->getFieldId().'" ';
$field .= 'type="color" name="'.$this->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()] .= '<script>
$(document).ready(function() {
pz_setEmailAutocomplete("#'.$html_id.' input");
});
</script>';

$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
}
}