Skip to content

Commit

Permalink
Merge pull request #15218 from eileenmcnaughton/import_again
Browse files Browse the repository at this point in the history
[REF] Move calculation of js for import fields WITH relationship keys to processor.
  • Loading branch information
seamuslee001 authored Sep 5, 2019
2 parents 6189132 + a9f13f0 commit 5288075
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
26 changes: 1 addition & 25 deletions CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,32 +864,8 @@ public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $
if ($mappingName[$i] != ts('- do not import -')) {

if ($processor->getRelationshipKey($i)) {

$contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i]));
$websiteTypeId = $processor->getWebsiteTypeID($i);
$locationId = $processor->getLocationTypeID($i);
$phoneType = $processor->getPhoneTypeID($i);
$imProvider = $processor->getIMProviderID($i);

$defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
if (!$websiteTypeId) {
if (!$locationId) {
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
}
}
// fix for edge cases, CRM-4954
if ($contactDetails == 'image_url') {
$contactDetails = str_replace('url', 'URL', $contactDetails);
}

if (!$contactDetails) {
$js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
}

if ((!$phoneType) && (!$imProvider)) {
$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
}
//$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
$js = $processor->getQuickFormJSForField($i);
$jsSet = TRUE;
}
else {
Expand Down
26 changes: 19 additions & 7 deletions CRM/Import/ImportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,32 @@ protected function isValidRelationshipKey($key) {
*/
public function getQuickFormJSForField($column) {
$columnNumbersToHide = [];

if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) {
$columnNumbersToHide[] = 1;
if ($this->getRelationshipKey($column)) {
if (!$this->getWebsiteTypeID($column) && !$this->getLocationTypeID($column)) {
$columnNumbersToHide[] = 2;
}
if (!$this->getFieldName($column)) {
$columnNumbersToHide[] = 1;
}
if (!$this->getPhoneOrIMTypeID($column)) {
$columnNumbersToHide[] = 3;
}
}
if (!$this->getPhoneOrIMTypeID($column)) {
$columnNumbersToHide[] = 2;
else {
if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) {
$columnNumbersToHide[] = 1;
}
if (!$this->getPhoneOrIMTypeID($column)) {
$columnNumbersToHide[] = 2;
}
$columnNumbersToHide[] = 3;
}
$columnNumbersToHide[] = 3;

$jsClauses = [];
foreach ($columnNumbersToHide as $columnNumber) {
$jsClauses[] = $this->getFormName() . "['mapper[$column][" . $columnNumber . "]'].style.display = 'none';";
}
return implode("\n", $jsClauses) . "\n";
return empty($jsClauses) ? '' : implode("\n", $jsClauses) . "\n";
}

/**
Expand Down

0 comments on commit 5288075

Please sign in to comment.