diff --git a/availability/amd/build/availability_more.min.js b/availability/amd/build/availability_more.min.js index 22358c76610..a76c3be3271 100644 --- a/availability/amd/build/availability_more.min.js +++ b/availability/amd/build/availability_more.min.js @@ -2,6 +2,8 @@ define("core_availability/availability_more",["exports"],(function(_exports){Obj /** * Show more action for availablity information. * + * @deprecated since 4.3 MDL-78204. + * @todo MDL-78489 This will be deleted in Moodle 4.7. * @module core_availability/availability_more * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/availability/amd/build/availability_more.min.js.map b/availability/amd/build/availability_more.min.js.map index 35247475686..254de74493d 100644 --- a/availability/amd/build/availability_more.min.js.map +++ b/availability/amd/build/availability_more.min.js.map @@ -1 +1 @@ -{"version":3,"file":"availability_more.min.js","sources":["../src/availability_more.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Show more action for availablity information.\n *\n * @module core_availability/availability_more\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Availability info selectors.\n */\nconst Selectors = {\n regions: {\n availability: '[data-region=\"availability-multiple\"]',\n },\n actions: {\n showmorelink: '[data-action=\"showmore\"]'\n },\n classes: {\n hidden: 'd-none',\n visible: 'd-block',\n\n }\n};\n\n/**\n * Displays all the availability information in case part of it is hidden.\n *\n * @param {Event} event the triggered event\n */\nconst showMoreHandler = (event) => {\n const triggerElement = event.target.closest(Selectors.actions.showmorelink);\n if (triggerElement === null) {\n return;\n }\n const container = triggerElement.closest(Selectors.regions.availability);\n container.querySelectorAll('.' + Selectors.classes.hidden).forEach(function(node) {\n node.classList.remove(Selectors.classes.hidden);\n });\n container.querySelectorAll('.' + Selectors.classes.visible).forEach(function(node) {\n node.classList.remove(Selectors.classes.visible);\n node.classList.add(Selectors.classes.hidden);\n });\n event.preventDefault();\n};\n\n/**\n * Initialise the eventlister for the showmore action on availability information.\n *\n * @method init\n */\nexport const init = () => {\n const body = document.querySelector('body');\n if (!body.dataset.showmoreactive) {\n document.addEventListener('click', showMoreHandler);\n body.dataset.showmoreactive = 1;\n }\n};\n"],"names":["Selectors","availability","showmorelink","hidden","visible","showMoreHandler","event","triggerElement","target","closest","container","querySelectorAll","forEach","node","classList","remove","add","preventDefault","body","document","querySelector","dataset","showmoreactive","addEventListener"],"mappings":";;;;;;;;MA0BMA,kBACO,CACLC,aAAc,yCAFhBD,kBAIO,CACLE,aAAc,4BALhBF,kBAOO,CACLG,OAAQ,SACRC,QAAS,WAUXC,gBAAmBC,cACfC,eAAiBD,MAAME,OAAOC,QAAQT,kBAAkBE,iBACvC,OAAnBK,4BAGEG,UAAYH,eAAeE,QAAQT,kBAAkBC,cAC3DS,UAAUC,iBAAiB,IAAMX,kBAAkBG,QAAQS,SAAQ,SAASC,MACxEA,KAAKC,UAAUC,OAAOf,kBAAkBG,WAE5CO,UAAUC,iBAAiB,IAAMX,kBAAkBI,SAASQ,SAAQ,SAASC,MACzEA,KAAKC,UAAUC,OAAOf,kBAAkBI,SACxCS,KAAKC,UAAUE,IAAIhB,kBAAkBG,WAEzCG,MAAMW,gCAQU,WACVC,KAAOC,SAASC,cAAc,QAC/BF,KAAKG,QAAQC,iBACdH,SAASI,iBAAiB,QAASlB,iBACnCa,KAAKG,QAAQC,eAAiB"} \ No newline at end of file +{"version":3,"file":"availability_more.min.js","sources":["../src/availability_more.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Show more action for availablity information.\n *\n * @deprecated since 4.3 MDL-78204.\n * @todo MDL-78489 This will be deleted in Moodle 4.7.\n * @module core_availability/availability_more\n * @copyright 2021 Bas Brands \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Availability info selectors.\n */\nconst Selectors = {\n regions: {\n availability: '[data-region=\"availability-multiple\"]',\n },\n actions: {\n showmorelink: '[data-action=\"showmore\"]'\n },\n classes: {\n hidden: 'd-none',\n visible: 'd-block',\n\n }\n};\n\n/**\n * Displays all the availability information in case part of it is hidden.\n *\n * @param {Event} event the triggered event\n */\nconst showMoreHandler = (event) => {\n const triggerElement = event.target.closest(Selectors.actions.showmorelink);\n if (triggerElement === null) {\n return;\n }\n const container = triggerElement.closest(Selectors.regions.availability);\n container.querySelectorAll('.' + Selectors.classes.hidden).forEach(function(node) {\n node.classList.remove(Selectors.classes.hidden);\n });\n container.querySelectorAll('.' + Selectors.classes.visible).forEach(function(node) {\n node.classList.remove(Selectors.classes.visible);\n node.classList.add(Selectors.classes.hidden);\n });\n event.preventDefault();\n};\n\n/**\n * Initialise the eventlister for the showmore action on availability information.\n *\n * @method init\n */\nexport const init = () => {\n const body = document.querySelector('body');\n if (!body.dataset.showmoreactive) {\n document.addEventListener('click', showMoreHandler);\n body.dataset.showmoreactive = 1;\n }\n};\n"],"names":["Selectors","availability","showmorelink","hidden","visible","showMoreHandler","event","triggerElement","target","closest","container","querySelectorAll","forEach","node","classList","remove","add","preventDefault","body","document","querySelector","dataset","showmoreactive","addEventListener"],"mappings":";;;;;;;;;;MA4BMA,kBACO,CACLC,aAAc,yCAFhBD,kBAIO,CACLE,aAAc,4BALhBF,kBAOO,CACLG,OAAQ,SACRC,QAAS,WAUXC,gBAAmBC,cACfC,eAAiBD,MAAME,OAAOC,QAAQT,kBAAkBE,iBACvC,OAAnBK,4BAGEG,UAAYH,eAAeE,QAAQT,kBAAkBC,cAC3DS,UAAUC,iBAAiB,IAAMX,kBAAkBG,QAAQS,SAAQ,SAASC,MACxEA,KAAKC,UAAUC,OAAOf,kBAAkBG,WAE5CO,UAAUC,iBAAiB,IAAMX,kBAAkBI,SAASQ,SAAQ,SAASC,MACzEA,KAAKC,UAAUC,OAAOf,kBAAkBI,SACxCS,KAAKC,UAAUE,IAAIhB,kBAAkBG,WAEzCG,MAAMW,gCAQU,WACVC,KAAOC,SAASC,cAAc,QAC/BF,KAAKG,QAAQC,iBACdH,SAASI,iBAAiB,QAASlB,iBACnCa,KAAKG,QAAQC,eAAiB"} \ No newline at end of file diff --git a/availability/amd/src/availability_more.js b/availability/amd/src/availability_more.js index 42a2b7f0494..35d58fc0e64 100644 --- a/availability/amd/src/availability_more.js +++ b/availability/amd/src/availability_more.js @@ -16,6 +16,8 @@ /** * Show more action for availablity information. * + * @deprecated since 4.3 MDL-78204. + * @todo MDL-78489 This will be deleted in Moodle 4.7. * @module core_availability/availability_more * @copyright 2021 Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/availability/classes/output/availability_info.php b/availability/classes/output/availability_info.php index 9e15f01fae4..b78b81d174e 100644 --- a/availability/classes/output/availability_info.php +++ b/availability/classes/output/availability_info.php @@ -40,12 +40,6 @@ class availability_info implements renderable, templatable { /** @var core_availability_multiple_messages availabilitymessages the course format class */ protected $availabilitymessages; - /** @var int counts number of conditions */ - protected $count = 0; - - /** @var int Maximum number of lines of availability info */ - protected const MAXVISIBLE = 4; - /** * Constructor. * @@ -53,7 +47,6 @@ class availability_info implements renderable, templatable { */ public function __construct(core_availability_multiple_messages $renderable) { $this->availabilitymessages = $renderable; - $this->count = 0; } /** @@ -68,10 +61,6 @@ class availability_info implements renderable, templatable { $template->id = uniqid(); - if ($this->count >= self::MAXVISIBLE) { - $template->showmorelink = true; - } - return $template; } @@ -82,12 +71,9 @@ class availability_info implements renderable, templatable { */ protected function get_item_base_template(): stdClass { return (object)[ - 'hidden' => $this->count > self::MAXVISIBLE, - 'abbreviate' => $this->count === self::MAXVISIBLE, 'id' => false, 'items' => [], 'hasitems' => false, - 'showmorelink' => false, ]; } @@ -101,15 +87,9 @@ class availability_info implements renderable, templatable { $template = $this->get_item_base_template(); - $template->header = get_string( - 'list_' . ($availability->root ? 'root_' : '') . - ($availability->andoperator ? 'and' : 'or') . - ($availability->treehidden ? '_hidden' : ''), - 'availability' - ); + $template->header = $this->get_item_header($availability); foreach ($availability->items as $item) { - $this->count++; if (is_string($item)) { $simple_item = $this->get_item_base_template(); $simple_item->header = $item; @@ -123,4 +103,20 @@ class availability_info implements renderable, templatable { return $template; } + + /** + * Get the item header. + * Depending on availability configuration this will return a string from a combined string identifier. + * For example: list_root_and_hidden, list_and, list_root_or_hidden, list_root_or, etc. + * + * @param core_availability_multiple_messages $availability the availability messages + * @return string the item header + */ + protected function get_item_header(core_availability_multiple_messages $availability): string { + $stridentifier = 'list_' . ($availability->root ? 'root_' : '') . + ($availability->andoperator ? 'and' : 'or') . + ($availability->treehidden ? '_hidden' : ''); + + return get_string($stridentifier, 'availability'); + } } diff --git a/availability/templates/availability_info.mustache b/availability/templates/availability_info.mustache index 32215a83a6b..f54746a3e6a 100644 --- a/availability/templates/availability_info.mustache +++ b/availability/templates/availability_info.mustache @@ -25,74 +25,36 @@ "header": "Not available unless:", "items" : [ { - "showmorelink": 0, - "abbreviate" : 0, - "hidden" : 0, "hasitems": 0, "header": "You belong to Green Group" }, { - "showmorelink": 0, - "abbreviate" : 0, - "hidden" : 0, "hasitems": 0, "header": "You belong to Red Group" }, { - "showmorelink": 0, - "abbreviate" : 1, - "hidden" : 0, "hasitems": 0, "header": "You belong to Orange Group" }, { - "showmorelink": 0, - "abbreviate" : 0, - "hidden" : 1, "hasitems": 0, "header": "You belong to Pink Group" }, { - "showmorelink": 0, - "abbreviate" : 0, - "hidden" : 1, "hasitems": 0, "header": "You belong to Red Group" } ], - "hasitems": 1, - "showmorelink": 1 + "hasitems": 1 } }} {{{header}}} {{#hasitems}}
    {{#items}} -
  • - {{#abbreviate}} - - {{> core_availability/availability_info }} - ... - {{/abbreviate}} - {{^abbreviate}} - {{> core_availability/availability_info }} - {{/abbreviate}} +
  • + {{> core_availability/availability_info }}
  • {{/items}} - {{#showmorelink}} -
  • - -
  • - {{/showmorelink}}
{{/hasitems}} - -{{#showmorelink}} -{{#js}} -require(['core_availability/availability_more'], function(availabilityMore) { - availabilityMore.init(); -}); -{{/js}} -{{/showmorelink}} diff --git a/availability/upgrade.txt b/availability/upgrade.txt index 2df60112297..87898eef25d 100644 --- a/availability/upgrade.txt +++ b/availability/upgrade.txt @@ -2,6 +2,12 @@ This files describes API changes in /availability/*. The information here is intended only for developers. +=== 4.3 === +* The `availability_info templatable` no longer exports 'showmore' information, and any component rendering avaialable_info + should handle showmore/showless behaviour by itself. + That means that 'showmorelink', 'hidden' and 'abbreviate' won't be exported for template in the root element neither its child items, + and `core_availability/availability_more` module has beed deprecated + === 4.2 === * The form for editing availability conditions now supports "private" conditions, that should not be shown diff --git a/lang/en/availability.php b/lang/en/availability.php index 44006cf9afb..19a28288dec 100644 --- a/lang/en/availability.php +++ b/lang/en/availability.php @@ -66,5 +66,7 @@ $string['privacy:metadata'] = 'The Access restriction subsystem does not store a $string['restrictaccess'] = 'Restrict access'; $string['restrictbygroup'] = 'Add group/grouping access restriction'; $string['setheading'] = '{$a->number} Set of {$a->count} restriction(s)'; -$string['showmore'] = 'Show more'; $string['unknowncondition'] = 'Unknown condition (deleted condition plugin)'; + +// Deprecated since Moodle 4.3. +$string['showmore'] = 'Show more'; diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 9ddd69cabdb..a632d60d90e 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -79,3 +79,4 @@ selectdevice,core_admin selecttheme,core_admin themenoselected,core_admin unsettheme,core_admin +showmore,core_availability \ No newline at end of file