Commit acc907fd authored by Carsten  Rose's avatar Carsten Rose

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

Implements #9679: formModeGlobal is now also used via STORE_USER - set formModeGlobal systemwide for a specific user (session).
parent f9700c9e
Pipeline #2824 passed with stages
in 2 minutes and 48 seconds
......@@ -2692,50 +2692,92 @@ See also: `delete-record`_.
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
existing *Form* just to display the form data, without a possibility for the user to change any data of the form.
Mode
;;;;
* *standard*:
* The form will behave like defined in the form editor.
* Missing required values will a) be indicated and b) block saving the record.
* `requiredOff` | `requiredOffButMark` :
* **readonly**: all `FormElement` of the whole form are temporarily in `readonly` mode.
* Both modes are identical, but 'requiredOffButMark' will mark all missing fields to the user.
* 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**:
* All `FormElement` with `mode=required`, will be handled as `mode=show`.
* The user can save the form without providing all necessary data!
* Check `STORE_VARS`_ for the variable `{{allRequiredGiven:V}}` - it shows if the form has been filled completely.
* Scenario 1:
* 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`.
* The user can save the form without filling all required inputs!
* Missing required inputs will be marked:
* On lost focus.
* When the user saves the record.
Extra
;;;;;
Via `STORE_VARS`_ the variable `{{allRequiredGiven:V}}` shows, if the form has been filled completely - independent of
the mode. The variable is only accessible during form save.
Usage example
;;;;;;;;;;;;;
*Readonly*
Code: ``SELECT 'p:{{pageAlias}}&form=person&r=1&formModeGlobal=readonly|s|t:View|s|b' AS _link``
* The form is called with SIP parameter ``formModeGlobal=readonly`` or ``form.parameter.mode=readonly``.
* The user can't change any data.
*Readonly systemwide*
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.
* 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. 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.
*Draft Mode 1*
* Scenario 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::
* 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.
{{UPDATE <table> SET dataValid={{allRequiredGiven:V0}} WHERE id={{id:R}} }}
*Draft Mode 2*
* In your your application logic, you can open the next process step if all data is given by evaluating `{{allRequiredGiven:V0}}`.
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::
The following shows the same *Form* in the `regular`, `readonly`, `requiredOff` and `requiredOffButMark` mode::
{{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,
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
* In the application logic, open the next process step if all data is given by evaluating `dataValid`.
FormElements
------------
......
......@@ -594,10 +594,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
$attribute['class'] = 'form-horizontal';
$attribute['data-toggle'] = 'validator';
$formModeGlobal = $this->store::getVar(F_MODE_GLOBAL, STORE_SIP . STORE_EMPTY);
if ($formModeGlobal == '') {
$formModeGlobal = $this->formSpec[F_MODE_GLOBAL] ?? '';
}
$formModeGlobal = Support::getFormModeGlobal($this->formSpec[F_MODE_GLOBAL] ?? '');
if ($formModeGlobal == F_MODE_REQUIRED_OFF_BUT_MARK || $formModeGlobal == F_MODE_REQUIRED_OFF) {
$attribute[DATA_REQUIRED_OFF_BUT_MARK] = 'true';
......
......@@ -1546,4 +1546,27 @@ class Support {
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 {
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.
if ($formSpec[F_MODE] == '') {
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP);
if ($formModeGlobal !== false) {
$formSpec[F_MODE] = $formModeGlobal;
}
}
// if ($formSpec[F_MODE] == '') {
// $formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP);
// if ($formModeGlobal !== false) {
// $formSpec[F_MODE] = $formModeGlobal;
// }
// }
//
$formSpec[F_MODE] = Support::getFormModeGlobal($formSpec[F_MODE]);
if ($formSpec[F_MODE] == F_MODE_READONLY) {
$formSpec[F_SHOW_BUTTON] = FORM_BUTTON_CLOSE;
......
......@@ -544,12 +544,9 @@ class Save {
*/
public function checkRequiredHidden() {
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP . STORE_EMPTY);
if ($formModeGlobal == '') {
$formModeGlobal = $this->formSpec[F_MODE_GLOBAL] ?? '';
}
$formModeGlobal = Support::getFormModeGlobal($this->formSpec[F_MODE_GLOBAL] ?? '');
$reportRequiredFailed = true;
switch ($formModeGlobal) {
case F_MODE_REQUIRED_OFF:
case F_MODE_REQUIRED_OFF_BUT_MARK:
......
......@@ -179,7 +179,7 @@ class FillStoreForm {
$newValues = array();
$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 == '') {
# During 'update': fake all elements to be not 'required'.
......
Markdown is supported
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