Skip to content

Commit

Permalink
[FEATURE] Allow Administration Page Parts To Update Stored parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed Jun 5, 2020
1 parent 47bf3ff commit 1862f00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/system/Papaya/Administration/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Papaya\Administration\UI as AdministrationUI;
use Papaya\Application\BaseObject as ApplicationBaseObject;
use Papaya\Request;
use Papaya\Request\Parameters;
use Papaya\Template;
use Papaya\Template\XSLT as XSLTTemplate;
use Papaya\UI\Menu;
Expand Down Expand Up @@ -160,9 +161,8 @@ public function execute() {
}
$parts = $this->parts();
$restoreParameters = ('get' === $this->papaya()->request->getMethod()) && !empty($this->_parameterGroup);
$parametersName = [\get_class($this), 'parameters', $this->_parameterGroup];
if ($restoreParameters && $parts->parameters()->isEmpty()) {
$value = $this->papaya()->session->getValue($parametersName);
$value = $this->papaya()->session->getValue($this->getSessionParametersName());
$parts->parameters()->merge(\is_array($value) ? $value : []);
$this->papaya()->request->setParameters(
Request::SOURCE_QUERY,
Expand All @@ -180,12 +180,22 @@ public function execute() {
}
}
if ($restoreParameters) {
$this->papaya()->session->setValue($parametersName, $parts->parameters()->toArray());
$this->storeParameters($parts->parameters());
}
$this->parts()->toolbar()->toolbar($this->toolbar());
$this->getTemplate()->addMenu($this->parts()->toolbar()->getXML());
}

private function getSessionParametersName() {
return [\get_class($this), 'parameters', $this->_parameterGroup];
}

public function storeParameters(Parameters $parameters = NULL) {
$this->papaya()->session->setValue(
$this->getSessionParametersName(), $parameters->toArray()
);
}

/**
* Getter/Setter for the parts list
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Papaya\Administration\Protocol\Commands {

use Papaya\Administration\Page as AdministrationPage;
use Papaya\Administration\Protocol\ProtocolContent;
use Papaya\Administration\Protocol\ProtocolPage;
use Papaya\Content\Protocol\ProtocolEntries;
Expand Down Expand Up @@ -42,8 +43,14 @@ class DeleteProtocolEntries extends DialogCommand {
*/
private $_protocolEntries;

public function __construct(ProtocolEntry $protocolEntry) {
/**
* @var AdministrationPage
*/
private $_page;

public function __construct(ProtocolEntry $protocolEntry, AdministrationPage $page) {
$this->_protocolEntry = $protocolEntry;
$this->_page = $page;
}

public function createDialog() {
Expand Down Expand Up @@ -106,6 +113,8 @@ public function createDialog() {
$this->hideAfterSuccess(TRUE);
$this->callbacks()->onExecuteSuccessful = function() use ($severity, $groupId, $createdBefore) {
if ($this->deleteEntries($severity, $groupId, $createdBefore)) {
$this->parameters()->set('cmd', 'show');
$this->_page->storeParameters($this->parameters());
$this->papaya()->messages->displayInfo(
'Protocol entries deleted.'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function _createCommands($name = ProtocolPage::PARAMETER_NAME_COMMAND,
$commands = new CommandsController($name, $default);
$commands->owner($this);
$commands[self::COMMAND_SHOW] = new Commands\ShowProtocolEntry($this->protocolEntry());
$commands[self::COMMAND_CLEANUP] = new Commands\DeleteProtocolEntries($this->protocolEntry());
$commands[self::COMMAND_CLEANUP] = new Commands\DeleteProtocolEntries($this->protocolEntry(), $this->getPage());
return $commands;
}

Expand Down
4 changes: 2 additions & 2 deletions src/system/Papaya/Administration/Protocol/ProtocolPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class ProtocolPage extends AdministrationPage {

protected function createContent() {
$this->getTemplate()->parameters()->set(PageParameters::COLUMN_WIDTH_CONTENT, '60%');
return new ProtocolContent();
return new ProtocolContent($this);
}

protected function createNavigation() {
$this->getTemplate()->parameters()->set(PageParameters::COLUMN_WIDTH_NAVIGATION, '40%');
return new ProtocolNavigation();
return new ProtocolNavigation($this);
}
}
}

0 comments on commit 1862f00

Please sign in to comment.