FIX : select list dependencies now work for ModuleBuilder sellist field

This commit is contained in:
Florian HENRY 2021-03-02 14:06:11 +01:00
parent e1ff1c736c
commit 27c354567a

View File

@ -5878,6 +5878,7 @@ abstract class CommonObject
$out = ''; $out = '';
$type = ''; $type = '';
$isDependList=0;
$param = array(); $param = array();
$param['options'] = array(); $param['options'] = array();
$reg = array(); $reg = array();
@ -5916,6 +5917,7 @@ abstract class CommonObject
$type = $this->fields[$key]['type']; $type = $this->fields[$key]['type'];
} }
$label = $this->fields[$key]['label']; $label = $this->fields[$key]['label'];
//$elementtype=$this->fields[$key]['elementtype']; // Seems not used //$elementtype=$this->fields[$key]['elementtype']; // Seems not used
$default = $this->fields[$key]['default']; $default = $this->fields[$key]['default'];
@ -6058,7 +6060,6 @@ abstract class CommonObject
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
$keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid');
if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
if (strpos($InfoFieldList[4], 'extra.') !== false) { if (strpos($InfoFieldList[4], 'extra.') !== false) {
$keyList = 'main.'.$InfoFieldList[2].' as rowid'; $keyList = 'main.'.$InfoFieldList[2].' as rowid';
@ -6172,6 +6173,7 @@ abstract class CommonObject
if (!empty($InfoFieldList[3]) && $parentField) if (!empty($InfoFieldList[3]) && $parentField)
{ {
$parent = $parentName.':'.$obj->{$parentField}; $parent = $parentName.':'.$obj->{$parentField};
$isDependList=1;
} }
$out .= '<option value="'.$obj->rowid.'"'; $out .= '<option value="'.$obj->rowid.'"';
@ -6328,6 +6330,7 @@ abstract class CommonObject
if (!empty($InfoFieldList[3]) && $parentField) { if (!empty($InfoFieldList[3]) && $parentField) {
$parent = $parentName.':'.$obj->{$parentField}; $parent = $parentName.':'.$obj->{$parentField};
$isDependList=1;
} }
$data[$obj->rowid] = $labeltoshow; $data[$obj->rowid] = $labeltoshow;
@ -6414,6 +6417,10 @@ abstract class CommonObject
if (!empty($hidden)) { if (!empty($hidden)) {
$out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>';
} }
if ($isDependList==1) {
$out .= $this->getJSListDependancies('_common');
}
/* Add comments /* Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)'; if ($type == 'date') $out.=' (YYYY-MM-DD)';
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
@ -6981,10 +6988,27 @@ abstract class CommonObject
$out .= "\n"; $out .= "\n";
// Add code to manage list depending on others // Add code to manage list depending on others
if (!empty($conf->use_javascript_ajax)) { if (!empty($conf->use_javascript_ajax)) {
$out .= ' $out .= getJSListDependancies();
}
$out .= '<!-- /showOptionals --> '."\n";
}
}
$out .= $hookmanager->resPrint;
return $out;
}
/**
* @param string $type
* @return string
*/
public function getJSListDependancies($type='_extra') {
$out .= '
<script> <script>
jQuery(document).ready(function() { jQuery(document).ready(function() {
function showOptions(child_list, parent_list, orig_select) function showOptions'.$type.'(child_list, parent_list, orig_select)
{ {
var val = $("select[name=\""+parent_list+"\"]").val(); var val = $("select[name=\""+parent_list+"\"]").val();
var parentVal = parent_list + ":" + val; var parentVal = parent_list + ":" + val;
@ -6998,7 +7022,7 @@ abstract class CommonObject
$("select[name=\""+child_list+"\"]").append(options); $("select[name=\""+child_list+"\"]").append(options);
} }
} }
function setListDependencies() { function setListDependencies'.$type.'() {
jQuery("select option[parent]").parent().each(function() { jQuery("select option[parent]").parent().each(function() {
var orig_select = {}; var orig_select = {};
var child_list = $(this).attr("name"); var child_list = $(this).attr("name");
@ -7007,26 +7031,17 @@ abstract class CommonObject
var infos = parent.split(":"); var infos = parent.split(":");
var parent_list = infos[0]; var parent_list = infos[0];
$("select[name=\""+parent_list+"\"]").change(function() { $("select[name=\""+parent_list+"\"]").change(function() {
showOptions(child_list, parent_list, orig_select[child_list]); showOptions'.$type.'(child_list, parent_list, orig_select[child_list]);
}); });
}); });
} }
setListDependencies(); setListDependencies'.$type.'();
}); });
</script>'."\n"; </script>'."\n";
}
$out .= '<!-- /showOptionals --> '."\n";
}
}
$out .= $hookmanager->resPrint;
return $out; return $out;
} }
/** /**
* Returns the rights used for this class * Returns the rights used for this class
* @return stdClass * @return stdClass