Factoring

This commit is contained in:
John BOTELLA 2021-10-31 09:29:20 +01:00
parent cdf1538ffa
commit ca766c2e71

View File

@ -63,11 +63,9 @@ class formSetup
*/ */
public function generateOutput($editMode = false) public function generateOutput($editMode = false)
{ {
$out = '';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$out.= '<input type="hidden" name="token" value="'.newToken().'">'; $out = '<input type="hidden" name="token" value="'.newToken().'">';
if ($editMode) { if ($editMode) {
$out .= '<input type="hidden" name="action" value="update">'; $out .= '<input type="hidden" name="action" value="update">';
} }
@ -168,7 +166,7 @@ class formSetup
*/ */
$item = new formSetupItem($confKey); $item = new formSetupItem($confKey);
$item->type = $params['type']; $item->setTypeFromTypeString($params['type']);
if (!empty($params['enabled'])) { if (!empty($params['enabled'])) {
$item->enabled = $params['enabled']; $item->enabled = $params['enabled'];
@ -186,7 +184,7 @@ class formSetup
/** /**
* used to export param array for /core/actions_setmoduleoptions.inc.php template * used to export param array for /core/actions_setmoduleoptions.inc.php template
* @return array $arrayofparameters for /core/actions_setmoduleoptions.inc.php * @return array $arrayofparameters for /core/actions_setmoduleoptions.inc.php
* @deprecated * @deprecated yes this method came deprecated because it exists only for manage setup convertion
*/ */
public function exportItemsAsParamsArray() public function exportItemsAsParamsArray()
{ {
@ -279,7 +277,7 @@ class formSetupItem
* And set var as protected when its done configuration must be done by method * And set var as protected when its done configuration must be done by method
* @var string $type 'string', 'textarea', 'category:'.Categorie::TYPE_CUSTOMER', 'emailtemplate', 'thirdparty_type' * @var string $type 'string', 'textarea', 'category:'.Categorie::TYPE_CUSTOMER', 'emailtemplate', 'thirdparty_type'
*/ */
public $type = 'string'; protected $type = 'string';
public $enabled = 1; public $enabled = 1;
@ -349,14 +347,12 @@ class formSetupItem
$out = ''; $out = '';
if ($this->type == 'textarea') { if ($this->type == 'title') {
$out.= '<textarea class="flat" name="'.$this->confKey.'" id="'.$this->confKey.'" cols="50" rows="5" wrap="soft">' . "\n"; $out.= $this->generateOutputField(); // title have no input
$out.= dol_htmlentities($this->fieldValue); } elseif ($this->type == 'textarea') {
$out.= "</textarea>\n"; $out.= $this->generateInputFieldTextarea();
} elseif ($this->type== 'html') { } elseif ($this->type== 'html') {
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $out.= $this->generateInputFieldHtml();
$doleditor = new DolEditor($this->confKey, $this->fieldValue, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
$doleditor->Create();
} elseif ($this->type == 'yesno') { } elseif ($this->type == 'yesno') {
$out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1); $out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
} elseif (preg_match('/emailtemplate:/', $this->type)) { } elseif (preg_match('/emailtemplate:/', $this->type)) {
@ -423,6 +419,42 @@ class formSetupItem
return $out; return $out;
} }
/**
* generate input field for textarea
* @return string
*/
public function generateInputFieldTextarea()
{
$out = '<textarea class="flat" name="'.$this->confKey.'" id="'.$this->confKey.'" cols="50" rows="5" wrap="soft">' . "\n";
$out.= dol_htmlentities($this->fieldValue);
$out.= "</textarea>\n";
return $out;
}
/**
* generate input field for html
* @return string
*/
public function generateInputFieldHtml()
{
global $conf;
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
$doleditor = new DolEditor($this->confKey, $this->fieldValue, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
return $doleditor->Create(1);
}
/**
* set the type from string : used for old module builder setup conf style conversion and tests
* because this two class will quickly evolve it's important to not set directly $this->type (will be protected) so this method exist
* to be sure we can manage evolution easily
* @param string $type possible values based on old module builder setup : 'string', 'textarea', 'category:'.Categorie::TYPE_CUSTOMER', 'emailtemplate', 'thirdparty_type'
* @deprecated yes this method came deprecated because it exists only for manage setup convertion
* @return bool
*/
public function setTypeFromTypeString($type)
{
$this->type = $type;
return true;
}
/** /**
* Add error * Add error
@ -459,7 +491,9 @@ class formSetupItem
$out = ''; $out = '';
if ($this->type == 'textarea') { if ($this->type == 'title') {
// nothing to do
} elseif ($this->type == 'textarea') {
$out.= dol_nl2br($this->fieldValue); $out.= dol_nl2br($this->fieldValue);
} elseif ($this->type== 'html') { } elseif ($this->type== 'html') {
$out.= $this->fieldValue; $out.= $this->fieldValue;
@ -609,4 +643,15 @@ class formSetupItem
$this->type = 'category:'.$catType; $this->type = 'category:'.$catType;
return $this; return $this;
} }
/**
* Set type of input as a simple title
* no data to store
* @return self
*/
public function setAsTitle()
{
$this->type = 'title';
return $this;
}
} }