From 200982e4f5ccb2a98312cdce22b94f7ccace631e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 Mar 2015 03:59:43 +0100 Subject: [PATCH 1/4] Set form action automatically only if Form::setAction() has not been called refs #8605 --- library/Icinga/Web/Form.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 3ff995028..faa212458 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -535,7 +535,13 @@ class Form extends Zend_Form ->addCsrfCounterMeasure() ->addSubmitButton(); - if ($this->getAction() === '') { + 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 + + // 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(Url::fromRequest()->without(array_keys($this->getElements()))); From f60a0b86eca8f5a4f1cba1b05fbdf01b0f6e00b3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 Mar 2015 04:01:08 +0100 Subject: [PATCH 2/4] POST disable/enable auto-refresh always against the current location refs #8605 --- application/forms/AutoRefreshForm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/forms/AutoRefreshForm.php b/application/forms/AutoRefreshForm.php index e1e436d34..1d2eda2be 100644 --- a/application/forms/AutoRefreshForm.php +++ b/application/forms/AutoRefreshForm.php @@ -21,6 +21,8 @@ class AutoRefreshForm extends Form public function init() { $this->setName('form_auto_refresh'); + // Post against the current location + $this->setAction(''); } /** From 1bd2e7cb84da5ff9d17e6cd7b176a55c85ed4a11 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 Mar 2015 04:02:42 +0100 Subject: [PATCH 3/4] Submit forms to the container's target URL if the form's action is not set refs #8605 --- public/js/icinga/events.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 54b2aaa00..f83c172f6 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -239,10 +239,8 @@ event.stopPropagation(); event.preventDefault(); - icinga.logger.debug('Submitting form: ' + method + ' ' + url, method); - if ($button.length) { - // activate spinner indicator + // Activate spinner if ($button.hasClass('spinner')) { $button.addClass('active'); } @@ -252,6 +250,13 @@ $target = self.getLinkTargetFor($form); } + if (! url) { + // Use the URL of the target container if the form's action is not set + url = $target.closest('.container').data('icinga-url'); + } + + icinga.logger.debug('Submitting form: ' + method + ' ' + url, method); + if (method === 'GET') { var dataObj = $form.serializeObject(); @@ -274,6 +279,7 @@ } } } + icinga.loader.loadUrl(url, $target, data, method); return false; From 2e1ae185fbb39b4d33c916a15686efb911b1ce61 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 Mar 2015 04:04:58 +0100 Subject: [PATCH 4/4] Retain detail URL if the layout is rerendered after a redirect refs #8605 --- public/js/icinga/loader.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 07ab3cbc1..1c674b947 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -292,6 +292,12 @@ r.url = redirect; if (parts.length) { r.loadNext = parts; + } else if (!! document.location.hash) { + // Retain detail URL if the layout is rerendered + parts = document.location.hash.split('#!').splice(1); + if (parts.length) { + r.loadNext = parts; + } } } else {