From 5f570acf4001f9a6352bfb218f7298f8dd1e9bf7 Mon Sep 17 00:00:00 2001 From: Thomas Famula Date: Tue, 18 Jun 2019 14:48:39 +0200 Subject: [PATCH 01/13] getUpdateOnLoadCode for all Inputs --- .../Component/Input/Field/Checkbox.php | 15 +++++++++ .../Component/Input/Field/Group.php | 17 ++++++++-- .../Component/Input/Field/Input.php | 31 ------------------- .../Component/Input/Field/MultiSelect.php | 26 ++++++++++++++++ .../Component/Input/Field/Numeric.php | 15 +++++++++ .../Component/Input/Field/Password.php | 15 +++++++++ .../Component/Input/Field/Radio.php | 14 +++++++++ .../Component/Input/Field/Select.php | 20 ------------ .../Component/Input/Field/Tag.php | 17 ++++++++++ .../Component/Input/Field/Text.php | 20 ------------ .../Component/Input/Field/Textarea.php | 15 +++++++++ .../templates/default/Input/tpl.checkbox.html | 2 +- .../default/Input/tpl.multiselect.html | 2 +- .../templates/default/Input/tpl.numeric.html | 2 +- .../templates/default/Input/tpl.password.html | 2 +- .../templates/default/Input/tpl.select.html | 2 +- src/UI/templates/default/Input/tpl.text.html | 2 +- 17 files changed, 137 insertions(+), 80 deletions(-) diff --git a/src/UI/Implementation/Component/Input/Field/Checkbox.php b/src/UI/Implementation/Component/Input/Field/Checkbox.php index b959a678bc6c..d88d0ea383cc 100644 --- a/src/UI/Implementation/Component/Input/Field/Checkbox.php +++ b/src/UI/Implementation/Component/Input/Field/Checkbox.php @@ -7,6 +7,7 @@ use ILIAS\Data\Factory as DataFactory; use ILIAS\UI\Component as C; +use ILIAS\UI\Component\Signal; use ILIAS\UI\Implementation\Component\JavaScriptBindable; use ILIAS\UI\Implementation\Component\Triggerer; use ILIAS\UI\Implementation\Component\Input\InputData; @@ -85,4 +86,18 @@ public function withInput(InputData $post_input) { return $clone; } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').prop('checked').toString()); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id').prop('checked').toString());"; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Group.php b/src/UI/Implementation/Component/Input/Field/Group.php index 5ee19500d964..dadc2105e704 100644 --- a/src/UI/Implementation/Component/Input/Field/Group.php +++ b/src/UI/Implementation/Component/Input/Field/Group.php @@ -66,9 +66,7 @@ public function withRequired($is_required) { } public function withOnUpdate(Signal $signal) { - //TODO: use $clone = parent::withOnUpdate($signal); once the exception there - //is solved. - $clone = $this->withTriggeredSignal($signal, 'update'); + $clone = parent::withOnUpdate($signal); $inputs = []; foreach ($this->inputs as $key => $input) { $inputs[$key] = $input->withOnUpdate($signal); @@ -76,4 +74,17 @@ public function withOnUpdate(Signal $signal) { $clone->inputs = $inputs; return $clone; } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function () { + /* + * Currently, there is no use case for Group here. The single Inputs + * within the Group are responsible for handling getUpdateOnLoadCode(). + */ + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Input.php b/src/UI/Implementation/Component/Input/Field/Input.php index 80aebf940d34..11a29531708c 100644 --- a/src/UI/Implementation/Component/Input/Field/Input.php +++ b/src/UI/Implementation/Component/Input/Field/Input.php @@ -467,34 +467,11 @@ final public function getContent() { return $this->content; } - /** - * @inheritdoc - */ - public function getUpdateOnLoadCode(): \Closure - { - throw new \Exception( - "This is not implemented yet. Every Input needs to implement ". - "this, but to be able to move on currently this is broken. ". - "If you see this message, please file a bug at mantis.ilias.de. ". - "Also have a look into the roadmap: \"Implement `Input::getUpdateOnLoadCode`, ". - "`Input::withOnUpdate` and `Input::appendOnUpdate` for every Input" - ); - // TODO: This method will need to be removed. - } - /** * @inheritdoc */ public function withOnUpdate(Signal $signal) { - // TODO: This exception will need to be removed. - throw new \Exception( - "This is not implemented yet. Every Input needs to implement ". - "this, but to be able to move on currently this is broken. ". - "If you see this message, please file a bug at mantis.ilias.de. ". - "Also have a look into the roadmap: \"Implement `Input::getUpdateOnLoadCode`, ". - "`Input::withOnUpdate` and `Input::appendOnUpdate` for every Input" - ); return $this->withTriggeredSignal($signal, 'update'); } @@ -503,14 +480,6 @@ public function withOnUpdate(Signal $signal) */ public function appendOnUpdate(Signal $signal) { - // TODO: This exception will need to be removed. - throw new \Exception( - "This is not implemented yet. Every Input needs to implement ". - "this, but to be able to move on currently this is broken. ". - "If you see this message, please file a bug at mantis.ilias.de. ". - "Also have a look into the roadmap: \"Implement `Input::getUpdateOnLoadCode`, ". - "`Input::withOnUpdate` and `Input::appendOnUpdate` for every Input" - ); return $this->appendTriggeredSignal($signal, 'update'); } } diff --git a/src/UI/Implementation/Component/Input/Field/MultiSelect.php b/src/UI/Implementation/Component/Input/Field/MultiSelect.php index a7702b5b9572..086796c70758 100644 --- a/src/UI/Implementation/Component/Input/Field/MultiSelect.php +++ b/src/UI/Implementation/Component/Input/Field/MultiSelect.php @@ -6,6 +6,7 @@ use ILIAS\UI\Component as C; use ILIAS\Data\Factory as DataFactory; +use ILIAS\UI\Component\Signal; /** * This implements the multi-select input. @@ -63,4 +64,29 @@ function ($value) { return $constraint; } + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "var checkedBoxes = function() { + var options = {}; + var options_combined = []; + $('#$id').find('input').each(function() { + options[$(this).val()] = $(this).prop('checked').toString(); + }); + for (let [key, value] of Object.entries(options)) { + options_combined.push(key + ': ' + value); + } + return options_combined.join(', '); + } + $('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', checkedBoxes()); + }); + il.UI.input.onFieldUpdate(event, '$id', checkedBoxes()); + "; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Numeric.php b/src/UI/Implementation/Component/Input/Field/Numeric.php index 101b79117384..ff2ffa794ca6 100644 --- a/src/UI/Implementation/Component/Input/Field/Numeric.php +++ b/src/UI/Implementation/Component/Input/Field/Numeric.php @@ -7,6 +7,7 @@ use ILIAS\Data\Factory as DataFactory; use ILIAS\UI\Component as C; +use ILIAS\UI\Component\Signal; /** * This implements the numeric input. @@ -51,4 +52,18 @@ protected function isClientSideValueOk($value) { protected function getConstraintForRequirement() { return $this->refinery->numeric()->isNumeric(); } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val()); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());"; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Password.php b/src/UI/Implementation/Component/Input/Field/Password.php index 34830654e9d0..bc3ce4a54184 100644 --- a/src/UI/Implementation/Component/Input/Field/Password.php +++ b/src/UI/Implementation/Component/Input/Field/Password.php @@ -7,6 +7,7 @@ use ILIAS\UI\Component as C; use ILIAS\Data\Password as PWD; use ILIAS\Data\Factory as DataFactory; +use ILIAS\UI\Component\Signal; use ILIAS\UI\Implementation\Component\ComponentHelper; use ILIAS\UI\Implementation\Component\SignalGeneratorInterface; use ILIAS\UI\Implementation\Component\JavaScriptBindable; @@ -159,4 +160,18 @@ public function getRevealSignal() { public function getMaskSignal() { return $this->signal_mask; } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').find('input').val().replace(/./g, '*')); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id').find('input').val().replace(/./g, '*'));"; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Radio.php b/src/UI/Implementation/Component/Input/Field/Radio.php index 6da60361a02f..c53bf6ee2211 100644 --- a/src/UI/Implementation/Component/Input/Field/Radio.php +++ b/src/UI/Implementation/Component/Input/Field/Radio.php @@ -5,6 +5,7 @@ namespace ILIAS\UI\Implementation\Component\Input\Field; use ILIAS\UI\Component as C; +use ILIAS\UI\Component\Signal; use ILIAS\UI\Implementation\Component\Input\InputData; use ILIAS\UI\Implementation\Component\Input\NameSource; use ILIAS\UI\Implementation\Component\JavaScriptBindable; @@ -160,4 +161,17 @@ public function withInput(InputData $post_input) { return $clone; } + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id input:checked').val()); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id input:checked').val());"; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Select.php b/src/UI/Implementation/Component/Input/Field/Select.php index 52a75893b01e..ed20f54b02b8 100644 --- a/src/UI/Implementation/Component/Input/Field/Select.php +++ b/src/UI/Implementation/Component/Input/Field/Select.php @@ -74,24 +74,4 @@ public function getUpdateOnLoadCode(): \Closure return $code; }; } - - /** - * @inheritdoc - */ - public function withOnUpdate(Signal $signal) - { - // TODO: This method will need to be removed. - // See ILIAS\UI\Implementation\Component\Input\Field\Input - return $this->withTriggeredSignal($signal, 'update'); - } - - /** - * @inheritdoc - */ - public function appendOnUpdate(Signal $signal) - { - // TODO: This method will need to be removed. - // See ILIAS\UI\Implementation\Component\Input\Field\Input - return $this->appendTriggeredSignal($signal, 'update'); - } } diff --git a/src/UI/Implementation/Component/Input/Field/Tag.php b/src/UI/Implementation/Component/Input/Field/Tag.php index 88bff16c16f0..fc1fc1bae975 100644 --- a/src/UI/Implementation/Component/Input/Field/Tag.php +++ b/src/UI/Implementation/Component/Input/Field/Tag.php @@ -286,4 +286,21 @@ public function withAdditionalOnTagAdded(Signal $signal): C\Input\Field\Tag { public function withAdditionalOnTagRemoved(Signal $signal): C\Input\Field\Tag { return $this->appendTriggeredSignal($signal, self::EVENT_ITEM_REMOVED); } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('itemAdded', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val()); + }); + $('#$id').on('itemRemoved', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val()); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());"; + return $code; + }; + } } diff --git a/src/UI/Implementation/Component/Input/Field/Text.php b/src/UI/Implementation/Component/Input/Field/Text.php index ed5bb43e4528..f6867363d67d 100644 --- a/src/UI/Implementation/Component/Input/Field/Text.php +++ b/src/UI/Implementation/Component/Input/Field/Text.php @@ -55,24 +55,4 @@ public function getUpdateOnLoadCode(): \Closure return $code; }; } - - /** - * @inheritdoc - */ - public function withOnUpdate(Signal $signal) - { - // TODO: This method will need to be removed. - // See ILIAS\UI\Implementation\Component\Input\Field\Input - return $this->withTriggeredSignal($signal, 'update'); - } - - /** - * @inheritdoc - */ - public function appendOnUpdate(Signal $signal) - { - // TODO: This method will need to be removed. - // See ILIAS\UI\Implementation\Component\Input\Field\Input - return $this->appendTriggeredSignal($signal, 'update'); - } } diff --git a/src/UI/Implementation/Component/Input/Field/Textarea.php b/src/UI/Implementation/Component/Input/Field/Textarea.php index 9df296e9e762..cf87a0e7958b 100644 --- a/src/UI/Implementation/Component/Input/Field/Textarea.php +++ b/src/UI/Implementation/Component/Input/Field/Textarea.php @@ -5,6 +5,7 @@ namespace ILIAS\UI\Implementation\Component\Input\Field; use ILIAS\UI\Component as C; +use ILIAS\UI\Component\Signal; use ILIAS\UI\Implementation\Component\JavaScriptBindable; use ILIAS\Data\Factory as DataFactory; @@ -105,4 +106,18 @@ public function isLimited() } return false; } + + /** + * @inheritdoc + */ + public function getUpdateOnLoadCode(): \Closure + { + return function ($id) { + $code = "$('#$id').on('input', function(event) { + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val()); + }); + il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());"; + return $code; + }; + } } diff --git a/src/UI/templates/default/Input/tpl.checkbox.html b/src/UI/templates/default/Input/tpl.checkbox.html index 8fa5d7a924ee..6924eb84b83c 100644 --- a/src/UI/templates/default/Input/tpl.checkbox.html +++ b/src/UI/templates/default/Input/tpl.checkbox.html @@ -1 +1 @@ - id="{ID}" value="checked" {VALUE}="checked" name="{NAME}" {DISABLED} class="form-control form-control-sm" /> + {VALUE}="checked" name="{NAME}" {DISABLED} class="form-control form-control-sm" /> diff --git a/src/UI/templates/default/Input/tpl.multiselect.html b/src/UI/templates/default/Input/tpl.multiselect.html index 835e3baa1c8a..7b8d961ee503 100644 --- a/src/UI/templates/default/Input/tpl.multiselect.html +++ b/src/UI/templates/default/Input/tpl.multiselect.html @@ -1,4 +1,4 @@ -