Skip to content

Commit

Permalink
IKM : work on new extrafield separator type
Browse files Browse the repository at this point in the history
  • Loading branch information
jfefe committed Mar 15, 2013
1 parent b1d50e3 commit b36b776
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
27 changes: 21 additions & 6 deletions htdocs/core/class/extrafields.class.php
Expand Up @@ -64,7 +64,7 @@ class ExtraFields
'phone'=>'ExtrafieldPhone',
'mail'=>'ExtrafieldMail',
'select' => 'ExtrafieldSelect',
'separator' => 'ExtrafieldSeparator'
'separate' => 'ExtrafieldSeparator'
);

/**
Expand Down Expand Up @@ -103,14 +103,13 @@ function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $uni
if (empty($attrname)) return -1;
if (empty($label)) return -1;


// Create field into database except for separator type
if ($elementtype != 'separator')
// Create field into database except for separator type which is not stored in database
if ($type != 'separate')
{
$result=$this->create($attrname,$type,$size,$elementtype, $unique, $required, $default_value,$param);
}
$err1=$this->errno;
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $elementtype == 'separator')
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{
// Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param);
Expand Down Expand Up @@ -550,8 +549,13 @@ function fetch_name_optionals_label($elementtype='member',$forceload=false)
{
while ($tab = $this->db->fetch_object($resql))
{

// we can add this attribute to adherent object
$array_name_label[$tab->name]=$tab->label;
if ($tab->type != 'separate')
{
$array_name_label[$tab->name]=$tab->label;
}

$this->attribute_type[$tab->name]=$tab->type;
$this->attribute_label[$tab->name]=$tab->label;
$this->attribute_size[$tab->name]=$tab->size;
Expand Down Expand Up @@ -734,5 +738,16 @@ function showOutputField($key,$value,$moreparam='')
return $out;
}

/**
* Return HTML string to print separator extrafield
*
* @param string $key Key of attribute
* @return string
*/
function showSeparator($key)
{
$out = '<tr class="liste_titre"><td colspan="4"><strong>'.$this->attribute_label[$key].'</strong></td></tr>';
return $out;
}
}
?>
14 changes: 11 additions & 3 deletions htdocs/core/tpl/admin_extrafields_add.tpl.php
Expand Up @@ -25,11 +25,18 @@ function init_typeoffields(type)
var size = jQuery("#size");
var unique = jQuery("#unique");
var required = jQuery("#required");
var default_value = jQuery("#default_value");
<?php
if(!GETPOST('type') == "select")
if(GETPOST('type') != "select")
{
print 'jQuery("#value_choice").hide();';
}

if (GETPOST('type') == "separate")
{
print "jQuery('#size, #unique, #required, #default_value').val('').attr('disabled','disabled');";
print 'jQuery("#value_choice").hide();';
}
?>

if (type == 'date') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); }
Expand All @@ -41,6 +48,7 @@ function init_typeoffields(type)
else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();}
else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();}
else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();}
else if (type == 'separate') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); required.val('').attr('disabled','disabled'); default_value.val('').attr('disabled','disabled'); jQuery("#value_choice").hide();}
else size.val('').attr('disabled','disabled');
}
init_typeoffields('');
Expand All @@ -64,7 +72,7 @@ function init_typeoffields(type)
<!-- Label -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo GETPOST('label'); ?>"></td></tr>
<!-- Code -->
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?> (<?php echo $langs->trans("AlphaNumOnlyCharsAndNoSpace"); ?>)</td><td class="valeur"><input type="text" name="attrname" size="10" value="<?php echo GETPOST('attrname'); ?>"></td></tr>
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?> (<?php echo $langs->trans("AlphaNumOnlyCharsAndNoSpace"); ?>)</td><td class="valeur"><input type="text" name="attrname" id="attrname" size="10" value="<?php echo GETPOST('attrname'); ?>"></td></tr>
<!-- Value (for select list / radio) -->
<tr id="value_choice">
<td>
Expand All @@ -75,7 +83,7 @@ function init_typeoffields(type)
</td>
</tr>
<!-- 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>
<!-- Size -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size')?GETPOST('size'):''); ?>"></td></tr>
<!-- Unique -->
Expand Down

0 comments on commit b36b776

Please sign in to comment.