Fix modulebuilder

This commit is contained in:
Laurent Destailleur 2017-12-09 20:17:47 +01:00
parent f22e7ee24a
commit cc813df2a5
5 changed files with 64 additions and 23 deletions

View File

@ -95,7 +95,7 @@ if ($action != 'create' && $action != 'edit')
if ($action == 'create') if ($action == 'create')
{ {
print "<br>"; print '<div name="topofform"></div><br>';
print load_fiche_titre($langs->trans('NewAttribute')); print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
@ -108,7 +108,7 @@ if ($action == 'create')
/* ************************************************************************** */ /* ************************************************************************** */
if ($action == 'edit' && ! empty($attrname)) if ($action == 'edit' && ! empty($attrname))
{ {
print "<br>"; print '<div name="topofform"></div><br>';
print load_fiche_titre($langs->trans("FieldEdition", $attrname)); print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';

View File

@ -4761,12 +4761,17 @@ abstract class CommonObject
$objectid = $this->id; $objectid = $this->id;
$label=$val['label']; $label= $val['label'];
$type =$val['type']; $type = $val['type'];
$size =$val['css']; $size = $val['css'];
// Convert var to be able to share same code than showInputField of extrafields // Convert var to be able to share same code than showInputField of extrafields
if (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar if (preg_match('/varchar\((\d+)\)/', $type, $reg))
{
$type = 'varchar'; // convert varchar(xx) int varchar
$size = $reg[1];
}
elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
if (is_array($val['arrayofkeyval'])) $type='select'; if (is_array($val['arrayofkeyval'])) $type='select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
@ -4835,6 +4840,7 @@ abstract class CommonObject
} }
} }
} }
//var_dump($showsize.' '.$size);
if (in_array($type,array('date','datetime'))) if (in_array($type,array('date','datetime')))
{ {
@ -4864,6 +4870,12 @@ abstract class CommonObject
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
} }
elseif ($type == 'text') elseif ($type == 'text')
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,0,ROWS_5,'90%');
$out=$doleditor->Create(1);
}
elseif ($type == 'html')
{ {
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%');
@ -5287,12 +5299,17 @@ abstract class CommonObject
} }
$objectid = $this->id; $objectid = $this->id;
$label=$val['label']; $label = $val['label'];
$type =$val['type']; $type = $val['type'];
$size =$val['css']; $size = $val['css'];
// Convert var to be able to share same code than showOutputField of extrafields // Convert var to be able to share same code than showOutputField of extrafields
if (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar if (preg_match('/varchar\((\d+)\)/', $type, $reg))
{
$type = 'varchar'; // convert varchar(xx) int varchar
$size = $reg[1];
}
elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
if (is_array($val['arrayofkeyval'])) $type='select'; if (is_array($val['arrayofkeyval'])) $type='select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
@ -5327,20 +5344,42 @@ abstract class CommonObject
{ {
if ($type == 'date') if ($type == 'date')
{ {
$showsize=10; //$showsize=10;
$showsize = 'minwidth100imp';
} }
elseif ($type == 'datetime') elseif ($type == 'datetime')
{ {
$showsize=19; //$showsize=19;
$showsize = 'minwidth200imp';
} }
elseif ($type == 'int' || $type == 'integer') elseif (in_array($type,array('int','double','price')))
{ {
$showsize=10; //$showsize=10;
$showsize = 'maxwidth75';
}
elseif ($type == 'url')
{
$showsize='minwidth400';
}
elseif ($type == 'boolean')
{
$showsize='';
} }
else else
{ {
$showsize=round($size); if (round($size) < 12)
if ($showsize > 48) $showsize=48; {
$showsize = 'minwidth100';
}
else if (round($size) <= 48)
{
$showsize = 'minwidth200';
}
else
{
//$showsize=48;
$showsize = 'minwidth400';
}
} }
} }
@ -5581,7 +5620,7 @@ abstract class CommonObject
} }
} }
} }
elseif ($type == 'text') elseif ($type == 'text' || $type == 'html')
{ {
$value=dol_htmlentitiesbr($value); $value=dol_htmlentitiesbr($value);
} }

View File

@ -35,14 +35,14 @@ foreach($object->fields as $key => $val)
print '<td'; print '<td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull'] > 0) print ' fieldrequired'; if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text') print ' tdtop'; if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '"'; print '"';
print '>'; print '>';
print $langs->trans($val['label']); print $langs->trans($val['label']);
print '</td>'; print '</td>';
print '<td>'; print '<td>';
if (in_array($val['type'], array('int', 'integer'))) $value = GETPOST($key, 'int'); if (in_array($val['type'], array('int', 'integer'))) $value = GETPOST($key, 'int');
elseif ($val['type'] == 'text') $value = GETPOST($key, 'none'); elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOST($key, 'none');
else $value = GETPOST($key, 'alpha'); else $value = GETPOST($key, 'alpha');
print $object->showInputField($val, $key, $value, '', '', '', 0); print $object->showInputField($val, $key, $value, '', '', '', 0);
print '</td>'; print '</td>';

View File

@ -34,13 +34,14 @@ foreach($object->fields as $key => $val)
print '<tr><td'; print '<tr><td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull'] > 0) print ' fieldrequired'; if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text') print ' tdtop'; if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '"'; print '"';
print '>'.$langs->trans($val['label']).'</td>'; print '>'.$langs->trans($val['label']).'</td>';
print '<td>'; print '<td>';
if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key; if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key;
elseif ($val['type'] == 'text') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key; elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key;
else $value = GETPOSTISSET($key)?GETPOST($key, 'alpha'):$object->$key; else $value = GETPOSTISSET($key)?GETPOST($key, 'alpha'):$object->$key;
//var_dump($val.' '.$key.' '.$value);
print $object->showInputField($val, $key, $value, '', '', '', 0); print $object->showInputField($val, $key, $value, '', '', '', 0);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@ -78,8 +78,9 @@ class MyObject extends CommonObject
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'), 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'),
'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'), 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirparty'), 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirparty'),
'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>60), 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>61), 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502), //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),