Clean import process
This commit is contained in:
parent
50b4eaf82f
commit
5ccf4145e3
@ -1002,7 +1002,7 @@ if ($step == 4 && $datatoimport) {
|
||||
print $s;
|
||||
print '</span> ';
|
||||
$htmlother->select_import_model($importmodelid, 'importmodelid', $datatoimport, 1, $user->id);
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
|
||||
print '<input type="submit" class="button small reposition" value="'.$langs->trans("Select").'">';
|
||||
print '</div>';
|
||||
print '</form>';
|
||||
|
||||
@ -1016,7 +1016,7 @@ if ($step == 4 && $datatoimport) {
|
||||
|
||||
//var_dump($array_match_file_to_database);
|
||||
|
||||
print '<tr valign="top"><td width="50%" class="nopaddingleftimp nopaddingrightimp">';
|
||||
print '<tr valign="top"><td width="50%" class="nopaddingleftimp">';
|
||||
|
||||
$fieldsplaced = array();
|
||||
$valforsourcefieldnb = array();
|
||||
@ -1034,7 +1034,6 @@ if ($step == 4 && $datatoimport) {
|
||||
foreach ($fieldssource as $key => $val) {
|
||||
$var = !$var;
|
||||
show_elem($fieldssource, $key, $val, $var); // key is field number in source file
|
||||
//print '> '.$lefti.'-'.$key.'-'.$val;
|
||||
$listofkeys[$key] = 1;
|
||||
$fieldsplaced[$key] = 1;
|
||||
$valforsourcefieldnb[$lefti] = $key;
|
||||
@ -1046,39 +1045,26 @@ if ($step == 4 && $datatoimport) {
|
||||
}
|
||||
//var_dump($valforsourcefieldnb);
|
||||
|
||||
// Complete source fields from count($fieldssource)+1 to count($fieldstarget)
|
||||
/*
|
||||
$more = 1;
|
||||
$num = count($fieldssource);
|
||||
while ($lefti <= $num) {
|
||||
$var = !$var;
|
||||
$newkey = getnewkey($fieldssource, $listofkeys);
|
||||
show_elem($fieldssource, $newkey, '', $var); // key start after field number in source file
|
||||
//print '> '.$lefti.'-'.$newkey;
|
||||
$listofkeys[$key] = 1;
|
||||
$lefti++;
|
||||
$more++;
|
||||
}
|
||||
*/
|
||||
|
||||
print "</div>\n";
|
||||
print "<!-- End box left container -->\n";
|
||||
|
||||
|
||||
print '</td><td width="50%" class="nopaddingleftimp nopaddingrightimp">';
|
||||
print '</td><td width="50%" class="nopaddingrightimp">';
|
||||
|
||||
// List of target fields
|
||||
$optionsnotused = "";
|
||||
$optionsall = array();
|
||||
foreach ($fieldstarget as $code => $line) {
|
||||
$text = '<option value="'.$code.'">';
|
||||
$text .= $langs->trans($line["label"]);
|
||||
if ($line["required"]) {
|
||||
$text .= "*";
|
||||
}
|
||||
$text .= '</option>';
|
||||
if (!$line["imported"]) {
|
||||
$text = '<option value="'.$code.'">';
|
||||
$text .= $langs->trans($line["label"]);
|
||||
if ($line["required"]) {
|
||||
$text .= "*";
|
||||
}
|
||||
$text .= '</option>';
|
||||
$optionsnotused .= $text;
|
||||
}
|
||||
$optionsall[$code] = array('label'=>$langs->trans($line["label"]), 'required'=>(empty($line["required"]) ? 0 : 1));
|
||||
}
|
||||
|
||||
$height = '32px'; //needs px for css height attribute below
|
||||
@ -1099,39 +1085,46 @@ if ($step == 4 && $datatoimport) {
|
||||
$entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity; // $entityicon must string name of picto of the field like 'project', 'company', 'contact', 'modulename', ...
|
||||
$entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $objimport->array_import_label[0]; // $entitylang must be a translation key to describe object the field is related to, like 'Company', 'Contact', 'MyModyle', ...
|
||||
|
||||
print '<td class="nowraponall" style="font-weight: normal">=> '.img_object('', $entityicon).' '.$langs->trans($entitylang).'</td>';
|
||||
//print '<td class="nowraponall" style="font-weight: normal">=> '.img_object('', $entityicon).' '.$langs->trans($entitylang).'</td>';
|
||||
print '<td class="nowraponall" style="font-weight: normal">=> </td>';
|
||||
|
||||
print '<td class="nowraponall" style="font-weight: normal">';
|
||||
print '<select id="selectorderimport_'.($i+1).'" class="targetselectchange minwidth300" name="select_'.$line["label"].'">';
|
||||
if ($line["imported"]) {
|
||||
print '<option value="-1"> </option>';
|
||||
print '<option selected="" value="'.$code.'">';
|
||||
} else {
|
||||
print '<option selected="" value="-1"> </option>';
|
||||
print '<option value="'.$code.'">';
|
||||
}
|
||||
$more = '';
|
||||
$text = $langs->trans($line["label"]);
|
||||
if ($line["required"]) {
|
||||
print '<strong>'.$text.'*</strong>';
|
||||
} else {
|
||||
print $text;
|
||||
|
||||
$j = 0;
|
||||
foreach ($optionsall as $code => $val) {
|
||||
$label = $val['required'] ? '<strong>' : '';
|
||||
$label .= $val['label'];
|
||||
$label .= $val['required'] ? '*</strong>' : '';
|
||||
|
||||
print '<option value="'.$code.'"';
|
||||
if ($j == $i) {
|
||||
print ' selected';
|
||||
}
|
||||
print " data-html='".dol_escape_htmltag($label)."'";
|
||||
print '>';
|
||||
print $label;
|
||||
print '</options>';
|
||||
$j++;
|
||||
}
|
||||
print '</option>';
|
||||
print $optionsnotused;
|
||||
print '</select>';
|
||||
//print ajax_combobox('selectorderimport_'.($i+1));
|
||||
print "</td>";
|
||||
|
||||
print '<td class="nowraponall" style="font-weight:normal; text-align:right">';
|
||||
$filecolumn = !empty($array_match_database_to_file[$code])?$array_match_database_to_file[$code]:0;
|
||||
$filecolumn = ($i + 1);
|
||||
// Source field info
|
||||
$htmltext = '<b><u>'.$langs->trans("FieldSource").'</u></b><br>';
|
||||
if ($filecolumn > count($fieldssource)) {
|
||||
$htmltext .= $langs->trans("DataComeFromNoWhere").'<br>';
|
||||
} else {
|
||||
if (empty($objimport->array_import_convertvalue[0][$code])) { // If source file does not need convertion
|
||||
$filecolumntoshow = $filecolumn;
|
||||
$filecolumntoshow = $i + 1;
|
||||
$htmltext .= $langs->trans("DataComeFromFileFieldNb", $filecolumntoshow).'<br>';
|
||||
} else {
|
||||
if ($objimport->array_import_convertvalue[0][$code]['rule'] == 'fetchidfromref') {
|
||||
@ -1143,7 +1136,6 @@ if ($step == 4 && $datatoimport) {
|
||||
}
|
||||
}
|
||||
// Source required
|
||||
$htmltext .= $langs->trans("SourceRequired").': <b>'.yn($line["label"]).'</b><br>';
|
||||
$example = !empty($objimport->array_import_examplevalues[0][$code])?$objimport->array_import_examplevalues[0][$code]:"";
|
||||
// Example
|
||||
if (empty($objimport->array_import_convertvalue[0][$code])) { // If source file does not need convertion
|
||||
@ -1166,6 +1158,7 @@ if ($step == 4 && $datatoimport) {
|
||||
$htmltext .= '<br>';
|
||||
// Target field info
|
||||
$htmltext .= '<b><u>'.$langs->trans("FieldTarget").'</u></b><br>';
|
||||
//$htmltext .= $langs->trans("SourceRequired").': <b>'.yn($line["label"]).'</b><br>';
|
||||
if (empty($objimport->array_import_convertvalue[0][$code])) { // If source file does not need convertion
|
||||
$htmltext .= $langs->trans("DataIsInsertedInto").'<br>';
|
||||
} else {
|
||||
@ -1236,49 +1229,87 @@ if ($step == 4 && $datatoimport) {
|
||||
print '<script type="text/javascript">'."\n";
|
||||
print 'var previousselectedvalueimport = "0";'."\n";
|
||||
print 'var previousselectedlabelimport = "0";'."\n";
|
||||
print 'var arrayofselectedvalues = [];'."\n";
|
||||
|
||||
print '$(document).ready(function () {'."\n";
|
||||
|
||||
print 'setOptionsToDisabled();'."\n";
|
||||
print 'saveSelection();'."\n";
|
||||
|
||||
print '$(".targetselectchange").focus(function(){'."\n";
|
||||
print 'previousselectedvalueimport = $(this).val();'."\n";
|
||||
print 'previousselectedlabelimport = $(this).children("option:selected").text();'."\n";
|
||||
print 'console.log("previousselectedvalueimport="+previousselectedvalueimport)'."\n";
|
||||
print ' previousselectedvalueimport = $(this).val();'."\n";
|
||||
print ' previousselectedlabelimport = $(this).children("option:selected").text();'."\n";
|
||||
print ' console.log("previousselectedvalueimport="+previousselectedvalueimport)'."\n";
|
||||
print '})'."\n";
|
||||
|
||||
// Function to set the disabled flag
|
||||
// - We set all option to "enabled"
|
||||
// - Then we scan all combo to get the value currently selected and save them into the array arrayofselectedvalues
|
||||
// - Then we set to disabled all fields that are selected
|
||||
print 'function setOptionsToDisabled() {'."\n";
|
||||
print ' console.log("Remove the disabled flag everywhere");'."\n";
|
||||
print ' $(".targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'."\n";
|
||||
print ' arrayofselectedvalues = [];'."\n";
|
||||
print ' $(".targetselectchange").each(function(){'."\n";
|
||||
print ' value = $(this).val()'."\n";
|
||||
print ' arrayofselectedvalues.push(value);'."\n";
|
||||
print ' });'."\n";
|
||||
print ' console.log("List of all selected values");'."\n";
|
||||
print ' console.log(arrayofselectedvalues);'."\n";
|
||||
print ' console.log("Set the disabled flag for every entry in arrayofselectedvalues");'."\n";
|
||||
print ' $.each( arrayofselectedvalues, function( key, value ) {'."\n";
|
||||
print ' if (value != -1) {'."\n";
|
||||
print ' console.log("Process key="+key+" value="+value);'."\n";
|
||||
print ' $(".targetselectchange").find(\'option[value="\'+value+\'"]\').prop("disabled", true);'."\n";
|
||||
print ' }'."\n";
|
||||
print ' });'."\n";
|
||||
print '};'."\n";
|
||||
|
||||
// Function to save the selection
|
||||
print 'function saveSelection() {'."\n";
|
||||
print ' arrayselectedfields = [];'."\n";
|
||||
print ' arrayselectedfields.push("0");'."\n";
|
||||
print ' $.each( arrayofselectedvalues, function( key, value ) {'."\n";
|
||||
print ' if (value != -1) {'."\n";
|
||||
print ' arrayselectedfields.push(value);'."\n";
|
||||
print ' } else {'."\n";
|
||||
print ' arrayselectedfields.push(0);'."\n";
|
||||
print ' }'."\n";
|
||||
print ' });'."\n";
|
||||
|
||||
print " $.ajax({\n";
|
||||
print " type: 'POST',\n";
|
||||
print " dataType: 'json',\n";
|
||||
print " url: '".dol_escape_js($_SERVER["PHP_SELF"])."?action=saveselectorder&token=".newToken()."',\n";
|
||||
print " data: 'selectorder='+arrayselectedfields.toString(),\n";
|
||||
print " success: function(){\n";
|
||||
print " console.log('Select order saved');\n";
|
||||
print " },\n";
|
||||
print ' });'."\n";
|
||||
print '};'."\n";
|
||||
|
||||
// If we make a change on a selectbox
|
||||
print '$(".targetselectchange").change(function(){'."\n";
|
||||
print 'if(previousselectedlabelimport != "" && previousselectedvalueimport != -1){'."\n";
|
||||
print '$(".targetselectchange").not($(this)).append(new Option(previousselectedlabelimport,previousselectedvalueimport));'."\n";
|
||||
print 'let valuetochange = $(this).val(); '."\n";
|
||||
print '$(".boxtdunused").each(function(){'."\n";
|
||||
print 'if ($(this).text().includes(valuetochange)){'."\n";
|
||||
print 'arraychild = $(this)[0].childNodes'."\n";
|
||||
print 'arraytexttomodify = arraychild[0].textContent.split(" ")'."\n";
|
||||
print 'arraytexttomodify[1] = previousselectedvalueimport '."\n";
|
||||
print 'textmodified = arraytexttomodify.join(" ") '."\n";
|
||||
print 'arraychild[0].textContent = textmodified'."\n";
|
||||
print 'arraychild[1].innerHTML = previousselectedlabelimport'."\n";
|
||||
print '}'."\n";
|
||||
print '})'."\n";
|
||||
print '}'."\n";
|
||||
print 'if($( this ).val() != -1){'."\n";
|
||||
print '$(".targetselectchange").not($( this )).find(\'option[value="\'+$( this ).val()+\'"]\').remove();'."\n";
|
||||
print '}'."\n";
|
||||
print '$(this).blur()'."\n";
|
||||
print 'arrayselectedfields = [];'."\n";
|
||||
print 'arrayselectedfields.push("0");'."\n";
|
||||
print '$(".targetselectchange").each(function(){'."\n";
|
||||
print 'value = $(this).val()'."\n";
|
||||
print 'arrayselectedfields.push(value);'."\n";
|
||||
print ' setOptionsToDisabled();'."\n";
|
||||
|
||||
print ' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'."\n";
|
||||
print ' let valuetochange = $(this).val(); '."\n";
|
||||
print ' $(".boxtdunused").each(function(){'."\n";
|
||||
print ' if ($(this).text().includes(valuetochange)){'."\n";
|
||||
print ' arraychild = $(this)[0].childNodes'."\n";
|
||||
print ' arraytexttomodify = arraychild[0].textContent.split(" ")'."\n";
|
||||
print ' arraytexttomodify[1] = previousselectedvalueimport '."\n";
|
||||
print ' textmodified = arraytexttomodify.join(" ") '."\n";
|
||||
print ' arraychild[0].textContent = textmodified'."\n";
|
||||
print ' arraychild[1].innerHTML = previousselectedlabelimport'."\n";
|
||||
print ' }'."\n";
|
||||
print ' })'."\n";
|
||||
print ' }'."\n";
|
||||
print ' $(this).blur()'."\n";
|
||||
|
||||
print ' saveSelection()'."\n";
|
||||
print '});'."\n";
|
||||
|
||||
print "$.ajax({\n";
|
||||
print " type: 'POST',\n";
|
||||
print " dataType: 'json',\n";
|
||||
print " url: '".dol_escape_js($_SERVER["PHP_SELF"])."?action=saveselectorder&token=".newToken()."',\n";
|
||||
print " data: 'selectorder='+arrayselectedfields.toString(),\n";
|
||||
print " success: function(){\n";
|
||||
print " console.log('Select order saved');\n";
|
||||
print " },\n";
|
||||
print '});'."\n";
|
||||
|
||||
print '});'."\n";
|
||||
print '})'."\n";
|
||||
print '</script>'."\n";
|
||||
}
|
||||
@ -1315,6 +1346,7 @@ if ($step == 4 && $datatoimport) {
|
||||
print '<input type="hidden" name="hexa" value="'.$hexa.'">';
|
||||
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
|
||||
print '<input type="hidden" name="endatlinenb" value="'.$endatlinenb.'">';
|
||||
print '<input type="hidden" name="page_y" value="">';
|
||||
print '<input type="hidden" value="'.dol_escape_htmltag($separator).'" name="separator">';
|
||||
print '<input type="hidden" value="'.dol_escape_htmltag($enclosure).'" name="enclosure">';
|
||||
|
||||
@ -1333,7 +1365,7 @@ if ($step == 4 && $datatoimport) {
|
||||
print $form->selectarray('visibility', $arrayvisibility, 'private');
|
||||
print '</td>';
|
||||
print '<td class="right">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("SaveImportProfile").'">';
|
||||
print '<input type="submit" class="button small reposition" value="'.$langs->trans("SaveImportProfile").'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// List of existing import profils
|
||||
@ -2201,14 +2233,15 @@ function show_elem($fieldssource, $pos, $key, $var, $nostyle = '')
|
||||
}
|
||||
|
||||
if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos]["imported"]))) { // No fields
|
||||
/*
|
||||
print '<tr style="height:'.$height.'" class="trimport oddevenimport">';
|
||||
print '<td class="nocellnopadding" width="16" style="font-weight: normal">';
|
||||
//print img_picto(($pos > 0 ? $langs->trans("MoveField", $pos) : ''), 'grip_title', 'class="boxhandle" style="cursor:move;"');
|
||||
print '</td>';
|
||||
print '<td style="font-weight: normal">';
|
||||
print $langs->trans("NoFields");
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
*/
|
||||
} elseif ($key == 'none') { // Empty line
|
||||
print '<tr style="height:'.$height.'" class="trimport oddevenimport">';
|
||||
print '<td class="nocellnopadding" width="16" style="font-weight: normal">';
|
||||
@ -2224,6 +2257,7 @@ function show_elem($fieldssource, $pos, $key, $var, $nostyle = '')
|
||||
print '<td class="nocellnopadding" width="16" style="font-weight: normal">';
|
||||
// The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object
|
||||
//print img_picto($langs->trans("MoveField", $pos), 'grip_title', 'class="boxhandle" style="cursor:move;"');
|
||||
print img_picto($langs->trans("Field").' '.$pos, 'file', 'class="pictofixedwith"');
|
||||
print '</td>';
|
||||
if (isset($fieldssource[$pos]['imported']) && $fieldssource[$pos]['imported'] == false) {
|
||||
print '<td class="nowraponall boxtdunused" style="font-weight: normal">';
|
||||
@ -2240,7 +2274,9 @@ function show_elem($fieldssource, $pos, $key, $var, $nostyle = '')
|
||||
if (!utf8_check($example)) {
|
||||
$example = utf8_encode($example);
|
||||
}
|
||||
print ' (<i>'.$example.'</i>)';
|
||||
print ' - ';
|
||||
//print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ExampleOnFirstLine").': </span>';
|
||||
print '<i class="opacitymedium">'.$example.'</i>';
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user