Skip to content

Commit

Permalink
Merge branch 'hotfix/2.0.0-beta33'
Browse files Browse the repository at this point in the history
- Fixes an issue that the pid was not being examined on create actions.
- Fixes an issue that the id was not being passed to toggle operations.
- Persisting of legend collapse states is now working.
  • Loading branch information
discordier committed Feb 5, 2016
2 parents 45e5f98 + 5fc71db commit bc1e4c4
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 141 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
@@ -1,10 +1,11 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- "5.3"
- "5.4"
- "5.5"
- "5.6"
- "7.0"

env:
- CONTAO_VERSION=~3.2.0
Expand All @@ -15,7 +16,7 @@ env:
# Exclude impossible Contao Version combinations.
matrix:
exclude:
- php: 5.3
- php: "5.3"
env: CONTAO_VERSION=~3.5.0

sudo: false
Expand Down
275 changes: 145 additions & 130 deletions composer.lock

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion contao/html/js/generalDriver_src.js
Expand Up @@ -195,6 +195,29 @@ var BackendGeneral =
}).get({'state': (publish ? 1 : 0)});

return false;
}
},

/**
* Set the visibility of a legend.
*
* @param {object} el The DOM element
* @param {string} legend The ID of the legend element
* @param {string} table The table name
*
* @returns {boolean}
*/
setLegendState: function(el, legend, table) {
el.blur();
var fs = $('pal_' + legend);

if (fs.hasClass('collapsed')) {
fs.removeClass('collapsed');
new Request.Contao().post({'action':'setLegendState', 'legend':legend, 'table':table, 'state':1, 'REQUEST_TOKEN':Contao.request_token});
} else {
fs.addClass('collapsed');
new Request.Contao().post({'action':'setLegendState', 'legend':legend, 'table':table, 'state':0, 'REQUEST_TOKEN':Contao.request_token});
}

return false;
}
};
2 changes: 1 addition & 1 deletion contao/templates/dcbe_general_edit.html5
Expand Up @@ -74,7 +74,7 @@ $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalDriver.css';

<?php foreach($this->fieldsets as $arrFieldset): if($arrFieldset['legend']): ?>
<fieldset id="pal_<?php echo specialchars($arrFieldset['legend']); ?>" class="<?php echo $arrFieldset['class']; ?> block">
<legend onclick="AjaxRequest.toggleFieldset(this,'<?php echo specialchars($arrFieldset['legend']); ?>','<?php echo specialchars($this->table); ?>')"><?php echo $arrFieldset['label']; ?></legend>
<legend onclick="BackendGeneral.setLegendState(this,'<?php echo specialchars($arrFieldset['legend']); ?>','<?php echo specialchars($this->table); ?>')"><?php echo $arrFieldset['label']; ?></legend>
<?php echo $arrFieldset['palette']; ?>
</fieldset>
<?php else: ?>
Expand Down
Expand Up @@ -174,7 +174,6 @@ public function parsePalette(
$legend = null;

foreach ($fields as $field) {
// TODO what about :hide? this is currently not supported by LegendInterface.
if (preg_match('~^\{(.*?)(_legend)?(:hide)?\}$~', $field, $matches)) {
$name = $matches[1];
if ($palette->hasLegend($name)) {
Expand All @@ -183,6 +182,9 @@ public function parsePalette(
$legend = new Legend($matches[1]);
$palette->addLegend($legend);
}
if (array_key_exists(3, $matches)) {
$legend->setInitialVisibility(false);
}
} else {
// Fallback for incomplete palettes without legend,
// Create an empty legend.
Expand Down
Expand Up @@ -364,6 +364,7 @@ private function calculateParameters(CommandInterface $command, $serializedModel
if ($command instanceof ToggleCommandInterface) {
// Toggle has to trigger the javascript.
$parameters['act'] = $command->getName();
$parameters['id'] = $serializedModelId;

return $parameters;
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\BasicDefinitionInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\LegendInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\PaletteInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface;
use ContaoCommunityAlliance\DcGeneral\Data\MultiLanguageDataProviderInterface;
Expand Down Expand Up @@ -398,6 +399,7 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues)
$translator = $environment->getTranslator();
$propertyDefinitions = $definition->getPropertiesDefinition();
$isAutoSubmit = ($environment->getInputProvider()->getValue('SUBMIT_TYPE') === 'auto');
$legendStates = $this->getLegendStates();

$fieldSets = array();
$first = true;
Expand All @@ -413,6 +415,8 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues)
continue;
}

$legendVisible = $this->isLegendVisible($legend, $legendStates);

foreach ($properties as $property) {
$this->ensurePropertyExists($property->getName(), $propertyDefinitions);

Expand All @@ -426,13 +430,15 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues)
$this->errors,
$propertyValues->getPropertyValueErrors($property->getName())
);
// Force legend open on error.
$legendVisible = true;
}

$fields[] = $widgetManager->renderWidget($property->getName(), $isAutoSubmit, $propertyValues);
}

$fieldSet['label'] = $legendName;
$fieldSet['class'] = ($first) ? 'tl_tbox' : 'tl_box';
$fieldSet['class'] = $this->getLegendClass($first, $legendVisible);
$fieldSet['palette'] = implode('', $fields);
$fieldSet['legend'] = $legend->getName();
$fieldSets[] = $fieldSet;
Expand Down Expand Up @@ -740,4 +746,64 @@ protected function clearBackendStates()
$_SESSION['TL_ERROR'] = array();
$_SESSION['TL_CONFIRM'] = array();
}

/**
* Determine if the passed legend is visible or collapsed.
*
* @param LegendInterface $legend The legend.
*
* @param bool[] $legendStates The states from the session.
*
* @return bool
*/
private function isLegendVisible($legend, $legendStates)
{
if (array_key_exists($legend->getName(), $legendStates)) {
return $legendStates[$legend->getName()];
}

return $legend->isInitialVisible();
}

/**
* Obtain the legend states.
*
* @return array
*/
private function getLegendStates()
{
$environment = $this->getEnvironment();
$definition = $environment->getDataDefinition();
$legendStates = $environment->getSessionStorage()->get('LEGENDS');

if (array_key_exists($definition->getName(), $legendStates)) {
$legendStates = $legendStates[$definition->getName()];

return $legendStates;
} else {
$legendStates = array();

return $legendStates;
}
}

/**
* Determine the class to use for a legend.
*
* @param bool $first Flag if this is the first legend.
*
* @param bool $visible Flag determining if the legend is visible.
*
* @return string
*/
private function getLegendClass($first, $visible)
{
$classes = array((($first) ? 'tl_tbox' : 'tl_box'));

if (!$visible) {
$classes[] = ' collapsed';
}

return implode(' ', $classes);
}
}
13 changes: 13 additions & 0 deletions src/ContaoCommunityAlliance/DcGeneral/Controller/Ajax.php
Expand Up @@ -167,6 +167,15 @@ abstract protected function reloadPagetree();
*/
abstract protected function reloadFiletree();

/**
* Toggle a legend.
*
* This method exits the script.
*
* @return void
*/
abstract protected function setLegendState();

/**
* Handle the post actions from DcGeneral.
*
Expand Down Expand Up @@ -219,6 +228,10 @@ public function executePostActions(DataContainerInterface $objDc)
$this->reloadFiletree($objDc);
break;

case 'setLegendState':
$this->setLegendState();
break;

// Pass unknown actions to original Contao handler.
default:
$ajax = new \Ajax($action);
Expand Down
19 changes: 19 additions & 0 deletions src/ContaoCommunityAlliance/DcGeneral/Controller/Ajax3X.php
Expand Up @@ -254,4 +254,23 @@ protected function reloadFiletree()
{
$this->reloadTree();
}

/**
* {@inheritDoc}
*/
protected function setLegendState()
{
$environment = $this->getEnvironment();
$input = $environment->getInputProvider();
$table = $input->getValue('table');
$legend = $input->getValue('legend');
$state = (bool) $input->getValue('state');
$session = $environment->getSessionStorage();
$states = $session->get('LEGENDS');

$states[$table][$legend] = $state;
$session->set('LEGENDS', $states);

$this->exitScript();
}
}
Expand Up @@ -79,7 +79,7 @@ public function process(EnforceModelRelationshipEvent $event)
*/
protected function loadParentModel(InputProviderInterface $input, EnvironmentInterface $environment)
{
if (!$input->hasValue('pid')) {
if (!$input->hasParameter('pid')) {
return null;
}

Expand Down
Expand Up @@ -137,5 +137,5 @@ protected function isEditOnlyResponse()
*
* @return void
*/
abstract public function process();
abstract public function process();
}

1 comment on commit bc1e4c4

@zonky2
Copy link
Contributor

@zonky2 zonky2 commented on bc1e4c4 Feb 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in EditMask.php gibt es einen Bug: wenn keine Legende vorhanden, werden alle Eingabefelder versteckt (Fieldset hat "collapse")

siehe https://community.contao.org/de/showthread.php?61190-Datens%E4tze-lassen-sich-nicht-erstellen-bearbeiten

Workaround: Legende anlegen

Please sign in to comment.