mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 00:34:03 +02:00
Fix search form autosubmission and response handling
This commit is contained in:
parent
e36fb2558e
commit
36f31f9f02
@ -97,7 +97,7 @@
|
|||||||
// We support an 'autosubmit' class on dropdown form elements
|
// We support an 'autosubmit' class on dropdown form elements
|
||||||
$(document).on('change', 'form select.autosubmit', { self: this }, this.autoSubmitForm);
|
$(document).on('change', 'form select.autosubmit', { self: this }, this.autoSubmitForm);
|
||||||
|
|
||||||
$(document).on('keyup', '#menu input.search', {self: this}, this.submitForm);
|
$(document).on('keyup', '#menu input.search', {self: this}, this.autoSubmitForm);
|
||||||
|
|
||||||
$(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
|
$(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
|
||||||
$(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
|
$(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
|
||||||
@ -171,13 +171,18 @@
|
|||||||
|
|
||||||
// .closest is not required unless subelements to trigger this
|
// .closest is not required unless subelements to trigger this
|
||||||
var $form = $(event.currentTarget).closest('form');
|
var $form = $(event.currentTarget).closest('form');
|
||||||
|
|
||||||
var regex = new RegExp('&', 'g');
|
var regex = new RegExp('&', 'g');
|
||||||
var url = $form.attr('action').replace(regex, '&'); // WHY??
|
var url = $form.attr('action').replace(regex, '&'); // WHY??
|
||||||
var method = $form.attr('method');
|
var method = $form.attr('method');
|
||||||
var $target;
|
var $target;
|
||||||
var data = $form.serializeArray();
|
var data = $form.serializeArray();
|
||||||
|
|
||||||
|
if (typeof method === 'undefined') {
|
||||||
|
method = 'POST';
|
||||||
|
} else {
|
||||||
|
method = method.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@ -186,10 +191,15 @@
|
|||||||
data.push({ name: 'btn_submit', value: 'yesss' });
|
data.push({ name: 'btn_submit', value: 'yesss' });
|
||||||
}
|
}
|
||||||
|
|
||||||
icinga.logger.debug('Submitting form: ' + method + ' ' + url);
|
icinga.logger.debug('Submitting form: ' + method + ' ' + url, method);
|
||||||
|
|
||||||
$target = self.getLinkTargetFor($form);
|
$target = self.getLinkTargetFor($form);
|
||||||
icinga.loader.loadUrl(url, $target, data, method);
|
|
||||||
|
if (method === 'GET') {
|
||||||
|
icinga.loader.loadUrl(icinga.utils.addUrlParams(url, data), $target, undefined, method);
|
||||||
|
} else {
|
||||||
|
icinga.loader.loadUrl(url, $target, data, method);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
@ -235,6 +235,7 @@
|
|||||||
|
|
||||||
var $resp = $(req.responseText);
|
var $resp = $(req.responseText);
|
||||||
var active = false;
|
var active = false;
|
||||||
|
var rendered = false;
|
||||||
|
|
||||||
if (! req.autorefresh) {
|
if (! req.autorefresh) {
|
||||||
// TODO: Hook for response/url?
|
// TODO: Hook for response/url?
|
||||||
@ -329,29 +330,29 @@
|
|||||||
req.$target.removeClass('impact');
|
req.$target.removeClass('impact');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle search requests, still hardcoded
|
// Handle search requests, still hardcoded.
|
||||||
if (req.url === '/search' &&
|
if (req.url.match(/^\/search/) &&
|
||||||
req.$target.data('icingaUrl') === '/search')
|
req.$target.data('icingaUrl').match(/^\/search/))
|
||||||
{
|
{
|
||||||
// TODO: We need dashboard pane and container identifiers (not ids)
|
// TODO: We need dashboard pane and container identifiers (not ids)
|
||||||
var targets = [];
|
var targets = [];
|
||||||
$('.dashboard .container').each(function (idx, el) {
|
$('.dashboard .container', req.$target).each(function (idx, el) {
|
||||||
targets.push($(el));
|
targets.push($(el));
|
||||||
});
|
});
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
$('.dashboard .container', $resp).each(function (idx, el) {
|
// Searching for '.dashboard .container' in $resp doesn't dork?!
|
||||||
|
$('.container', $resp).each(function (idx, el) {
|
||||||
var $el = $(el);
|
var $el = $(el);
|
||||||
var url = $el.data('icingaUrl');
|
var url = $el.data('icingaUrl');
|
||||||
targets[i].data('icingaUrl', url);
|
targets[i].data('icingaUrl', url);
|
||||||
|
|
||||||
var title = $('h1', $el).first();
|
var title = $('h1', $el).first();
|
||||||
$('h1', targets[i]).first().replaceWith(title);
|
$('h1', targets[i]).first().replaceWith(title);
|
||||||
|
|
||||||
self.loadUrl(url, targets[i]);
|
self.loadUrl(url, targets[i]);
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
return;
|
rendered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.$target.data('icingaUrl', req.url);
|
req.$target.data('icingaUrl', req.url);
|
||||||
@ -387,6 +388,10 @@
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (rendered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.renderContentToContainer($resp, req.$target);
|
this.renderContentToContainer($resp, req.$target);
|
||||||
if (url.match(/#/)) {
|
if (url.match(/#/)) {
|
||||||
this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]);
|
this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]);
|
||||||
@ -427,10 +432,9 @@
|
|||||||
this.icinga.ui.fixControls();
|
this.icinga.ui.fixControls();
|
||||||
}
|
}
|
||||||
} else if (req.status > 0) {
|
} else if (req.status > 0) {
|
||||||
this.icinga.logger.debug(req.responseText.slice(0, 100));
|
this.icinga.logger.error(req.status, errorThrown, req.responseText.slice(0, 100));
|
||||||
this.renderContentToContainer(
|
this.renderContentToContainer(
|
||||||
'<h1>' + req.status + ' ' + errorThrown + '</h1> ' +
|
req.responseText,
|
||||||
req.responseText,
|
|
||||||
req.$target
|
req.$target
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user