summaryrefslogtreecommitdiff
path: root/app/assets
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/lib/utils/forms.js12
-rw-r--r--app/assets/javascripts/pages/projects/project.js23
-rw-r--r--app/assets/javascripts/pages/search/show/search.js3
3 files changed, 26 insertions, 12 deletions
diff --git a/app/assets/javascripts/lib/utils/forms.js b/app/assets/javascripts/lib/utils/forms.js
new file mode 100644
index 00000000000..106209a2f3a
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/forms.js
@@ -0,0 +1,12 @@
+export const serializeFormEntries = entries =>
+ entries.reduce((acc, { name, value }) => Object.assign(acc, { [name]: value }), {});
+
+export const serializeForm = form => {
+ const fdata = new FormData(form);
+ const entries = Array.from(fdata.keys()).map(key => {
+ const val = fdata.getAll(key);
+ return { name: key, value: val.length === 1 ? val[0] : val };
+ });
+
+ return serializeFormEntries(entries);
+};
diff --git a/app/assets/javascripts/pages/projects/project.js b/app/assets/javascripts/pages/projects/project.js
index f0d529758d5..332b6811af6 100644
--- a/app/assets/javascripts/pages/projects/project.js
+++ b/app/assets/javascripts/pages/projects/project.js
@@ -1,9 +1,10 @@
-/* eslint-disable func-names, no-var, no-return-assign, one-var, object-shorthand, vars-on-top */
+/* eslint-disable func-names, no-var, no-return-assign, object-shorthand, vars-on-top */
import $ from 'jquery';
import Cookies from 'js-cookie';
import { __ } from '~/locale';
-import { visitUrl } from '~/lib/utils/url_utility';
+import { visitUrl, mergeUrlParams } from '~/lib/utils/url_utility';
+import { serializeForm } from '~/lib/utils/forms';
import axios from '~/lib/utils/axios_utils';
import flash from '~/flash';
import projectSelect from '../../project_select';
@@ -107,9 +108,10 @@ export default class Project {
refLink.href = '#';
return $('.js-project-refs-dropdown').each(function() {
- var $dropdown, selected;
- $dropdown = $(this);
- selected = $dropdown.data('selected');
+ var $dropdown = $(this);
+ var selected = $dropdown.data('selected');
+ var fieldName = $dropdown.data('fieldName');
+ var shouldVisit = Boolean($dropdown.data('visit'));
return $dropdown.glDropdown({
data(term, callback) {
axios
@@ -127,7 +129,7 @@ export default class Project {
filterRemote: true,
filterByText: true,
inputFieldName: $dropdown.data('inputFieldName'),
- fieldName: $dropdown.data('fieldName'),
+ fieldName,
renderRow: function(ref) {
var li = refListItem.cloneNode(false);
@@ -158,15 +160,12 @@ export default class Project {
clicked: function(options) {
const { e } = options;
e.preventDefault();
- if ($('input[name="ref"]').length) {
+ if ($(`input[name="${fieldName}"]`).length) {
var $form = $dropdown.closest('form');
-
- var $visit = $dropdown.data('visit');
- var shouldVisit = $visit ? true : $visit;
var action = $form.attr('action');
- var divider = action.indexOf('?') === -1 ? '?' : '&';
+
if (shouldVisit) {
- visitUrl(`${action}${divider}${$form.serialize()}`);
+ visitUrl(mergeUrlParams(serializeForm($form[0]), action));
}
}
},
diff --git a/app/assets/javascripts/pages/search/show/search.js b/app/assets/javascripts/pages/search/show/search.js
index 7743e05e748..81b6225cb18 100644
--- a/app/assets/javascripts/pages/search/show/search.js
+++ b/app/assets/javascripts/pages/search/show/search.js
@@ -2,6 +2,7 @@ import $ from 'jquery';
import Flash from '~/flash';
import Api from '~/api';
import { __ } from '~/locale';
+import Project from '~/pages/projects/project';
export default class Search {
constructor() {
@@ -69,6 +70,8 @@ export default class Search {
},
clicked: () => Search.submitSearch(),
});
+
+ Project.initRefSwitcher();
}
eventListeners() {