From cd687f57d68a87d5462e41dd8f99db091e34c566 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 17 Mar 2016 21:58:51 +0100 Subject: [PATCH] NEW Can change type of extrafields for some combinations. --- htdocs/core/actions_extrafields.inc.php | 21 ++++- htdocs/core/tpl/admin_extrafields_add.tpl.php | 23 +++-- .../core/tpl/admin_extrafields_edit.tpl.php | 92 ++++++++++++++----- 3 files changed, 98 insertions(+), 38 deletions(-) diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index f31e2c184d8..6a162123ce0 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -41,10 +41,16 @@ if ($action == 'add') { $error++; $langs->load("errors"); - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->trans("Type")); + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); $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) { $error++; @@ -203,8 +209,15 @@ if ($action == 'update') { $error++; $langs->load("errors"); - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->trans("Type")); - $action = 'create'; + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); + $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) { diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 2b485f69fb9..25b86cdc0bf 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -30,6 +30,7 @@ jQuery(document).ready(function() { function init_typeoffields(type) { + console.log("select new type "+type); var size = jQuery("#size"); var unique = jQuery("#unique"); var required = jQuery("#required"); @@ -92,23 +93,21 @@ trans("Position"); ?> - trans("Value"); ?> - - -
- - -textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0)?> -textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0)?> -textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0)?> -textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0)?> -
+ + +
+ + + textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0)?> +
- trans("DefaultValue"); ?>"> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index b79fa539d2e..f12f90d6206 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -22,20 +22,45 @@ jQuery(document).ready(function() { function init_typeoffields(type) { + console.log("select new type "+type); var size = jQuery("#size"); var unique = jQuery("#unique"); var required = jQuery("#required"); - if (type == 'date') { size.prop('disabled', true); } - else if (type == 'datetime') { size.prop('disabled', true); } - else if (type == 'double') { size.removeAttr('disabled'); } - else if (type == 'int') { size.removeAttr('disabled'); } - else if (type == 'text') { size.removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); } - 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);} + var default_value = jQuery("#default_value"); + + + 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); } init_typeoffields(jQuery("#type").val()); + jQuery("#type").change(function() { + init_typeoffields($(this).val()); + }); }); @@ -85,33 +110,56 @@ elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') ) trans("AttributeCode"); ?> trans("Type"); ?> - - +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 ''; +} +else +{ + print $type2label[$type]; + print ''; +} +?> trans("Size"); ?> trans("Position"); ?> - trans("Value"); ?> - - -
- -textwithpicto('', $langs->trans("ExtrafieldParamHelp".$type),1,0)?>
+ + +
+ + + textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0)?> + textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0)?> +
- trans("Unique"); ?>>