Fix #12586 Fix Datatable init error

parent a3ae1a28
Pipeline #5647 passed with stage
in 8 minutes
......@@ -37,12 +37,13 @@ class Document extends \dependency\xml\Document
------------------------------------------------------------------------- */
protected $layout;
protected $classes;
protected $plugins;
public $plugins;
protected $headers;
protected $layoutData;
public $XPath;
public $translator;
public $dateTimeFormatter;
public $pluginsParameters = [];
/**
* -- document --
* <html>
......@@ -402,15 +403,9 @@ class Document extends \dependency\xml\Document
*/
public function addPlugins($node = null)
{
//var_dump("addPlugins($node->nodeType)");
$elements = $this->XPath->query("descendant-or-self::*[@class]", $node);
foreach ($elements as $element) {
foreach (explode(' ', $element->getAttribute('class')) as $htmlClass) {
if (isset($this->plugins[$htmlClass])) {
$pluginClass = $this->plugins[$htmlClass];
$element->plugin[$htmlClass] = new $pluginClass($element);
}
}
$element->addPlugins();
}
}
......@@ -420,19 +415,9 @@ class Document extends \dependency\xml\Document
*/
public function savePlugins($node = null)
{
$parameters = [];
$elements = $this->XPath->query("descendant-or-self::*[@class]", $node);
foreach ($elements as $element) {
foreach ($element->plugin as $name => $plugin) {
if (method_exists($plugin, 'saveHtml')) {
$plugin->saveHtml();
}
if (!isset($parameters[$name]) && method_exists($plugin, 'saveParameters')) {
$parameters[$name]=$plugin;
$plugin->saveParameters();
}
}
$element->savePlugins();
}
}
......
......@@ -24,7 +24,7 @@ class Element
/* -------------------------------------------------------------------------
- Properties
------------------------------------------------------------------------- */
public $plugin = array();
protected $plugin;
/* -------------------------------------------------------------------------
- Methods
------------------------------------------------------------------------- */
......@@ -99,4 +99,71 @@ class Element
{
return implode(" ", $array);
}
}
\ No newline at end of file
/**
* Returns the requested property
*
* @param string $name
*
* @return mixed
*/
public function __get($name)
{
if ($name == 'plugin' && empty($this->plugin)) {
$this->plugin = new PluginContainer($this);
}
return $this->{$name};
}
/**
* Add plugins
*/
public function addPlugins()
{
foreach (explode(' ', $this->getAttribute('class')) as $htmlClass) {
if (isset($this->ownerDocument->plugins[$htmlClass])) {
if (!isset($this->plugin)) {
$this->plugin = new PluginContainer($this);
}
$this->plugin->add($htmlClass);
}
}
}
/**
* Translate plugins
*/
public function translatePlugins()
{
if (!isset($this->plugin)) {
return;
}
foreach ($this->plugin as $name => $plugin) {
if (method_exists($plugin, 'translate')) {
$plugin->translate();
}
}
}
/**
* Save plugins
*/
public function savePlugins()
{
if (!isset($this->plugin)) {
return;
}
foreach ($this->plugin as $name => $plugin) {
if (method_exists($plugin, 'saveHtml')) {
$plugin->saveHtml();
}
if (method_exists($plugin, 'saveParameters')) {
$plugin->saveParameters();
}
}
}
}
......@@ -253,11 +253,7 @@ trait LocalisationTrait
{
$elements = $this->XPath->query("descendant-or-self::*[@class]", $node);
foreach ($elements as $element) {
foreach ($element->plugin as $name => $plugin) {
if (method_exists($plugin, 'translate')) {
$plugin->translate();
}
}
$element->translatePlugins();
}
}
......
<?php
/*
* Copyright (C) 2019 Maarch
*
* This file is part of dependency html.
*
* Dependency html is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dependency html is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with dependency html. If not, see <http://www.gnu.org/licenses/>.
*/
namespace dependency\html;
/**
* Element plugins container
*
* @package Dependency\Html
* @author Cyril VAZQUEZ <cyril.vazquez@maarch.org>
**/
class PluginContainer extends \ArrayObject
{
/**
* The owner element of the container
*
* @var DOMElement
*/
protected $element;
/**
* Constructs a new container
* @param DOMElement $element
*/
public function __construct($element)
{
$this->element = $element;
}
/**
* Returns the requested plugin or instancites a new one
*
* @param string $name
*
* @return object
*/
public function offsetGet($name)
{
if (!isset($this[$name]) && isset($this->element->ownerDocument->plugins[$name])) {
$this->add($name);
}
return parent::offsetGet($name);
}
/**
* Adds a plugin from a class
*
* @param string $name
*/
public function add($name)
{
$pluginClass = $this->element->ownerDocument->plugins[$name];
$plugin = new $pluginClass($this->element);
$this[$name] = $plugin;
}
}
......@@ -120,7 +120,7 @@
};
$('#app_maarchRM_main').ready(function () {
$("#managementMetadataForm").find("[name=retentionStartDate]").data("datepicker").setDate(new Date());
//$("#managementMetadataForm").find("[name=retentionStartDate]").data("datepicker").setDate(new Date());
});
$("#archiveForm").keypress(function(e) {
......
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