From cf2f200e063b882910406347f24962db4d66da82 Mon Sep 17 00:00:00 2001 From: Rafael Ostertag Date: Tue, 8 Aug 2017 15:53:49 +0200 Subject: [PATCH 1/2] ElementUpdate.js: when updating a `value` attribute, use `$().val()`. QfqForm.js: When handling responses to `save`, handle `element-update` independently from `form-update` --- javascript/src/ElementUpdate.js | 3 +++ javascript/src/QfqForm.js | 3 +++ mockup/elementupdate.html | 1 + 3 files changed, 7 insertions(+) diff --git a/javascript/src/ElementUpdate.js b/javascript/src/ElementUpdate.js index 177199fd..3ec47bd9 100644 --- a/javascript/src/ElementUpdate.js +++ b/javascript/src/ElementUpdate.js @@ -78,6 +78,9 @@ var QfqNS = QfqNS || {}; n.ElementUpdate.setAttribute = function ($element, attributeName, attributeValue) { $element.attr(attributeName, attributeValue); + if (attributeName.toLowerCase() === "value") { + $element.val(attributeValue); + } }; n.ElementUpdate.deleteAttribute = function ($element, attributeName) { diff --git a/javascript/src/QfqForm.js b/javascript/src/QfqForm.js index 57a768e7..dd510f8f 100644 --- a/javascript/src/QfqForm.js +++ b/javascript/src/QfqForm.js @@ -895,6 +895,9 @@ var QfqNS = QfqNS || {}; // do we have to update the HTML Form? if (data['form-update']) { this.applyFormConfiguration(data['form-update']); + } + + if (data['element-update']) { this.applyElementConfiguration(data['element-update']); } diff --git a/mockup/elementupdate.html b/mockup/elementupdate.html index 2e770e4c..dff1fe92 100644 --- a/mockup/elementupdate.html +++ b/mockup/elementupdate.html @@ -168,6 +168,7 @@ + -- GitLab From dea7c8c4a9fd237d266ee77aa58f40a035ba71ec Mon Sep 17 00:00:00 2001 From: Carsten Rose Date: Sat, 12 Aug 2017 14:27:06 +0200 Subject: [PATCH 2/2] AbstractBuildForm.php: add variant to update md5 via form-update. Remove test 'span' wrap around 'recordHashMd5'. Introduce constants API_FORM_UPDATE_*. --- extension/qfq/qfq/AbstractBuildForm.php | 19 +++++++++++-------- extension/qfq/qfq/Constants.php | 11 ++++++----- extension/qfq/qfq/form/Dirty.php | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 20d6a8e8..ed7160f0 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -191,8 +191,13 @@ abstract class AbstractBuildForm { // element-update: with 'value' $recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO); $md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId); + + // Via 'element-update' $json[][API_ELEMENT_UPDATE][DIRTY_RECORD_HASH_MD5][API_ELEMENT_ATTRIBUTE]['value'] = $md5; + // Via 'form-update' +// $json[] = [API_FORM_UPDATE_FORM_ELEMENT => DIRTY_RECORD_HASH_MD5, API_FORM_UPDATE_VALUE => $md5, +// API_FORM_UPDATE_DISABLED => false, API_FORM_UPDATE_REQUIRED => false ]; } } @@ -303,15 +308,13 @@ abstract class AbstractBuildForm { * @throws \qfq\CodeException * @throws \qfq\DbException */ - public function buildInputRecordHashMd5($flagWithSpan = true) { + public function buildInputRecordHashMd5() { $recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO); $md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId); $data = ""; - if ($flagWithSpan) { - $data = Support::wrapTag('', $data); - } +// $data = ""; return $data; } @@ -768,7 +771,7 @@ abstract class AbstractBuildForm { $json = $this->getJsonFeMode($formElement[FE_MODE]); // disabled, required - $json['form-element'] = $htmlFormElementName; + $json[API_FORM_UPDATE_FORM_ELEMENT] = $htmlFormElementName; if (isset($formElement[FE_FLAG_ROW_OPEN_TAG]) && isset($formElement[FE_FLAG_ROW_CLOSE_TAG])) { $flagRowUpdate = ($formElement[FE_FLAG_ROW_OPEN_TAG] && $formElement[FE_FLAG_ROW_CLOSE_TAG]); @@ -776,9 +779,9 @@ abstract class AbstractBuildForm { $flagRowUpdate = true; } - // 'value' update via 'form-update' on the full row: only if there is no other FE that row + // 'value' update via 'form-update' on the full row: only if there is no other FE in that row if ($flagRowUpdate) { - $json['value'] = $value; + $json[API_FORM_UPDATE_VALUE] = $value; } if (isset($formElement[FE_LABEL])) { @@ -838,7 +841,7 @@ abstract class AbstractBuildForm { $this->getFeMode($feMode, $dummy, $disabled, $required); - return [API_JSON_DISABLED => $disabled === 'yes', API_JSON_REQUIRED => $required === 'yes']; + return [API_FORM_UPDATE_DISABLED => $disabled === 'yes', API_FORM_UPDATE_REQUIRED => $required === 'yes']; } /** diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index 6fd804a1..ac74e64e 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -587,6 +587,12 @@ const API_LOCK_TIMEOUT = 'lock_timeout'; const API_FIELD_NAME = 'field-name'; const API_FIELD_MESSAGE = 'field-message'; const API_FORM_UPDATE = 'form-update'; +const API_FORM_UPDATE_FORM_ELEMENT = 'form-element'; +const API_FORM_UPDATE_VALUE = 'value'; +const API_FORM_UPDATE_HIDDEN = 'hidden'; +const API_FORM_UPDATE_DISABLED = 'disabled'; +const API_FORM_UPDATE_REQUIRED = 'required'; + const API_ELEMENT_UPDATE = 'element-update'; const API_ELEMENT_ATTRIBUTE = 'attr'; const API_ELEMENT_CONTENT = 'content'; @@ -594,15 +600,10 @@ const API_SUBMIT_REASON = 'submit_reason'; const API_SUBMIT_REASON_SAVE = 'save'; const API_SUBMIT_REASON_SAVE_CLOSE = 'save,close'; - const API_LOCK_ACTION_LOCK = 'lock'; const API_LOCK_ACTION_EXTEND = 'extend'; const API_LOCK_ACTION_RELEASE = 'release'; -const API_JSON_HIDDEN = 'hidden'; -const API_JSON_DISABLED = 'disabled'; -const API_JSON_REQUIRED = 'required'; - const API_ANSWER_STATUS_SUCCESS = 'success'; const API_ANSWER_STATUS_CONFLICT = 'conflict'; const API_ANSWER_STATUS_CONFLICT_ALLOW_FORCE = 'conflict_allow_force'; diff --git a/extension/qfq/qfq/form/Dirty.php b/extension/qfq/qfq/form/Dirty.php index ee378b14..33d27b35 100644 --- a/extension/qfq/qfq/form/Dirty.php +++ b/extension/qfq/qfq/form/Dirty.php @@ -249,6 +249,7 @@ class Dirty { $record = $this->db->sql("SELECT * FROM $tableName WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to lock not found."); $rcMd5 = OnArray::getMd5($record); + return ($recordHashMd5 != $rcMd5); } -- GitLab