remove submit button in view mode. also add validation so to prevent user processing...
authorKurund Jalmi <kurundjalmi@thirdsectordesign.org>
Tue, 22 Aug 2023 19:35:48 +0000 (20:35 +0100)
committerKurund Jalmi <kurundjalmi@thirdsectordesign.org>
Wed, 6 Dec 2023 00:23:33 +0000 (00:23 +0000)
ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php
ext/afform/core/Civi/Api4/Action/Afform/Submit.php
ext/afform/core/ang/af/afForm.component.js

index e1516a21e644b887b5c4481227274fd14ca3e27f..2c3fcc75ce5939af19f3f04a51fab508225e14ae 100644 (file)
@@ -239,6 +239,7 @@ class AfformAdminMeta {
             'class' => 'af-button btn btn-primary',
             'crm-icon' => 'fa-check',
             'ng-click' => 'afform.submit()',
+            'ng-if' => 'afform.showSubmitButton',
             '#children' => [
               ['#text' => E::ts('Submit')],
             ],
index 3e29c775ea76714cfc3bfce3458e33d80bffe242..87229d6a8470acd50baf598452d97fd99f109592 100644 (file)
@@ -126,8 +126,6 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction {
 
     // do nothing and return early
     if (empty($afformSubmissionData)) {
-      // unset sid from args
-      $this->args['sid'] = NULL;
       return;
     }
 
@@ -171,7 +169,7 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction {
     foreach ($ids as $index => $id) {
       $this->_entityIds[$entity['name']][$index] = [
         $idField => isset($result[$id]) ? $id : NULL,
-        '_joins' => [],
+        'joins' => [],
       ];
       if (isset($result[$id])) {
         $data = ['fields' => $result[$id]];
index abb3ea308878b7fbe3f562b3a29ee8f9636354a3..4654a9b94e59d9b3761afda69bfd5a08ae0a254e 100644 (file)
@@ -32,6 +32,21 @@ class Submit extends AbstractProcessor {
     // preprocess submitted values
     $entityValues = $this->preprocessSubmittedValues($this->values);
 
+    // get the submission information if we have submission id.
+    // currently we don't support processing of already processed forms
+    // return validation error in those cases
+    if (!empty($this->args['sid'])) {
+      $afformSubmissionData = \Civi\Api4\AfformSubmission::get(FALSE)
+        ->addWhere('id', '=', $this->args['sid'])
+        ->addWhere('afform_name', '=', $this->name)
+        ->addWhere('status_id:name', '=', 'Processed')
+        ->execute()->count();
+
+      if ($afformSubmissionData > 0) {
+        throw new \CRM_Core_Exception(ts('Submission is already processed.'));
+      }
+    }
+
     // Call validation handlers
     $event = new AfformValidateEvent($this->_afform, $this->_formDataModel, $this, $entityValues);
     \Civi::dispatcher()->dispatch('civi.afform.validate', $event);
index 8170fdebeca353b8ac99baaeb3c75ea534b3dc42..1c210f8d8418fd9ef507ce0f049731f708a47f8b 100644 (file)
           angular.merge(data[selectedEntity][selectedIndex].fields, _.cloneDeep(schema[selectedEntity].data || {}));
           data[selectedEntity][selectedIndex].joins = {};
         }
+
+        ctrl.showSubmitButton = displaySubmitButton(args);
+      };
+
+      function displaySubmitButton(args) {
+        if (args['sid'] && args['sid'].length > 0) {
+          return false;
+        }
+        return true;
       };
 
       // Used when submitting file fields