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
|
||||
$(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('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
|
||||
|
@ -171,13 +171,18 @@
|
|||
|
||||
// .closest is not required unless subelements to trigger this
|
||||
var $form = $(event.currentTarget).closest('form');
|
||||
|
||||
var regex = new RegExp('&', 'g');
|
||||
var url = $form.attr('action').replace(regex, '&'); // WHY??
|
||||
var method = $form.attr('method');
|
||||
var $target;
|
||||
var data = $form.serializeArray();
|
||||
|
||||
if (typeof method === 'undefined') {
|
||||
method = 'POST';
|
||||
} else {
|
||||
method = method.toUpperCase();
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
|
@ -186,10 +191,15 @@
|
|||
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);
|
||||
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;
|
||||
},
|
||||
|
|
|
@ -235,6 +235,7 @@
|
|||
|
||||
var $resp = $(req.responseText);
|
||||
var active = false;
|
||||
var rendered = false;
|
||||
|
||||
if (! req.autorefresh) {
|
||||
// TODO: Hook for response/url?
|
||||
|
@ -329,29 +330,29 @@
|
|||
req.$target.removeClass('impact');
|
||||
}
|
||||
|
||||
// Handle search requests, still hardcoded
|
||||
if (req.url === '/search' &&
|
||||
req.$target.data('icingaUrl') === '/search')
|
||||
// Handle search requests, still hardcoded.
|
||||
if (req.url.match(/^\/search/) &&
|
||||
req.$target.data('icingaUrl').match(/^\/search/))
|
||||
{
|
||||
// TODO: We need dashboard pane and container identifiers (not ids)
|
||||
var targets = [];
|
||||
$('.dashboard .container').each(function (idx, el) {
|
||||
$('.dashboard .container', req.$target).each(function (idx, el) {
|
||||
targets.push($(el));
|
||||
});
|
||||
|
||||
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 url = $el.data('icingaUrl');
|
||||
targets[i].data('icingaUrl', url);
|
||||
|
||||
var title = $('h1', $el).first();
|
||||
$('h1', targets[i]).first().replaceWith(title);
|
||||
|
||||
self.loadUrl(url, targets[i]);
|
||||
i++;
|
||||
});
|
||||
return;
|
||||
rendered = true;
|
||||
}
|
||||
|
||||
req.$target.data('icingaUrl', req.url);
|
||||
|
@ -387,6 +388,10 @@
|
|||
});
|
||||
*/
|
||||
|
||||
if (rendered) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.renderContentToContainer($resp, req.$target);
|
||||
if (url.match(/#/)) {
|
||||
this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]);
|
||||
|
@ -427,10 +432,9 @@
|
|||
this.icinga.ui.fixControls();
|
||||
}
|
||||
} 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(
|
||||
'<h1>' + req.status + ' ' + errorThrown + '</h1> ' +
|
||||
req.responseText,
|
||||
req.responseText,
|
||||
req.$target
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue