Merge pull request #11111 from OPEN-DSI/new-extrafields-separator-collapse

NEW add extrafield separator collapsing capabilities
This commit is contained in:
Laurent Destailleur 2019-06-24 19:04:51 +02:00 committed by GitHub
commit 2a3b4c3fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 7 deletions

View File

@ -6381,6 +6381,7 @@ abstract class CommonObject
$out .= '<!-- showOptionalsInput --> ';
$out .= "\n";
$extrafields_collapse_num = '';
$e = 0;
foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
{
@ -6440,6 +6441,20 @@ abstract class CommonObject
if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
{
$extrafields_collapse_num = '';
$extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
if (!empty($extrafield_param) && is_array($extrafield_param)) {
$extrafield_param_list = array_keys($extrafield_param['options']);
if (count($extrafield_param_list)>0) {
$extrafield_collapse_display_value = intval($extrafield_param_list[0]);
if ($extrafield_collapse_display_value==1 || $extrafield_collapse_display_value==2) {
$extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
}
}
}
$out .= $extrafields->showSeparator($key, $this);
}
else
@ -6459,7 +6474,7 @@ abstract class CommonObject
$html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : '';
$out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >';
$out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.' trextrafields_collapse'.$extrafields_collapse_num.'" '.$domData.' >';
if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0)
{

View File

@ -1956,9 +1956,43 @@ class ExtraFields
{
global $langs;
$out = '<tr class="trextrafieldseparator trextrafieldseparator'.$key.'"><td colspan="2"><strong>';
$out = '<tr id="trextrafieldseparator'.$key.'" class="trextrafieldseparator trextrafieldseparator'.$key.'"><td colspan="2"><strong>';
$out.= $langs->trans($this->attributes[$object->table_element]['label'][$key]);
$out.= '</strong></td></tr>';
$extrafield_param = $this->attributes[$object->table_element]['param'][$key];
if (!empty($extrafield_param) && is_array($extrafield_param)) {
$extrafield_param_list = array_keys($extrafield_param['options']);
if (count($extrafield_param_list) > 0) {
$extrafield_collapse_display_value = intval($extrafield_param_list[0]);
if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
$collapse_display = ($extrafield_collapse_display_value == 2 ? false : true);
$extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key];
$out .= '<script type="text/javascript">';
$out .= 'jQuery(document).ready(function(){';
if ($collapse_display === false) {
$out .= ' jQuery("#trextrafieldseparator' . $key . ' td").prepend("<span class=\"cursorpointer fa fa-plus-square\"></span>&nbsp;");';
$out .= ' jQuery(".trextrafields_collapse' . $extrafields_collapse_num . '").hide();';
} else {
$out .= ' jQuery("#trextrafieldseparator' . $key . ' td").prepend("<span class=\"cursorpointer fa fa-minus-square\"></span>&nbsp;");';
}
$out .= ' jQuery("#trextrafieldseparator' . $key . '").click(function(){';
$out .= ' jQuery(".trextrafields_collapse' . $extrafields_collapse_num . '").toggle("slow", function(){';
$out .= ' if (jQuery(".trextrafields_collapse' . $extrafields_collapse_num . '").is(":hidden")) {';
$out .= ' jQuery("#trextrafieldseparator' . $key . ' td span").addClass("fa-plus-square").removeClass("fa-minus-square");';
$out .= ' } else {';
$out .= ' jQuery("#trextrafieldseparator' . $key . ' td span").addClass("fa-minus-square").removeClass("fa-plus-square");';
$out .= ' }';
$out .= ' });';
$out .= ' });';
$out .= '});';
$out .= '</script>';
}
}
}
return $out;
}

View File

@ -107,7 +107,7 @@ $langs->load("modulebuilder");
else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();jQuery("#helppassword").hide();}
else if (type == 'separate') {
langfile.val('').prop('disabled',true);size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true);
jQuery("#value_choice").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();
jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();
}
else { // type = string
size.val('').prop('disabled', true);

View File

@ -103,7 +103,7 @@ $langs->load("modulebuilder");
else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").show();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();jQuery("#helppassword").hide();}
else if (type == 'separate') { size.val('').prop('disabled', true); unique.removeAttr('checked').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();jQuery("#helppassword").hide();}
else if (type == 'separate') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();jQuery("#helppassword").hide();}
else { // type = string
size.val('').prop('disabled', true);
unique.removeAttr('disabled');
@ -173,7 +173,7 @@ if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_ar
}
}
}
elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($type == 'password'))
elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') || ($type == 'password') || ($type == 'separate'))
{
$paramlist=array_keys($param['options']);
$param_chain = $paramlist[0];

View File

@ -48,8 +48,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
//var_dump($extrafields->attributes[$object->table_element]);
if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]['label']))
{
$extrafields_collapse_num = '';
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
{
// Discard if extrafield is a hidden field on form
@ -86,11 +86,25 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]
}
if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate')
{
$extrafields_collapse_num = '';
$extrafield_param = $extrafields->attributes[$object->table_element]['param'][$key];
if (!empty($extrafield_param) && is_array($extrafield_param)) {
$extrafield_param_list = array_keys($extrafield_param['options']);
if (count($extrafield_param_list)>0) {
$extrafield_collapse_display_value = intval($extrafield_param_list[0]);
if ($extrafield_collapse_display_value==1 || $extrafield_collapse_display_value==2) {
$extrafields_collapse_num = $extrafields->attributes[$object->table_element]['pos'][$key];
}
}
}
print $extrafields->showSeparator($key, $object);
}
else
{
print '<tr>';
print '<tr class="trextrafields_collapse'.$extrafields_collapse_num.'">';
print '<td class="titlefield">';
print '<table width="100%" class="nobordernopadding">';
print '<tr>';