From b54326bf5d10056e7606cca1d6876bd4ff505ba7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 26 Mar 2014 07:48:22 +0000 Subject: [PATCH] Improve form submission, make use of serializeObject --- public/js/icinga/events.js | 17 +++++++++-------- public/js/icinga/utils.js | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 8aedd74f0..600d83b05 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -175,7 +175,7 @@ var url = $form.attr('action').replace(regex, '&'); // WHY?? var method = $form.attr('method'); var $target; - var data = $form.serializeArray(); + var data; if (typeof method === 'undefined') { method = 'POST'; @@ -186,20 +186,21 @@ event.stopPropagation(); event.preventDefault(); - // TODO: Check button - if (typeof autosubmit === 'undefined' || ! autosubmit) { - data.push({ name: 'btn_submit', value: 'yesss' }); - } - icinga.logger.debug('Submitting form: ' + method + ' ' + url, method); $target = self.getLinkTargetFor($form); if (method === 'GET') { - icinga.loader.loadUrl(icinga.utils.addUrlParams(url, data), $target, undefined, method); + url = icinga.utils.addUrlParams(url, $form.serializeObject()); } else { - icinga.loader.loadUrl(url, $target, data, method); + data = $form.serializeArray(); + + // TODO: Check button + if (typeof autosubmit === 'undefined' || ! autosubmit) { + data.push({ name: 'btn_submit', value: 'yesss' }); + } } + icinga.loader.loadUrl(url, $target, data, method); return false; }, diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 2e627c64d..6f20297e7 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -89,13 +89,13 @@ // Local URLs only addUrlParams: function (url, params) { - var parts = this.parseUrl(url); - var result = parts.path; - var newparams = parts.params; - var idx, p; - $.each(params, function (idx, p) { + var parts = this.parseUrl(url), + result = parts.path, + newparams = parts.params; + + $.each(params, function (key, value) { // We overwrite existing params - newparams[p.name] = p.value; + newparams[key] = value; }); if (Object.keys(newparams).length > 0) {