[TASK] Use Backups of field values and take already set values into account
authorOliver Eglseder <oliver.eglseder@in2code.de>
Wed, 9 Sep 2015 09:01:52 +0000 (11:01 +0200)
committerOliver Eglseder <oliver.eglseder@in2code.de>
Wed, 9 Sep 2015 09:01:52 +0000 (11:01 +0200)
Classes/Domain/Model/Condition.php
Classes/Domain/Model/Rule.php
Resources/Public/JavaScript/PowermailCondition.js

index c5957c9..6d348b9 100644 (file)
@@ -267,8 +267,17 @@ class Condition extends AbstractEntity {
 
                                        /** @var Field $field */
                                        foreach ($page->getFields() as $field) {
+                                               $action = self::$actionNumberMap[$this->actions];
+                                               if ($action === 'hide') {
+                                                       $arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()] = $field->getText();
+                                                       $field->setText('');
+                                               } elseif ($action === 'un_hide') {
+                                                       if (!empty($arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()])) {
+                                                               $field->setText($arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()]);
+                                                       }
+                                               }
                                                $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
-                                                       'action' => self::$actionNumberMap[$this->actions],
+                                                       'action' => $action,
                                                        'matchingCondition' => $this->getUid(),
                                                );
                                        }
@@ -286,8 +295,17 @@ class Condition extends AbstractEntity {
                                /** @var Field $field */
                                foreach ($page->getFields() as $field) {
                                        if ($field->getUid() === (int) $this->targetField) {
+                                               $action = self::$actionNumberMap[$this->actions];
+                                               if ($action === 'hide') {
+                                                       $arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()] = $field->getText();
+                                                       $field->setText('');
+                                               } elseif ($action === 'un_hide') {
+                                                       if (!empty($arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()])) {
+                                                               $field->setText($arguments['old_alues'][$form->getUid()][$page->getUid()][$field->getMarker()]);
+                                                       }
+                                               }
                                                $arguments['todo_field'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
-                                                       'action' => self::$actionNumberMap[$this->actions],
+                                                       'action' => $action,
                                                        'matchingCondition' => $this->getUid(),
                                                );
                                                break;
index 3b74aad..cda5453 100644 (file)
@@ -190,6 +190,9 @@ class Rule extends AbstractEntity {
                                                break;
                                        }
                                }
+                               if ($equalField !== NULL) {
+                                       break;
+                               }
                        }
                }
                /** @var Page $page */
index 1b1ceab..10af72a 100644 (file)
@@ -38,10 +38,14 @@ function PowermailCondition($formElement) {
        ];
 
        this.sendFormValuesToPowermailCond = function() {
+               var formToSend = $(that.$formElement.get(0));
+               var tempEnabledFields = formToSend.find(':disabled').removeProp('disabled');
+               var dataToSend = new FormData(that.$formElement.get(0));
+               tempEnabledFields.prop('disabled', true);
                jQuery.ajax({
                        type: 'POST',
                        url: 'index.php?type=3131',
-                       data: new FormData(that.$formElement.get(0)),
+                       data: dataToSend,
                        contentType: false,
                        processData: false,
                        success: function(data) {
@@ -53,12 +57,11 @@ function PowermailCondition($formElement) {
                                                        for (var fieldMarker in data.todo_field[formUid][pageUid]) {
                                                                var fields = form.find('[id^=powermail_field_' + fieldMarker + ']');
                                                                if (data.todo_field[formUid][pageUid][fieldMarker]['action'] === 'hide') {
-                                                                       fields.val('');
                                                                        fields.prop('disabled', true);
                                                                        fields.closest('.powermail_fieldwrap').hide();
                                                                }
                                                                if (data.todo_field[formUid][pageUid][fieldMarker]['action'] === 'un_hide') {
-                                                                       fields.prop('disabled', false);
+                                                                       fields.removeProp('disabled');
                                                                        fields.closest('.powermail_fieldwrap').show();
                                                                }
                                                        }