Commit 65c70895 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'F9679formModeGlobalSTORE_USER' into 'master'

Implements #9679: formModeGlobal is now also used via STORE_USER - set...

See merge request !212
parents f9700c9e acc907fd
Pipeline #2825 passed with stages
in 2 minutes and 34 seconds
...@@ -2692,50 +2692,92 @@ See also: `delete-record`_. ...@@ -2692,50 +2692,92 @@ See also: `delete-record`_.
Form mode global Form mode global
"""""""""""""""" """"""""""""""""
The Form global mode `mode` is given by default with `{{formModeGlobal:SE:alnumx}}`. A form can be operated in modes: *standard* | **readonly** | **requiredOff** | **requiredOffButMark**.
Optional it might be defined via *Form.parameter* :: Mode *standard* is given if none of the others are defined.
mode = readonly | requiredOff | requiredOffButMark The `mode` is given via (in this priority):
* Via STORE_USER: {{formModeGlobal:U}}
* Via STORE_SIP: {{formModeGlobal:S}}
* Via Form: `form.parameter.mode=...`
* `readonly`: all `FormElement` of the whole form are temporarily in `readonly` mode. This is a fast way to use an Mode
existing *Form* just to display the form data, without a possibility for the user to change any data of the form. ;;;;
* *standard*:
* The form will behave like defined in the form editor.
* Missing required values will a) be indicated and b) block saving the record.
* **readonly**: all `FormElement` of the whole form are temporarily in `readonly` mode.
* Fast way to display the form data, without a possibility for the user to change any data of the form.
* The mode will be be inherited to all subforms.
* `requiredOff` | `requiredOffButMark` : * **requiredOff**:
* Both modes are identical, but 'requiredOffButMark' will mark all missing fields to the user. * All `FormElement` with `mode=required`, will be handled as `mode=show`.
* The user can save the form without filling all required inputs!
* Required inputs are indicated by a red star - missing values **won't** be complained.
* **requiredOffButMark**:
* All `FormElement` with `mode=required`, will be handled as `mode=show`. * All `FormElement` with `mode=required`, will be handled as `mode=show`.
* The user can save the form without providing all necessary data! * The user can save the form without filling all required inputs!
* Check `STORE_VARS`_ for the variable `{{allRequiredGiven:V}}` - it shows if the form has been filled completely. * Missing required inputs will be marked:
* Scenario 1:
* A form has one or more FormElement with 'fe.type=required'. * On lost focus.
* Calling the form with `formModeGlobal=requiredOff` will allow the user to save the form, even if not all * When the user saves the record.
FE.type=required elements are given. Name this the 'draft' mode.
* Calling the form without `formModeGlobal` (this is the default), forces the user to fill out
all FE.type=required fields. Name this the 'final submit' mode.
* Scenario 2: Extra
;;;;;
* A form has one or more FormElement with 'fe.type=required'. Via `STORE_VARS`_ the variable `{{allRequiredGiven:V}}` shows, if the form has been filled completely - independent of
* Calling the form with `formModeGlobal=requiredOff` will allow the user to save the form, even if not all the mode. The variable is only accessible during form save.
FE.type=required elements are given.
* Define an FE-Action 'afterSave', and do some action on `{{allRequiredGiven:V0}}` like::
{{UPDATE <table> SET dataValid={{allRequiredGiven:V0}} WHERE id={{id:R}} }} Usage example
;;;;;;;;;;;;;
*Readonly*
Code: ``SELECT 'p:{{pageAlias}}&form=person&r=1&formModeGlobal=readonly|s|t:View|s|b' AS _link``
* In your your application logic, you can open the next process step if all data is given by evaluating `{{allRequiredGiven:V0}}`. * The form is called with SIP parameter ``formModeGlobal=readonly`` or ``form.parameter.mode=readonly``.
* The user can't change any data.
*Readonly systemwide*
The following shows the same *Form* in the `regular`, `readonly`, `requiredOff` and `requiredOffButMark` mode:: Code (somewhere): ``SELECT 'requiredoff' AS '_=formModeGlobal'``
Code: ``SELECT 'p:{{pageAlias}}&form=person&r=1|s|t:View|s|b' AS _link``
* The STORE_USER variable is set `formModeGlobal=readonly`.
* All forms will be shown in readonly mode - fast option to give a user access to the website, without the possibility to
change any data.
*Draft Mode 1*
Code: ``SELECT 'p:{{pageAlias}}&form=person&r=1&formModeGlobal=readquiredOff|s|t:View|s|b' AS _link``
* A form has one or more FormElement with 'fe.type=required'.
* Opening the form with `formModeGlobal=requiredOff` will allow the user to save the form, even if not all
FE.type=required elements are given. This can be called 'draft' mode.
* Opening the form without `formModeGlobal` (that's the default), forces the user to fill out
all FE.type=required fields. This can be called 'final submit' mode.
*Draft Mode 2*
Code: ``SELECT 'p:{{pageAlias}}&form=person&r=1&formModeGlobal=readquiredOff|s|t:View|s|b' AS _link``
* A form has one or more FormElement with 'fe.type=required'.
* Calling the form with `formModeGlobal=requiredOff` will allow the user to save the form, even if not all
FE.type=required elements are given.
* Define an FE-Action 'afterSave', and do some action on `{{allRequiredGiven:V0}}` like::
{{UPDATE <table> SET dataValid={{allRequiredGiven:V0}} WHERE id={{id:R}} }}
10.sql = SELECT CONCAT('p:{{pageAlias:T}}&form=person&r=', p.id, '|Regular') as _pagee, * In the application logic, open the next process step if all data is given by evaluating `dataValid`.
CONCAT('p:{{pageAlias:T}}&form=person&formModeGlobal=readonly&r=', p.id, '|Readonly') as _pagee,
CONCAT('p:{{pageAlias:T}}&form=person&formModeGlobal=requiredOff&r=', p.id, '|Required off') as _pagee
CONCAT('p:{{pageAlias:T}}&form=person&formModeGlobal=requiredOffButMark&r=', p.id, '|Required off') as _pagee
FROM Person AS p
FormElements FormElements
------------ ------------
......
...@@ -594,10 +594,7 @@ class BuildFormBootstrap extends AbstractBuildForm { ...@@ -594,10 +594,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
$attribute['class'] = 'form-horizontal'; $attribute['class'] = 'form-horizontal';
$attribute['data-toggle'] = 'validator'; $attribute['data-toggle'] = 'validator';
$formModeGlobal = $this->store::getVar(F_MODE_GLOBAL, STORE_SIP . STORE_EMPTY); $formModeGlobal = Support::getFormModeGlobal($this->formSpec[F_MODE_GLOBAL] ?? '');
if ($formModeGlobal == '') {
$formModeGlobal = $this->formSpec[F_MODE_GLOBAL] ?? '';
}
if ($formModeGlobal == F_MODE_REQUIRED_OFF_BUT_MARK || $formModeGlobal == F_MODE_REQUIRED_OFF) { if ($formModeGlobal == F_MODE_REQUIRED_OFF_BUT_MARK || $formModeGlobal == F_MODE_REQUIRED_OFF) {
$attribute[DATA_REQUIRED_OFF_BUT_MARK] = 'true'; $attribute[DATA_REQUIRED_OFF_BUT_MARK] = 'true';
......
...@@ -1546,4 +1546,27 @@ class Support { ...@@ -1546,4 +1546,27 @@ class Support {
return uniqid(); return uniqid();
} }
/**
* Get formModeGlobal from STORE_USER, STORE_SIP or directly from $mode.
*
* @param $mode
* @return array|string
* @throws \CodeException
* @throws \UserFormException
*/
public static function getFormModeGlobal($mode) {
$formModeGlobal = self::$store->getVar(F_MODE_GLOBAL, STORE_USER);
if ($formModeGlobal === '' || $formModeGlobal === false) {
$formModeGlobal = self::$store->getVar(F_MODE_GLOBAL, STORE_SIP);
}
if ($formModeGlobal === '' || $formModeGlobal === false) {
$formModeGlobal = $mode;
}
return $formModeGlobal;
}
} }
\ No newline at end of file
...@@ -1443,12 +1443,15 @@ class QuickFormQuery { ...@@ -1443,12 +1443,15 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_FE_MIN_WIDTH, F_FE_MIN_WIDTH_DEFAULT); Support::setIfNotSet($formSpec, F_FE_MIN_WIDTH, F_FE_MIN_WIDTH_DEFAULT);
// In case there is no F_MODE defined on the form, check if there is one in STORE_SIP. // In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
if ($formSpec[F_MODE] == '') { // if ($formSpec[F_MODE] == '') {
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP); // $formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP);
if ($formModeGlobal !== false) { // if ($formModeGlobal !== false) {
$formSpec[F_MODE] = $formModeGlobal; // $formSpec[F_MODE] = $formModeGlobal;
} // }
} // }
//
$formSpec[F_MODE] = Support::getFormModeGlobal($formSpec[F_MODE]);
if ($formSpec[F_MODE] == F_MODE_READONLY) { if ($formSpec[F_MODE] == F_MODE_READONLY) {
$formSpec[F_SHOW_BUTTON] = FORM_BUTTON_CLOSE; $formSpec[F_SHOW_BUTTON] = FORM_BUTTON_CLOSE;
......
...@@ -544,12 +544,9 @@ class Save { ...@@ -544,12 +544,9 @@ class Save {
*/ */
public function checkRequiredHidden() { public function checkRequiredHidden() {
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP . STORE_EMPTY); $formModeGlobal = Support::getFormModeGlobal($this->formSpec[F_MODE_GLOBAL] ?? '');
if ($formModeGlobal == '') {
$formModeGlobal = $this->formSpec[F_MODE_GLOBAL] ?? '';
}
$reportRequiredFailed = true; $reportRequiredFailed = true;
switch ($formModeGlobal) { switch ($formModeGlobal) {
case F_MODE_REQUIRED_OFF: case F_MODE_REQUIRED_OFF:
case F_MODE_REQUIRED_OFF_BUT_MARK: case F_MODE_REQUIRED_OFF_BUT_MARK:
......
...@@ -179,7 +179,7 @@ class FillStoreForm { ...@@ -179,7 +179,7 @@ class FillStoreForm {
$newValues = array(); $newValues = array();
$clientValues = $this->store->getStore(STORE_CLIENT); $clientValues = $this->store->getStore(STORE_CLIENT);
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP . STORE_EMPTY); $formModeGlobal = Support::getFormModeGlobal($this->formSpec[F_MODE_GLOBAL] ?? '');
if ($formMode == FORM_UPDATE && $formModeGlobal == '') { if ($formMode == FORM_UPDATE && $formModeGlobal == '') {
# During 'update': fake all elements to be not 'required'. # During 'update': fake all elements to be not 'required'.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment