John BOTELLA 3 lat temu
rodzic
commit
321195ef96

+ 73 - 10
htdocs/core/class/html.formsetup.class.php

@@ -422,7 +422,7 @@ class FormSetup
 
 		if (!array($this->items)) { return false; }
 		foreach ($this->items as $item) {
-			$item->reloadValueFromConf();
+			$item->loadValueFromConf();
 		}
 
 		return true;
@@ -587,8 +587,11 @@ class FormSetupItem
 	/** @var string $fieldValue  */
 	public $fieldValue;
 
+	/** @var string $defaultFieldValue  */
+	public $defaultFieldValue = null;
+
 	/** @var array $fieldAttr  fields attribute only for compatible fields like input text */
-	public $fieldAttr;
+	public $fieldAttr = array();
 
 	/** @var bool|string set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too */
 	public $fieldOverride = false;
@@ -648,17 +651,33 @@ class FormSetupItem
 		$this->entity = $conf->entity;
 
 		$this->confKey = $confKey;
-		$this->fieldValue = $conf->global->{$this->confKey};
+		$this->loadValueFromConf();
 	}
 
 	/**
-	 * reload conf value from databases
-	 * @return null
+	 * load conf value from databases
+	 * @return bool
 	 */
-	public function reloadValueFromConf()
+	public function loadValueFromConf()
 	{
 		global $conf;
-		$this->fieldValue = $conf->global->{$this->confKey};
+		if (isset($conf->global->{$this->confKey})) {
+			$this->fieldValue = $conf->global->{$this->confKey};
+			return true;
+		} else {
+			$this->fieldValue = null;
+			return false;
+		}
+	}
+
+	/**
+	 * reload conf value from databases is an aliase of loadValueFromConf
+	 * @deprecated
+	 * @return bool
+	 */
+	public function reloadValueFromConf()
+	{
+		return $this->loadValueFromConf();
 	}
 
 
@@ -791,6 +810,12 @@ class FormSetupItem
 			return $this->fieldInputOverride;
 		}
 
+		// Set default value
+		if (is_null($this->fieldValue)) {
+			$this->fieldValue = $this->defaultFieldValue;
+		}
+
+
 		$this->fieldAttr['name'] = $this->confKey;
 		$this->fieldAttr['id'] = 'setup-'.$this->confKey;
 		$this->fieldAttr['value'] = $this->fieldValue;
@@ -807,6 +832,8 @@ class FormSetupItem
 			$out.= $this->generateInputFieldTextarea();
 		} elseif ($this->type== 'html') {
 			$out.= $this->generateInputFieldHtml();
+		} elseif ($this->type== 'color') {
+			$out.=  $this->generateInputFieldColor();
 		} elseif ($this->type == 'yesno') {
 			$out.= $this->form->selectyesno($this->confKey, $this->fieldValue, 1);
 		} elseif (preg_match('/emailtemplate:/', $this->type)) {
@@ -825,14 +852,22 @@ class FormSetupItem
 				$out.= $this->form->select_produits($selected, $this->confKey, '', 0, 0, 1, 2, '', 0, array(), 0, '1', 0, $this->cssClass, 0, '', null, 1);
 			}
 		} else {
-			if (empty($this->fieldAttr)) { $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth200' : $this->cssClass); }
-
-			$out.= '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' />';
+			$out.= $this->generateInputFieldText();
 		}
 
 		return $out;
 	}
 
+	/**
+	 * generatec default input field
+	 * @return string
+	 */
+	public function generateInputFieldText()
+	{
+		if (empty($this->fieldAttr)) { $this->fieldAttr['class'] = 'flat '.(empty($this->cssClass) ? 'minwidth200' : $this->cssClass); }
+		return '<input '.FormSetup::generateAttributesStringFromArray($this->fieldAttr).' />';
+	}
+
 	/**
 	 * generate input field for textarea
 	 * @return string
@@ -1029,6 +1064,8 @@ class FormSetupItem
 			$out.= $this->generateOutputFieldSelect();
 		} elseif ($this->type== 'html') {
 			$out.=  $this->fieldValue;
+		} elseif ($this->type== 'color') {
+			$out.=  $this->generateOutputFieldColor();
 		} elseif ($this->type == 'yesno') {
 			$out.= ajax_constantonoff($this->confKey);
 		} elseif (preg_match('/emailtemplate:/', $this->type)) {
@@ -1102,6 +1139,22 @@ class FormSetupItem
 		return $outPut;
 	}
 
+	/**
+	 * @return string
+	 */
+	public function generateOutputFieldColor()
+	{
+		$this->fieldAttr['disabled']=null;
+		return $this->generateInputField();
+	}
+	/**
+	 * @return string
+	 */
+	public function generateInputFieldColor()
+	{
+		$this->fieldAttr['type']= 'color';
+		return $this->generateInputFieldText();
+	}
 
 	/**
 	 * @return string
@@ -1130,6 +1183,16 @@ class FormSetupItem
 		return $this;
 	}
 
+	/**
+	 * Set type of input as color
+	 * @return self
+	 */
+	public function setAsColor()
+	{
+		$this->type = 'color';
+		return $this;
+	}
+
 	/**
 	 * Set type of input as textarea
 	 * @return self

+ 1 - 1
htdocs/modulebuilder/index.php

@@ -240,7 +240,7 @@ if ($dirins && $action == 'initmodule' && $modulename) {
 
 		// Copy last html.formsetup.class.php' to backport folder
 		$tryToCopyFromSetupClass = true;
-		$backportDest = $destdir .'/backport/v17/core/class';
+		$backportDest = $destdir .'/backport/v16/core/class';
 		$backportFileSrc = DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
 		$backportFileDest = $backportDest.'/html.formsetup.class.php';
 		$result = dol_mkdir($backportDest);

+ 16 - 1
htdocs/modulebuilder/template/admin/setup.php

@@ -88,7 +88,7 @@ $useFormSetup = 1;
 if (!class_exists('FormSetup')) {
 	// For retrocompatibility Dolibarr < 16.0
 	if (floatval(DOL_VERSION) < 16.0 && !class_exists('FormSetup')) {
-		require_once __DIR__.'/../backport/v17/core/class/html.formsetup.class.php';
+		require_once __DIR__.'/../backport/v16/core/class/html.formsetup.class.php';
 	} else {
 		require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
 	}
@@ -104,6 +104,7 @@ $item->cssClass = 'minwidth500';
 
 // Setup conf MYMODULE_MYPARAM1 as a simple string input
 $item = $formSetup->newItem('MYMODULE_MYPARAM1');
+$item->defaultFieldValue = 'default value';
 
 // Setup conf MYMODULE_MYPARAM1 as a simple textarea input but we replace the text of field title
 $item = $formSetup->newItem('MYMODULE_MYPARAM2');
@@ -145,6 +146,20 @@ $item->helpText = $langs->transnoentities('MYMODULE_MYPARAM8');
 $formSetup->newItem('MYMODULE_MYPARAM9')->setAsSelect($TField);
 
 
+// Setup conf MYMODULE_MYPARAM10
+$item = $formSetup->newItem('MYMODULE_MYPARAM10');
+$item->setAsColor();
+$item->defaultFieldValue = '#FF0000';
+$item->nameText = $item->getNameText().' more html text ';
+$item->fieldInputOverride = '';
+$item->helpText = $langs->transnoentities('AnHelpMessage');
+//$item->fieldValue = '';
+//$item->fieldAttr = array() ; // fields attribute only for compatible fields like input text
+//$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too
+//$item->fieldInputOverride = false; // set this var to override field input
+//$item->fieldOutputOverride = false; // set this var to override field output
+
+
 $setupnotempty =+ count($formSetup->items);