dev/user-interface#17 Fix popup confirmation on import forms
[civicrm-core.git] / CRM / Import / Form / Preview.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class previews the uploaded file and returns summary statistics.
20 *
21 * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes,
22 * those classes can be removed entirely and this class will not need to be abstract
23 */
24 abstract class CRM_Import_Form_Preview extends CRM_Core_Form {
25
26 /**
27 * Return a descriptive name for the page, used in wizard header.
28 *
29 * @return string
30 */
31 public function getTitle() {
32 return ts('Preview');
33 }
34
35 /**
36 * Build the form object.
37 */
38 public function buildQuickForm() {
39
40 // FIXME: This is a hack...
41 // The tpl contains javascript that starts the import on form submit
42 // Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked
43 // Hacking in some onclick js to make them act more like links instead of buttons
44 $path = CRM_Utils_System::currentPath();
45 $query = ['_qf_MapField_display' => 'true'];
46 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
47 if (CRM_Utils_Rule::qfKey($qfKey)) {
48 $query['qfKey'] = $qfKey;
49 }
50 $previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE);
51 $cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE);
52
53 $this->addButtons([
54 [
55 'type' => 'back',
56 'name' => ts('Previous'),
57 'js' => ['onclick' => "location.href='{$previousURL}'; return false;"],
58 ],
59 [
60 'type' => 'next',
61 'name' => ts('Import Now'),
62 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
63 'isDefault' => TRUE,
64 ],
65 [
66 'type' => 'cancel',
67 'name' => ts('Cancel'),
68 'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"],
69 ],
70 ]);
71 }
72
73 /**
74 * Set status url for ajax.
75 */
76 public function setStatusUrl() {
77 $statusID = $this->get('statusID');
78 if (!$statusID) {
79 $statusID = md5(uniqid(rand(), TRUE));
80 $this->set('statusID', $statusID);
81 }
82 $statusUrl = CRM_Utils_System::url('civicrm/ajax/status', "id={$statusID}", FALSE, NULL, FALSE);
83 $this->assign('statusUrl', $statusUrl);
84 }
85
86 }