Skip to content

Commit

Permalink
Move calculation of js for import fields WITH relationship keys to pr…
Browse files Browse the repository at this point in the history
…ocessor.

As should be obvious we can collapse a lot more out with the next commit now....
  • Loading branch information
eileenmcnaughton committed Sep 5, 2019
1 parent 2ce691d commit 34cca87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 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
24 changes: 18 additions & 6 deletions CRM/Import/ImportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,26 @@ 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) {
Expand Down

0 comments on commit 34cca87

Please sign in to comment.