[TASK] Experimental support for experimental IRRE-Forms and make pages hideable
authorOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 3 Sep 2015 14:39:26 +0000 (16:39 +0200)
committerOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 3 Sep 2015 14:39:26 +0000 (16:39 +0200)
Classes/Domain/Model/Condition.php
Classes/Domain/Validator/ConditionAwareValidator.php
Resources/Public/JavaScript/PowermailCondition.js

index d1e2a67..f42a8da 100644 (file)
@@ -256,18 +256,44 @@ class Condition extends AbstractEntity {
         * @return array
         */
        public function apply(Form $form, array $arguments) {
-               /** @var Page $page */
-               foreach ($form->getPages() as $page) {
-                       /** @var Field $field */
-                       foreach ($page->getFields() as $field) {
-                               if ($field->getUid() === (int) $this->targetField) {
-                                       $arguments['todo'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+               if (strpos($this->targetField, 'fieldset') !== FALSE) {
+                       $pageUid = (int) substr($this->targetField, 9);
+                       /** @var Page $page */
+                       foreach ($form->getPages() as $page) {
+                               if ($page->getUid() === $pageUid) {
+
+                                       /** @var Field $field */
+                                       foreach ($page->getFields() as $field) {
+                                               if ($field->getUid() === (int) $this->targetField) {
+                                                       $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                                               'action' => self::$actionNumberMap[$this->actions],
+                                                               'matchingCondition' => $this->getUid(),
+                                                       );
+                                                       break;
+                                               }
+                                       }
+
+                                       $arguments['todo_page'][$form->getUid()][$page->getUid()] = array(
                                                'action' => self::$actionNumberMap[$this->actions],
                                                'matchingCondition' => $this->getUid(),
                                        );
                                        break;
                                }
                        }
+               } else {
+                       /** @var Page $page */
+                       foreach ($form->getPages() as $page) {
+                               /** @var Field $field */
+                               foreach ($page->getFields() as $field) {
+                                       if ($field->getUid() === (int) $this->targetField) {
+                                               $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                                       'action' => self::$actionNumberMap[$this->actions],
+                                                       'matchingCondition' => $this->getUid(),
+                                               );
+                                               break;
+                                       }
+                               }
+                       }
                }
                return $arguments;
        }
@@ -278,18 +304,45 @@ class Condition extends AbstractEntity {
         * @return array
         */
        public function negate(Form $form, array $arguments) {
-               /** @var Page $page */
-               foreach ($form->getPages() as $page) {
-                       /** @var Field $field */
-                       foreach ($page->getFields() as $field) {
-                               if ($field->getUid() === (int) $this->targetField) {
-                                       $arguments['todo'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+
+               if (strpos($this->targetField, 'fieldset') !== FALSE) {
+                       $pageUid = (int) substr($this->targetField, 9);
+                       /** @var Page $page */
+                       foreach ($form->getPages() as $page) {
+                               if ($page->getUid() === $pageUid) {
+
+                                       /** @var Field $field */
+                                       foreach ($page->getFields() as $field) {
+                                               if ($field->getUid() === (int) $this->targetField) {
+                                                       $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                                               'action' => $this->getNegatedActionString(),
+                                                               'matchingCondition' => $this->getUid(),
+                                                       );
+                                                       break;
+                                               }
+                                       }
+
+                                       $arguments['todo_page'][$form->getUid()][$page->getUid()] = array(
                                                'action' => $this->getNegatedActionString(),
                                                'matchingCondition' => $this->getUid(),
                                        );
                                        break;
                                }
                        }
+               } else {
+                       /** @var Page $page */
+                       foreach ($form->getPages() as $page) {
+                               /** @var Field $field */
+                               foreach ($page->getFields() as $field) {
+                                       if ($field->getUid() === (int) $this->targetField) {
+                                               $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                                       'action' => $this->getNegatedActionString(),
+                                                       'matchingCondition' => $this->getUid(),
+                                               );
+                                               break;
+                                       }
+                               }
+                       }
                }
                return $arguments;
        }
index 9e4bf95..c07c217 100644 (file)
@@ -28,7 +28,10 @@ namespace In2code\PowermailCond\Domain\Validator;
  ***************************************************************/
 
 use In2code\Powermail\Domain\Model\Field;
+use In2code\Powermail\Domain\Model\Form;
+use In2code\Powermail\Domain\Model\Page;
 use In2code\Powermail\Domain\Validator\InputValidator;
+use In2code\Powermail\Utility\ConfigurationUtility;
 use In2code\PowermailCond\Domain\Model\Condition;
 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
 
@@ -50,15 +53,40 @@ class ConditionAwareValidator extends InputValidator {
                $feUser = $GLOBALS['TSFE']->fe_user;
                $arguments = $feUser->getSessionData('tx_powermail_cond');
                $fieldMarker = $field->getMarker();
-               if (!empty($arguments['todo'][$fieldMarker])) {
-                       if (!$arguments['todo'][$fieldMarker] === Condition::getActionNumberMap(Condition::ACTION_HIDE)) {
-                               // Mandatory Check
-                               if ($field->getMandatory()) {
-                                       if (!$this->validateMandatory($value)) {
-                                               $this->setErrorAndMessage($field, 'mandatory');
+
+
+               if (ConfigurationUtility::isReplaceIrreWithElementBrowserActive()) {
+                       $pages = $field->getPages();
+                       /** @var Form $form */
+                       foreach ($pages->getForms() as $form) {
+                               /** @var Page $page */
+                               foreach ($form->getPages() as $page) {
+                                       /** @var Field $field */
+                                       foreach ($page->getFields() as $field) {
+                                               if (!empty($arguments[$form->getUid()][$page->getUid()][$fieldMarker]['action'])) {
+                                                       if ($arguments[$form->getUid()][$page->getUid()][$fieldMarker]['action'] === Condition::getActionNumberMap(Condition::ACTION_HIDE)) {
+                                                               return;
+                                                       }
+                                               }
                                        }
                                }
                        }
+               } else {
+                       $page = $field->getPages();
+                       $form = $page->getForms()->getUid();
+                       $page = $page->getUid();
+                       if (!empty($arguments['todo_field'][$form][$page][$fieldMarker]['action'])) {
+                               if ($arguments['todo_field'][$form][$page][$fieldMarker]['action'] === Condition::getActionNumberMap(Condition::ACTION_HIDE)) {
+                                       return;
+                               }
+                       }
+               }
+
+               // Mandatory Check
+               if ($field->getMandatory()) {
+                       if (!$this->validateMandatory($value)) {
+                               $this->setErrorAndMessage($field, 'mandatory');
+                       }
                }
 
                // String Checks
index 6a85941..38b7154 100644 (file)
@@ -46,18 +46,18 @@ function PowermailCondition($formElement) {
                        processData: false,
                        success: function(data) {
                                console.log(data);
-                               if (data.todo !== undefined) {
-                                       for (var formUid in data.todo) {
+                               if (data.todo_field !== undefined) {
+                                       for (var formUid in data.todo_field) {
                                                var form = $('.powermail_form_' + formUid)
-                                               for (var pageUid in data.todo[formUid]) {
-                                                       for (var fieldMarker in data.todo[formUid][pageUid]) {
+                                               for (var pageUid in data.todo_field[formUid]) {
+                                                       for (var fieldMarker in data.todo_field[formUid][pageUid]) {
                                                                var input = form.find('#powermail_field_' + fieldMarker);
-                                                               if (data.todo[formUid][pageUid][fieldMarker]['action'] === 'hide') {
+                                                               if (data.todo_field[formUid][pageUid][fieldMarker]['action'] === 'hide') {
                                                                        input.val('');
                                                                        input.prop('disabled', true);
                                                                        input.closest('.powermail_fieldwrap').hide();
                                                                }
-                                                               if (data.todo[formUid][pageUid][fieldMarker]['action'] === 'un_hide') {
+                                                               if (data.todo_field[formUid][pageUid][fieldMarker]['action'] === 'un_hide') {
                                                                        input.prop('disabled', false);
                                                                        input.closest('.powermail_fieldwrap').show();
                                                                }
@@ -65,6 +65,21 @@ function PowermailCondition($formElement) {
                                                }
                                        }
                                }
+                               if (data.todo_page !== undefined) {
+                                       for (var formUid in data.todo_page) {
+                                               var form = $('.powermail_form_' + formUid)
+                                               for (var pageUid in data.todo_page[formUid]) {
+                                                       var page = form.find('.powermail_fieldset_' + pageUid);
+                                                       if (data.todo_page[formUid][pageUid]['action'] === 'hide') {
+                                                               page.hide();
+                                                       }
+                                                       if (data.todo_page[formUid][pageUid]['action'] === 'un_hide') {
+                                                               page.show();
+                                                       }
+                                               }
+                                       }
+                               }
+
                        }
                });
        };
@@ -76,7 +91,6 @@ function PowermailCondition($formElement) {
         */
        function initialize() {
                that.$formElement.css('background-color', 'red');
-               //that.sendFormValuesToPowermailCond();
        }
 
        // make global