Skip to content

Commit

Permalink
Merge pull request #25759 from eileenmcnaughton/import_notice
Browse files Browse the repository at this point in the history
Fix really annoying notice on mispelt variable name `$isCheked`
  • Loading branch information
totten authored Mar 15, 2023
2 parents 863e84d + 1e25307 commit b7b8374
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 48 deletions.
23 changes: 2 additions & 21 deletions CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ public function preProcess(): void {
public function buildQuickForm(): void {
$this->addSavedMappingFields();

$this->addFormRule(['CRM_Contact_Import_Form_MapField', 'formRule']);

//-------- end of saved mapping stuff ---------

$defaults = [];
Expand Down Expand Up @@ -303,24 +301,6 @@ public function buildQuickForm(): void {
$this->addFormButtons();
}

/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return bool
* list of errors to be posted back to the form
*/
public static function formRule(array $fields): bool {
if (!empty($fields['saveMapping'])) {
// todo - this is nonsensical - sane js is better. PR to fix got stale but
// is here https://github.com/civicrm/civicrm-core/pull/23950
CRM_Core_Smarty::singleton()->assign('isCheked', TRUE);
}
return TRUE;
}

/**
* Process the mapped fields and map it into the uploaded file.
*
Expand Down Expand Up @@ -381,7 +361,7 @@ public function submit(array $params): void {
//Updating Mapping Records
if (!empty($params['updateMapping'])) {
foreach (array_keys($this->getColumnHeaders()) as $i) {
$this->saveMappingField($params['mappingId'], $i, TRUE);
$this->saveMappingField($this->getSavedMappingID(), $i, TRUE);
}
}

Expand All @@ -394,6 +374,7 @@ public function submit(array $params): void {
];

$saveMapping = civicrm_api3('Mapping', 'create', $mappingParams);
$this->updateUserJobMetadata('MapField', ['mapping_id' => $saveMapping['id']]);

foreach (array_keys($this->getColumnHeaders()) as $i) {
$this->saveMappingField($saveMapping['id'], $i);
Expand Down
21 changes: 15 additions & 6 deletions CRM/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,21 @@ protected function buildSavedMappingFields($savedMappingID) {
$this->add('text', 'saveMappingDesc', ts('Description'));
}
else {
// @todo we should stop doing this - the passed in value should be fine, confirmed OK in contact import.
$savedMapping = $this->get('savedMapping');

$mappingName = (string) civicrm_api3('Mapping', 'getvalue', ['id' => $savedMappingID, 'return' => 'name']);
// @todo - this should go too - used when going back to the DataSource form but it should
// access the job.
$this->set('loadedMapping', $savedMapping);
$this->add('hidden', 'mappingId', $savedMappingID);
$this->add('hidden', 'mappingId', $savedMapping);

$this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
$saveDetailsName = ts('Save as a new field mapping');
$this->add('text', 'saveMappingName', ts('Name'));
$this->add('text', 'saveMappingDesc', ts('Description'));
}
$this->assign('savedMappingName', $mappingName ?? NULL);
$this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, ['onclick' => "showSaveDetails(this)"]);
$this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL);
}

/**
Expand Down Expand Up @@ -255,12 +257,11 @@ protected function saveMapping(): void {
'description' => $this->getSubmittedValue('saveMappingDesc'),
'mapping_type_id:name' => $this->getMappingTypeName(),
])->execute()->first()['id'];

$this->updateUserJobMetadata('MapField', ['mapping_id' => $savedMappingID]);
foreach (array_keys($this->getColumnHeaders()) as $i) {
$this->saveMappingField($savedMappingID, $i, FALSE);
}
$this->set('savedMapping', $savedMappingID);
$this->updateUserJobMetadata('mapping', ['id' => $savedMappingID]);
}
}

Expand Down Expand Up @@ -362,7 +363,7 @@ protected function addMapper(): array {
* @throws \CRM_Core_Exception
*/
protected function addSavedMappingFields(): void {
$savedMappingID = (int) $this->getSubmittedValue('savedMapping');
$savedMappingID = $this->getSavedMappingID();
$this->buildSavedMappingFields($savedMappingID);
$this->addFormRule(['CRM_Import_Form_MapField', 'mappingRule']);
}
Expand Down Expand Up @@ -466,4 +467,12 @@ protected function guessMappingBasedOnColumns(string $columnHeader): string {
return $this->defaultFromHeader($columnHeader, $headerPatterns);
}

/**
* @return int
*/
protected function getSavedMappingID(): int {
$savedMappingID = (int) ($this->getUserJob()['metadata']['MapField']['mapping_id'] ?? $this->getSubmittedValue('savedMapping'));
return $savedMappingID;
}

}
12 changes: 0 additions & 12 deletions templates/CRM/Contact/Import/Form/MapField.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@
</script>
{/literal}

<script type="text/javascript" >
{literal}
if ( document.getElementsByName("saveMapping")[0].checked ) {
document.getElementsByName("updateMapping")[0].checked = true;
document.getElementsByName("saveMapping")[0].checked = false;
}
{/literal}
{if $isCheked}
document.getElementsByName("saveMapping")[0].checked = true;
{/if}
</script>

<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
{$initHideBoxes|smarty:nodefaults}

Expand Down
25 changes: 16 additions & 9 deletions templates/CRM/Import/Form/MapTableCommon.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,24 @@
} else {
cj('#saveDetails').hide();
}

function showSaveDetails(chkbox) {
if (chkbox.checked) {
document.getElementById("saveDetails").style.display = "block";
document.getElementById("saveMappingName").disabled = false;
document.getElementById("saveMappingDesc").disabled = false;
cj('#updateMapping').change(function() {
cj('#saveMapping').prop("checked", !this.checked).change();
});
cj('#saveMapping').change(function() {
if (this.checked) {
cj('#saveDetails').show();
cj('#updateMapping').prop('checked', false);
cj('#saveMappingName').removeAttr('disabled')
cj('#saveMappingDesc').removeAttr('disabled')
} else {
document.getElementById("saveDetails").style.display = "none";
document.getElementById("saveMappingName").disabled = true;
document.getElementById("saveMappingDesc").disabled = true;
cj('#saveDetails').hide();
cj('#saveMappingName').attr('disabled','disabled');
cj('#saveMappingDesc').attr('disabled','disabled');
}
});
// Load in update mode if we have already saved the name - ie gone forwards & back.
if (cj('#saveMappingName').val()) {
cj('#updateMapping').prop("checked", true).change();
}
cj('select[id^="mapper"][id$="[0]"]').addClass('huge');
{/literal}
Expand Down

0 comments on commit b7b8374

Please sign in to comment.