Merge branch 'bugfix/separate-sort-controls-9421'

fixes #9421
This commit is contained in:
Johannes Meyer 2015-07-27 11:50:19 +02:00
commit ce87b7f036
7 changed files with 70 additions and 37 deletions

View File

@ -250,7 +250,6 @@ class ConfigController extends Controller
$backendName = $this->params->getRequired('backend');
$form = new UserBackendConfigForm();
$form->setAction(Url::fromRequest());
$form->setRedirectUrl('config/userbackend');
$form->setTitle(sprintf($this->translate('Edit User Backend %s'), $backendName));
$form->setIniConfig(Config::app('authentication'));

View File

@ -78,7 +78,6 @@ class UsergroupbackendController extends Controller
$backendName = $this->params->getRequired('backend');
$form = new UserGroupBackendForm();
$form->setAction(Url::fromRequest());
$form->setRedirectUrl('usergroupbackend/list');
$form->setTitle(sprintf($this->translate('Edit User Group Backend %s'), $backendName));
$form->setIniConfig(Config::app('groups'));

View File

@ -37,13 +37,13 @@ class Controller extends ModuleActionController
return;
}
if (($sort = $request->getPost('sort'))) {
if (($sort = $request->getPost('sort')) || ($direction = $request->getPost('dir'))) {
$url = Url::fromRequest();
$url->setParam('sort', $sort);
if (($dir = $request->getPost('dir'))) {
$url->setParam('dir', $dir);
if ($sort) {
$url->setParam('sort', $sort);
$url->remove('dir');
} else {
$url->removeParam('dir');
$url->setParam('dir', $direction);
}
$this->redirectNow($url);

View File

@ -292,9 +292,11 @@ class Form extends Zend_Form
public function getRedirectUrl()
{
if ($this->redirectUrl === null) {
$url = $this->getRequest()->getUrl();
// Be sure to remove all form dependent params because we do not want to submit it again
$this->redirectUrl = $url->without(array_keys($this->getElements()));
$this->redirectUrl = $this->getRequest()->getUrl();
if ($this->getMethod() === 'get') {
// Be sure to remove all form dependent params because we do not want to submit it again
$this->redirectUrl = $this->redirectUrl->without(array_keys($this->getElements()));
}
}
return $this->redirectUrl;
@ -658,22 +660,26 @@ class Form extends Zend_Form
*/
public function create(array $formData = array())
{
if (false === $this->created) {
if (! $this->created) {
$this->createElements($formData);
$this->addFormIdentification()
->addCsrfCounterMeasure()
->addSubmitButton();
// Use Form::getAttrib() instead of Form::getAction() here because we want to explicitly check against
// null. Form::getAction() would return the empty string '' if the action is not set.
// For not setting the action attribute use Form::setAction(''). This is required for for the
// accessibility's enable/disable auto-refresh mechanic
if ($this->getAttrib('action') === null) {
// Use Form::getAttrib() instead of Form::getAction() here because we want to explicitly check against
// null. Form::getAction() would return the empty string '' if the action is not set.
// For not setting the action attribute use Form::setAction(''). This is required for for the
// accessibility's enable/disable auto-refresh mechanic
$action = $this->getRequest()->getUrl();
if ($this->getMethod() === 'get') {
$action = $action->without(array_keys($this->getElements()));
}
// TODO(el): Re-evalute this necessity. JavaScript could use the container's URL if there's no action set.
// We MUST set an action as JS gets confused otherwise, if
// this form is being displayed in an additional column
$this->setAction($this->getRequest()->getUrl()->without(array_keys($this->getElements())));
$this->setAction($action);
}
$this->created = true;
@ -920,7 +926,7 @@ class Form extends Zend_Form
*/
public function addFormIdentification()
{
if (false === $this->uidDisabled && $this->getElement($this->uidElementName) === null) {
if (! $this->uidDisabled && $this->getElement($this->uidElementName) === null) {
$this->addElement(
'hidden',
$this->uidElementName,
@ -942,7 +948,7 @@ class Form extends Zend_Form
*/
public function addCsrfCounterMeasure()
{
if (false === $this->tokenDisabled && $this->getElement($this->tokenElementName) === null) {
if (! $this->tokenDisabled && $this->getElement($this->tokenElementName) === null) {
$this->addElement(new CsrfCounterMeasure($this->tokenElementName));
}

View File

@ -127,43 +127,56 @@ class SortBox extends AbstractWidget
*/
public function render()
{
$form = new Form();
$form->setTokenDisabled();
$form->setName($this->name);
$form->setAttrib('class', 'sort-control inline');
$form->addElement(
$columnForm = new Form();
$columnForm->setTokenDisabled();
$columnForm->setName($this->name . '-column');
$columnForm->setAttrib('class', 'inline');
$columnForm->addElement(
'select',
'sort',
array(
'autosubmit' => true,
'label' => $this->view()->translate('Sort by'),
'multiOptions' => $this->sortFields
'multiOptions' => $this->sortFields,
'decorators' => array(
array('ViewHelper'),
array('Label')
)
)
);
$form->getElement('sort')->setDecorators(array(
array('ViewHelper'),
array('Label')
));
$form->addElement(
$orderForm = new Form();
$orderForm->setTokenDisabled();
$orderForm->setName($this->name . '-order');
$orderForm->setAttrib('class', 'inline');
$orderForm->addElement(
'select',
'dir',
array(
'autosubmit' => true,
'label' => $this->view()->translate('Direction', 'sort direction'),
'multiOptions' => array(
'asc' => 'Asc',
'desc' => 'Desc',
'asc' => $this->view()->translate('Ascending', 'sort direction'),
'desc' => $this->view()->translate('Descending', 'sort direction')
),
'decorators' => array(
array('ViewHelper')
array('ViewHelper'),
array('Label', array('class' => 'no-js'))
)
)
);
if ($this->request) {
$form->populate($this->request->getParams());
$url = $this->request->getUrl();
if ($url->hasParam('sort')) {
$columnForm->populate(array('sort' => $url->getParam('sort')));
}
if ($url->hasParam('dir')) {
$orderForm->populate(array('dir' => $url->getParam('dir')));
}
}
return $form;
return '<div class="sort-control">' . $columnForm . $orderForm . '</div>';
}
}

View File

@ -1,6 +1,6 @@
/*! Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
form.sort-control {
div.sort-control {
.dontprint;
float: right;
@ -15,7 +15,13 @@ form.sort-control {
}
select[name=dir] {
width: 5em;
width: 8em;
margin-left: 0;
}
}
html.no-js div.sort-control form {
display: table;
margin-left: auto;
margin-top: 0.25em;
}

View File

@ -405,3 +405,13 @@ html {
padding-top: 0em;
font-size: 0.9em;
}
// Hide non-javascript elements if javascript is enabled
html.js *.no-js {
.sr-only;
}
// Hide javascript elements if javascript is disabled
html.no-js *.js {
.sr-only;
}