NEW Can change type of extrafields for some combinations.
This commit is contained in:
parent
dfcd72399a
commit
cd687f57d6
@ -41,10 +41,16 @@ if ($action == 'add')
|
|||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
|
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"));
|
||||||
$action = 'create';
|
$action = 'create';
|
||||||
}
|
}
|
||||||
|
if (GETPOST('type')=='varchar' && $extrasize <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$langs->load("errors");
|
||||||
|
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size"));
|
||||||
|
$action = 'edit';
|
||||||
|
}
|
||||||
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
|
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@ -203,8 +209,15 @@ if ($action == 'update')
|
|||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
|
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"));
|
||||||
$action = 'create';
|
$action = 'edit';
|
||||||
|
}
|
||||||
|
if (GETPOST('type')=='varchar' && $extrasize <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$langs->load("errors");
|
||||||
|
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size"));
|
||||||
|
$action = 'edit';
|
||||||
}
|
}
|
||||||
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
|
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
function init_typeoffields(type)
|
function init_typeoffields(type)
|
||||||
{
|
{
|
||||||
|
console.log("select new type "+type);
|
||||||
var size = jQuery("#size");
|
var size = jQuery("#size");
|
||||||
var unique = jQuery("#unique");
|
var unique = jQuery("#unique");
|
||||||
var required = jQuery("#required");
|
var required = jQuery("#required");
|
||||||
@ -92,7 +93,6 @@
|
|||||||
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
|
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
|
||||||
<!-- Default Value (for select list / radio/ checkbox) -->
|
<!-- Default Value (for select list / radio/ checkbox) -->
|
||||||
<tr id="value_choice">
|
<tr id="value_choice">
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<?php echo $langs->trans("Value"); ?>
|
<?php echo $langs->trans("Value"); ?>
|
||||||
</td>
|
</td>
|
||||||
@ -108,7 +108,6 @@
|
|||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<!-- Default Value -->
|
<!-- Default Value -->
|
||||||
<tr><td><?php echo $langs->trans("DefaultValue"); ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
|
<tr><td><?php echo $langs->trans("DefaultValue"); ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
|
||||||
|
|||||||
@ -22,20 +22,45 @@
|
|||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
function init_typeoffields(type)
|
function init_typeoffields(type)
|
||||||
{
|
{
|
||||||
|
console.log("select new type "+type);
|
||||||
var size = jQuery("#size");
|
var size = jQuery("#size");
|
||||||
var unique = jQuery("#unique");
|
var unique = jQuery("#unique");
|
||||||
var required = jQuery("#required");
|
var required = jQuery("#required");
|
||||||
if (type == 'date') { size.prop('disabled', true); }
|
var default_value = jQuery("#default_value");
|
||||||
else if (type == 'datetime') { size.prop('disabled', true); }
|
<?php
|
||||||
else if (type == 'double') { size.removeAttr('disabled'); }
|
if((GETPOST('type') != "select") && (GETPOST('type') != "sellist"))
|
||||||
else if (type == 'int') { size.removeAttr('disabled'); }
|
{
|
||||||
else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); }
|
print 'jQuery("#value_choice").hide();';
|
||||||
else if (type == 'varchar') { size.removeAttr('disabled'); }
|
}
|
||||||
else if (type == 'boolean') { size.val('').prop('disabled', true); unique.prop('disabled', true);}
|
|
||||||
else if (type == 'price') { size.val('').prop('disabled', true); unique.prop('disabled', true);}
|
if (GETPOST('type') == "separate")
|
||||||
|
{
|
||||||
|
print "jQuery('#size, #unique, #required, #default_value').val('').prop('disabled', true);";
|
||||||
|
print 'jQuery("#value_choice").hide();';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
|
||||||
|
else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
|
||||||
|
else if (type == 'double') { size.removeAttr('disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
|
||||||
|
else if (type == 'int') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
|
||||||
|
else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
|
||||||
|
else if (type == 'varchar') { size.removeAttr('disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
|
||||||
|
else if (type == 'boolean') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();}
|
||||||
|
else if (type == 'price') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();}
|
||||||
|
else if (type == 'select') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
|
||||||
|
else if (type == 'link') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();}
|
||||||
|
else if (type == 'sellist') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
|
||||||
|
else if (type == 'radio') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
|
||||||
|
else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
|
||||||
|
else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").show();jQuery("#helplink").hide();}
|
||||||
|
else if (type == 'separate') { size.val('').prop('disabled', true); unique.prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
|
||||||
else size.val('').prop('disabled', true);
|
else size.val('').prop('disabled', true);
|
||||||
}
|
}
|
||||||
init_typeoffields(jQuery("#type").val());
|
init_typeoffields(jQuery("#type").val());
|
||||||
|
jQuery("#type").change(function() {
|
||||||
|
init_typeoffields($(this).val());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -85,18 +110,39 @@ elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') )
|
|||||||
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
|
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><?php echo $attrname; ?></td></tr>
|
||||||
<!-- Type -->
|
<!-- Type -->
|
||||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
|
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
|
||||||
<?php print $type2label[$type]; ?>
|
<?php
|
||||||
<input type="hidden" name="type" id="type" value="<?php print $type; ?>">
|
// Define list of possible type transition
|
||||||
|
$typewecanchangeinto=array(
|
||||||
|
'varchar'=>array('varchar', 'phone', 'mail', 'select'),
|
||||||
|
'mail'=>array('varchar', 'phone', 'mail', 'select'),
|
||||||
|
'phone'=>array('varchar', 'phone', 'mail', 'select'),
|
||||||
|
'select'=>array('varchar', 'phone', 'mail', 'select')
|
||||||
|
);
|
||||||
|
if (in_array($type, array_keys($typewecanchangeinto)))
|
||||||
|
{
|
||||||
|
$newarray=array();
|
||||||
|
print '<select id="type" class="flat type" name="type">';
|
||||||
|
foreach($type2label as $key => $val)
|
||||||
|
{
|
||||||
|
$selected='';
|
||||||
|
if ($key == (GETPOST('type')?GETPOST('type'):$type)) $selected=' selected="selected"';
|
||||||
|
if (in_array($key, $typewecanchangeinto[$type])) print '<option value="'.$key.'"'.$selected.'>'.$val.'</option>';
|
||||||
|
else print '<option value="'.$key.'" disabled="disabled"'.$selected.'>'.$val.'</option>';
|
||||||
|
}
|
||||||
|
print '</select>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $type2label[$type];
|
||||||
|
print '<input type="hidden" name="type" id="type" value="'.$type.'">';
|
||||||
|
}
|
||||||
|
?>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<!-- Size -->
|
<!-- Size -->
|
||||||
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
|
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
|
||||||
<!-- Position -->
|
<!-- Position -->
|
||||||
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo $extrafields->attribute_pos[$attrname]; ?>"></td></tr>
|
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo $extrafields->attribute_pos[$attrname]; ?>"></td></tr>
|
||||||
<!-- Value (for select list / radio) -->
|
<!-- Value (for select list / radio) -->
|
||||||
<?php
|
|
||||||
if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') || ($type == 'chkbxlst') || ($type == 'radio') || ($type == 'link'))
|
|
||||||
{
|
|
||||||
?>
|
|
||||||
<tr id="value_choice">
|
<tr id="value_choice">
|
||||||
<td>
|
<td>
|
||||||
<?php echo $langs->trans("Value"); ?>
|
<?php echo $langs->trans("Value"); ?>
|
||||||
@ -105,13 +151,15 @@ if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') || ($typ
|
|||||||
<table class="nobordernopadding">
|
<table class="nobordernopadding">
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<textarea name="param" id="param" cols="80" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($param_chain); ?></textarea>
|
<textarea name="param" id="param" cols="80" rows="<?php echo ROWS_4 ?>"><?php echo dol_htmlcleanlastbr($param_chain); ?></textarea>
|
||||||
</td><td><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelp".$type),1,0)?></td></tr>
|
</td><td>
|
||||||
|
<span id="helpselect"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0)?></span>
|
||||||
|
<span id="helpsellist"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0)?></span>
|
||||||
|
<span id="helpchkbxlst"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0)?></span>
|
||||||
|
<span id="helplink"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0)?></span>
|
||||||
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<!-- Unique -->
|
<!-- Unique -->
|
||||||
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique" <?php echo ($unique?' checked':''); ?>></td></tr>
|
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique" <?php echo ($unique?' checked':''); ?>></td></tr>
|
||||||
<!-- Required -->
|
<!-- Required -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user