Skip to content

Commit 263869a

Browse files
author
Aleš
authored
Add files via upload
1 parent 8ed8cba commit 263869a

1 file changed

Lines changed: 111 additions & 111 deletions

File tree

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,111 @@
1-
<?php
2-
3-
/**
4-
* This file is part of the NasExt extensions of Nette Framework
5-
*
6-
* Copyright (c) 2013 Dusan Hudak (http://dusan-hudak.com)
7-
*
8-
* For the full copyright and license information, please view
9-
* the file license.md that was distributed with this source code.
10-
*/
11-
12-
namespace NasExt\Forms\Controls;
13-
14-
use NasExt;
15-
use Nette;
16-
17-
18-
/**
19-
* @author Jáchym Toušek
20-
* @author Dusan Hudak
21-
* @author Ales Wita
22-
* @license MIT
23-
*/
24-
class DependentSelectBox extends Nette\Forms\Controls\SelectBox implements Nette\Application\UI\ISignalReceiver
25-
{
26-
use NasExt\Forms\DependentTrait;
27-
28-
/** @var string */
29-
const SIGNAL_NAME = 'load';
30-
31-
32-
/**
33-
* @param string $label
34-
* @param array<int, Nette\Forms\IControl> $parents
35-
*/
36-
public function __construct($label, array $parents)
37-
{
38-
$this->parents = $parents;
39-
parent::__construct($label);
40-
}
41-
42-
43-
/**
44-
* @param string $signal
45-
* @return void
46-
*/
47-
public function signalReceived($signal)
48-
{
49-
$presenter = $this->lookup('Nette\\Application\\UI\\Presenter');
50-
51-
if ($presenter->isAjax() && $signal === self::SIGNAL_NAME && !$this->isDisabled()) {
52-
$parentsNames = [];
53-
foreach ($this->parents as $parent) {
54-
$value = $presenter->getParameter($this->getNormalizeName($parent));
55-
$parent->setValue($value);
56-
57-
$parentsNames[$parent->getName()] = $parent->getValue();
58-
}
59-
60-
$data = $this->getDependentData([$parentsNames]);
61-
$presenter->payload->dependentselectbox = [
62-
'id' => $this->getHtmlId(),
63-
'items' => $data->getPreparedItems(!is_array($this->disabled) ?: $this->disabled),
64-
'value' => $data->getValue(),
65-
'prompt' => $data->getPrompt() === null ? $this->translate($this->getPrompt()) : $this->translate($data->getPrompt()),
66-
'disabledWhenEmpty' => $this->disabledWhenEmpty,
67-
];
68-
$presenter->sendPayload();
69-
}
70-
}
71-
72-
73-
/**
74-
* @return void
75-
*/
76-
private function tryLoadItems()
77-
{
78-
if ($this->parents === array_filter($this->parents, function ($p) {return !$p->hasErrors();})) {
79-
$parentsValues = [];
80-
foreach ($this->parents as $parent) {
81-
$parentsValues[$parent->getName()] = $parent->getValue();
82-
}
83-
84-
$data = $this->getDependentData([$parentsValues]);
85-
$items = $data->getItems();
86-
87-
88-
if ($this->getForm()->isSubmitted()) {
89-
$this->setValue($this->value);
90-
91-
} elseif ($this->tempValue !== null) {
92-
$this->setValue($this->tempValue);
93-
94-
} else {
95-
$this->setValue($data->getValue());
96-
}
97-
98-
99-
if (count($items) > 0) {
100-
$this->loadHttpData();
101-
102-
$this->setItems($items)
103-
->setPrompt($data->getPrompt() === null ? $this->getPrompt() : $data->getPrompt());
104-
} else {
105-
if ($this->disabledWhenEmpty === true && !$this->isDisabled()) {
106-
$this->setDisabled();
107-
}
108-
}
109-
}
110-
}
111-
}
1+
<?php
2+
3+
/**
4+
* This file is part of the NasExt extensions of Nette Framework
5+
*
6+
* Copyright (c) 2013 Dusan Hudak (http://dusan-hudak.com)
7+
*
8+
* For the full copyright and license information, please view
9+
* the file license.md that was distributed with this source code.
10+
*/
11+
12+
namespace NasExt\Forms\Controls;
13+
14+
use NasExt;
15+
use Nette;
16+
17+
18+
/**
19+
* @author Jáchym Toušek
20+
* @author Dusan Hudak
21+
* @author Ales Wita
22+
* @license MIT
23+
*/
24+
class DependentSelectBox extends Nette\Forms\Controls\SelectBox implements Nette\Application\UI\ISignalReceiver
25+
{
26+
use NasExt\Forms\DependentTrait;
27+
28+
/** @var string */
29+
const SIGNAL_NAME = 'load';
30+
31+
32+
/**
33+
* @param string $label
34+
* @param array<int, Nette\Forms\IControl> $parents
35+
*/
36+
public function __construct($label, array $parents)
37+
{
38+
$this->parents = $parents;
39+
parent::__construct($label);
40+
}
41+
42+
43+
/**
44+
* @param string $signal
45+
* @return void
46+
*/
47+
public function signalReceived($signal)
48+
{
49+
$presenter = $this->lookup('Nette\\Application\\UI\\Presenter');
50+
51+
if ($presenter->isAjax() && $signal === self::SIGNAL_NAME && !$this->isDisabled()) {
52+
$parentsNames = [];
53+
foreach ($this->parents as $parent) {
54+
$value = $presenter->getParameter($this->getNormalizeName($parent));
55+
$parent->setValue($value);
56+
57+
$parentsNames[$parent->getName()] = $parent->getValue();
58+
}
59+
60+
$data = $this->getDependentData([$parentsNames]);
61+
$presenter->payload->dependentselectbox = [
62+
'id' => $this->getHtmlId(),
63+
'items' => $data->getPreparedItems(!is_array($this->disabled) ?: $this->disabled),
64+
'value' => $data->getValue(),
65+
'prompt' => $data->getPrompt() === null ? $this->translate($this->getPrompt()) : $this->translate($data->getPrompt()),
66+
'disabledWhenEmpty' => $this->disabledWhenEmpty,
67+
];
68+
$presenter->sendPayload();
69+
}
70+
}
71+
72+
73+
/**
74+
* @return void
75+
*/
76+
private function tryLoadItems()
77+
{
78+
if ($this->parents === array_filter($this->parents, function ($p) {return !$p->hasErrors();})) {
79+
$parentsValues = [];
80+
foreach ($this->parents as $parent) {
81+
$parentsValues[$parent->getName()] = $parent->getValue();
82+
}
83+
84+
$data = $this->getDependentData([$parentsValues]);
85+
$items = $data->getItems();
86+
87+
88+
if ($this->getForm()->isSubmitted()) {
89+
$this->setValue($this->value);
90+
91+
} elseif ($this->tempValue !== null) {
92+
$this->setValue($this->tempValue);
93+
94+
} else {
95+
$this->setValue($data->getValue());
96+
}
97+
98+
99+
if (count($items) > 0) {
100+
$this->loadHttpData();
101+
102+
$this->setItems($items)
103+
->setPrompt($data->getPrompt() === null ? $this->getPrompt() : $data->getPrompt());
104+
} else {
105+
if ($this->disabledWhenEmpty === true && !$this->isDisabled()) {
106+
$this->setDisabled();
107+
}
108+
}
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)