Skip to content

Commit

Permalink
Merge pull request #24359 from eileenmcnaughton/master
Browse files Browse the repository at this point in the history
Merge branch '5.53' to master
  • Loading branch information
eileenmcnaughton authored Aug 23, 2022
2 parents 4d9349d + aa5805d commit 5820d17
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
76 changes: 44 additions & 32 deletions CRM/Import/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,7 @@ public function preProcess() {
* Build the form object.
*/
public function buildQuickForm() {

// FIXME: This is a hack...
// The tpl contains javascript that starts the import on form submit
// Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked
// Hacking in some onclick js to make them act more like links instead of buttons
$path = CRM_Utils_System::currentPath();
$query = ['_qf_MapField_display' => 'true'];
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
if (CRM_Utils_Rule::qfKey($qfKey)) {
$query['qfKey'] = $qfKey;
}
$previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE);
$cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE);

$this->addButtons([
[
'type' => 'back',
'name' => ts('Previous'),
'js' => ['onclick' => "location.href='{$previousURL}'; return false;"],
],
[
'type' => 'next',
'name' => ts('Import Now'),
'spacing' => '          ',
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"],
],
]);
$this->addButtons($this->getButtons());
}

/**
Expand Down Expand Up @@ -146,4 +115,47 @@ protected function runTheImport(): void {
$runner->runAllViaWeb();
}

/**
* Get the buttons for the form.
*
* @return array|array[]
* @throws \CRM_Core_Exception
*/
private function getButtons(): array {
// FIXME: This is a hack...
// The tpl contains javascript that starts the import on form submit
// Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked
// Hacking in some onclick js to make them act more like links instead of buttons
$path = CRM_Utils_System::currentPath();
$query = ['_qf_MapField_display' => 'true'];
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
if (CRM_Utils_Rule::qfKey($qfKey)) {
$query['qfKey'] = $qfKey;
}
$previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE);
$cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE);
$buttons = [
[
'type' => 'back',
'name' => ts('Previous'),
'js' => ['onclick' => "location.href='{$previousURL}'; return false;"],
],
];
if ($this->hasImportableRows()) {
$buttons[] = [
'type' => 'next',
'name' => ts('Import Now'),
'spacing' => '          ',
'isDefault' => TRUE,
];
}
$buttons[] = [
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"],
];

return $buttons;
}

}
11 changes: 11 additions & 0 deletions CRM/Import/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,15 @@ protected function isSkipDuplicates(): bool {
return ((int) $this->getSubmittedValue('onDuplicate')) === CRM_Import_Parser::DUPLICATE_SKIP;
}

/**
* Are there valid rows to import.
*
* @return bool
*
* @throws \CRM_Core_Exception
*/
protected function hasImportableRows(): bool {
return (bool) $this->getRowCount(['new']);
}

}

0 comments on commit 5820d17

Please sign in to comment.