Commit 7c7edd39 authored by Karl Hasselbring's avatar Karl Hasselbring
Browse files

Fixed: Eigene Foki funktionieren jetzt wieder in der Suche

parent 038ca5f0
...@@ -18,10 +18,11 @@ class MetaGerSearch extends Controller ...@@ -18,10 +18,11 @@ class MetaGerSearch extends Controller
return redirect()->to('https://maps.metager.de/map/' . $searchinput . '/1240908.5493525574,6638783.2192695495,6'); return redirect()->to('https://maps.metager.de/map/' . $searchinput . '/1240908.5493525574,6638783.2192695495,6');
} }
if ($focus !== "angepasst" && $this->startsWith($focus, "focus_")) { /*if ($focus !== "angepasst" && $this->startsWith($focus, "focus_")) {
$metager->parseFormData($request); $metager->parseFormData($request);
return $metager->createView(); return $metager->createView();
} }*/
#die($request->header('User-Agent')); #die($request->header('User-Agent'));
$time = microtime(); $time = microtime();
# Mit gelieferte Formulardaten parsen und abspeichern: # Mit gelieferte Formulardaten parsen und abspeichern:
......
...@@ -481,6 +481,8 @@ class MetaGer ...@@ -481,6 +481,8 @@ class MetaGer
$overtureEnabled = false; $overtureEnabled = false;
$sumaCount = 0; $sumaCount = 0;
$isCustomSearch = strpos($this->fokus, 'focus_') == 0;
/* Erstellt die Liste der eingestellten Sumas /* Erstellt die Liste der eingestellten Sumas
* Der einzige Unterschied bei angepasstem Suchfokus ist, * Der einzige Unterschied bei angepasstem Suchfokus ist,
* dass nicht nach den Typen einer Suma, * dass nicht nach den Typen einer Suma,
...@@ -492,7 +494,7 @@ class MetaGer ...@@ -492,7 +494,7 @@ class MetaGer
* Zu Liste hinzufügen * Zu Liste hinzufügen
*/ */
foreach ($sumas as $suma) { foreach ($sumas as $suma) {
if (($this->sumaIsSelected($suma, $request) if (($this->sumaIsSelected($suma, $request, $isCustomSearch)
|| (!$this->isBildersuche() || (!$this->isBildersuche()
&& $this->sumaIsAdsuche($suma, $overtureEnabled))) && $this->sumaIsAdsuche($suma, $overtureEnabled)))
&& (!$this->sumaIsDisabled($suma))) { && (!$this->sumaIsDisabled($suma))) {
...@@ -593,10 +595,10 @@ class MetaGer ...@@ -593,10 +595,10 @@ class MetaGer
# Spezielle Suchen und Sumas # Spezielle Suchen und Sumas
public function sumaIsSelected($suma, $request) public function sumaIsSelected($suma, $request, $custom)
{ {
if ($this->fokus === "angepasst") { if ($custom) {
if ($request->has($suma["name"])) { if ($request->has("engine_" . $suma["name"])) {
return true; return true;
} }
} else { } else {
......
...@@ -2,14 +2,14 @@ $(function () { ...@@ -2,14 +2,14 @@ $(function () {
loadLocalStorage(); loadLocalStorage();
setSearchbarActionListeners(); setSearchbarActionListeners();
loadInitialCustomFocuses(); loadInitialCustomFocuses();
checkFocusEditable(); loadInitialSelectedFocus();
loadSelectedFocus(); focusChanged();
}); });
/** /**
* Loads the user theme and stored settings from local storage * Loads the user theme and stored settings from local storage
*/ */
function loadLocalStorage () { function loadLocalStorage() {
if (localStorage) { if (localStorage) {
setSettings(); setSettings();
} }
...@@ -18,13 +18,13 @@ function loadLocalStorage () { ...@@ -18,13 +18,13 @@ function loadLocalStorage () {
/** /**
* Sets all action listeners for this page * Sets all action listeners for this page
*/ */
function setSearchbarActionListeners () { function setSearchbarActionListeners() {
$('.focusCheckbox').click(toggleDeleteButton); $('.focusCheckbox').click(toggleDeleteButton);
$('#addFocusBtn').click(() => showFocusCreateDialog('')); $('#addFocusBtn').click(() => showFocusCreateDialog(''));
$('#editFocusBtn').click(editCurrentFocus); $('#editFocusBtn').click(editCurrentFocus);
$('.save-focus-btn').click(saveFocus); $('.save-focus-btn').click(saveFocus);
$('.delete-focus-btn').click(deleteFocus); $('.delete-focus-btn').click(deleteFocus);
$('#focus-select').change(checkFocusEditable); $('#focus-select').change(focusChanged);
// Save Focus on clicking enter while in the focus name input // Save Focus on clicking enter while in the focus name input
$('#focus-name').keyup(function (event) { $('#focus-name').keyup(function (event) {
if (event.keyCode == 13) { if (event.keyCode == 13) {
...@@ -36,7 +36,7 @@ function setSearchbarActionListeners () { ...@@ -36,7 +36,7 @@ function setSearchbarActionListeners () {
}); });
} }
function setSettings () { function setSettings() {
var acceptedParams = ['autocomplete', 'key', 'lang', 'newtab', 'sprueche']; var acceptedParams = ['autocomplete', 'key', 'lang', 'newtab', 'sprueche'];
for (var key in localStorage) { for (var key in localStorage) {
var value = localStorage.getItem(key); var value = localStorage.getItem(key);
...@@ -66,7 +66,7 @@ function setSettings () { ...@@ -66,7 +66,7 @@ function setSettings () {
/** /**
* Loads all the custom focuses stored in local storage * Loads all the custom focuses stored in local storage
*/ */
function loadInitialCustomFocuses () { function loadInitialCustomFocuses() {
for (var key in localStorage) { for (var key in localStorage) {
if (key.startsWith('focus_')) { if (key.startsWith('focus_')) {
var focus = loadFocusById(key); var focus = loadFocusById(key);
...@@ -75,11 +75,15 @@ function loadInitialCustomFocuses () { ...@@ -75,11 +75,15 @@ function loadInitialCustomFocuses () {
} }
} }
function loadInitialSelectedFocus() {
setFocus(getFocusInUrl());
}
/** /**
* Shows the focus create dialog * Shows the focus create dialog
* If an id is given it will try to load a focus for the given id * If an id is given it will try to load a focus for the given id
*/ */
function showFocusCreateDialog (id) { function showFocusCreateDialog(id) {
if (id === undefined) { if (id === undefined) {
id = ''; id = '';
} }
...@@ -109,28 +113,26 @@ function showFocusCreateDialog (id) { ...@@ -109,28 +113,26 @@ function showFocusCreateDialog (id) {
/** /**
* Shows the focus create dialog for a given id * Shows the focus create dialog for a given id
*/ */
function showFocusEditDialog (id) { function showFocusEditDialog(id) {
showFocusCreateDialog(id); showFocusCreateDialog(id);
} }
function getCurrentFocus () { function getCurrentFocus() {
return document.getElementById('focus-select').value; return document.getElementById('focus-select').value;
} }
/** /**
* Shows an edit dialog for the current selected focus * Shows an edit dialog for the current selected focus
*/ */
function editCurrentFocus () { function editCurrentFocus() {
console.log('hi');
var currentFocus = getCurrentFocus(); var currentFocus = getCurrentFocus();
console.log(currentFocus);
showFocusEditDialog(currentFocus); showFocusEditDialog(currentFocus);
} }
/** /**
* Shows/Hides the delete button if (no) checkboxes are selected * Shows/Hides the delete button if (no) checkboxes are selected
*/ */
function toggleDeleteButton () { function toggleDeleteButton() {
if (atLeastOneChecked()) { if (atLeastOneChecked()) {
$('.delete-focus-btn').show(); $('.delete-focus-btn').show();
} else { } else {
...@@ -142,7 +144,7 @@ function toggleDeleteButton () { ...@@ -142,7 +144,7 @@ function toggleDeleteButton () {
* Save the current Focus * Save the current Focus
* Listens for save button * Listens for save button
*/ */
function saveFocus () { function saveFocus() {
/* Vorprüfungen */ /* Vorprüfungen */
// Falls keine Suchmaschine ausgewählt wurde // Falls keine Suchmaschine ausgewählt wurde
if (!atLeastOneChecked()) { if (!atLeastOneChecked()) {
...@@ -214,7 +216,7 @@ function saveFocus () { ...@@ -214,7 +216,7 @@ function saveFocus () {
* Delete current Focus * Delete current Focus
* Listens for delete button * Listens for delete button
*/ */
function deleteFocusById (id) { function deleteFocusById(id) {
localStorage.removeItem(id); localStorage.removeItem(id);
removeFocusById(id); removeFocusById(id);
$('#focus-select').change(); $('#focus-select').change();
...@@ -224,7 +226,7 @@ function deleteFocusById (id) { ...@@ -224,7 +226,7 @@ function deleteFocusById (id) {
* Delete current Focus * Delete current Focus
* Listens for delete button * Listens for delete button
*/ */
function deleteFocus () { function deleteFocus() {
var oldId = document.getElementById('original-id').value; var oldId = document.getElementById('original-id').value;
deleteFocusById(oldId); deleteFocusById(oldId);
$('#create-focus-modal').modal('hide'); $('#create-focus-modal').modal('hide');
...@@ -234,7 +236,7 @@ function deleteFocus () { ...@@ -234,7 +236,7 @@ function deleteFocus () {
/** /**
* Is the name valid (in terms of characters)? * Is the name valid (in terms of characters)?
*/ */
function isValidName (name) { function isValidName(name) {
// no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed // no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed
// at least 1 character // at least 1 character
return /^[a-zA-Z0-9äöüß\-_ ]+$/.test(name); return /^[a-zA-Z0-9äöüß\-_ ]+$/.test(name);
...@@ -243,21 +245,21 @@ function isValidName (name) { ...@@ -243,21 +245,21 @@ function isValidName (name) {
/** /**
* Is at least one focus selected? * Is at least one focus selected?
*/ */
function atLeastOneChecked () { function atLeastOneChecked() {
return $('.focusCheckbox:checked').length > 0; return $('.focusCheckbox:checked').length > 0;
} }
/** /**
* Is there already a focus with this name? * Is there already a focus with this name?
*/ */
function alreadyInUse (name) { function alreadyInUse(name) {
return localStorage.hasOwnProperty(getIdFromName(name)); return localStorage.hasOwnProperty(getIdFromName(name));
} }
/** /**
* Adds an option to the focus selector * Adds an option to the focus selector
*/ */
function addFocus (name) { function addFocus(name) {
var id = getIdFromName(name); var id = getIdFromName(name);
$('#focus-select').append('<option value="' + id + '" style="font-family: FontAwesome, sans-serif;">&#xf2c0; ' + name + '</option>'); $('#focus-select').append('<option value="' + id + '" style="font-family: FontAwesome, sans-serif;">&#xf2c0; ' + name + '</option>');
} }
...@@ -265,14 +267,14 @@ function addFocus (name) { ...@@ -265,14 +267,14 @@ function addFocus (name) {
/** /**
* Remove the focuses html-elements * Remove the focuses html-elements
*/ */
function removeFocus (name) { function removeFocus(name) {
removeFocusById(getIdFromName(name)); removeFocusById(getIdFromName(name));
} }
/** /**
* Remove the focuses html-elements * Remove the focuses html-elements
*/ */
function removeFocusById (id) { function removeFocusById(id) {
if (id == '') { if (id == '') {
return; return;
} }
...@@ -283,7 +285,7 @@ function removeFocusById (id) { ...@@ -283,7 +285,7 @@ function removeFocusById (id) {
* Turns a name into an id * Turns a name into an id
* Converts special characters and spaces * Converts special characters and spaces
*/ */
function getIdFromName (name) { function getIdFromName(name) {
name = name.toLowerCase(); name = name.toLowerCase();
name = name.split(' ').join('_'); name = name.split(' ').join('_');
name = name.split('ä').join('ae'); name = name.split('ä').join('ae');
...@@ -295,21 +297,21 @@ function getIdFromName (name) { ...@@ -295,21 +297,21 @@ function getIdFromName (name) {
/** /**
* Loads the focus object for the given id from local storage * Loads the focus object for the given id from local storage
*/ */
function loadFocusById (id) { function loadFocusById(id) {
return JSON.parse(localStorage.getItem(id)); return JSON.parse(localStorage.getItem(id));
} }
/** /**
* Unchecks all focuses from the focus creator dialog * Unchecks all focuses from the focus creator dialog
*/ */
function uncheckAll () { function uncheckAll() {
$('.focusCheckbox').prop('checked', false); $('.focusCheckbox').prop('checked', false);
} }
/** /**
* Sets the selected focus to default * Sets the selected focus to default
*/ */
function setFocusToDefault () { function setFocusToDefault() {
setFocus(DEFAULT_FOCUS); setFocus(DEFAULT_FOCUS);
} }
...@@ -317,33 +319,60 @@ function setFocusToDefault () { ...@@ -317,33 +319,60 @@ function setFocusToDefault () {
* Sets the selected focus * Sets the selected focus
* @param {String} focusID The id of the focus, without # * @param {String} focusID The id of the focus, without #
*/ */
function setFocus (focusID) { function setFocus(focusID) {
$('#focus-select option[value="' + focusID + '"]').prop('selected', true); $('#focus-select option[value="' + focusID + '"]').prop('selected', true);
$('#focus-select').change(); $('#focus-select').change();
} }
function checkFocusEditable () { function focusChanged() {
if (getCurrentFocus().startsWith('focus_')) { var selectedFocus = getCurrentFocus();
if (focusIsEditable(selectedFocus)) {
enableEditFocusBtn(); enableEditFocusBtn();
} else { } else {
disableEditFocusBtn(); disableEditFocusBtn();
} }
loadFocusForSearch(selectedFocus);
}
function focusIsEditable(focus) {
if (focus.startsWith('focus_')) {
return true
} else {
return false
}
} }
function enableEditFocusBtn () { function enableEditFocusBtn() {
$('#editFocusBtn').removeClass('disabled').click(editCurrentFocus); $('#editFocusBtn').removeClass('disabled').click(editCurrentFocus);
} }
function disableEditFocusBtn () { function disableEditFocusBtn() {
$('#editFocusBtn').addClass('disabled').off('click'); $('#editFocusBtn').addClass('disabled').off('click');
} }
function loadSelectedFocus() { function loadFocusForSearch(focus) {
var url = window.location; var focus = loadFocusById(focus);
var focus = /focus=(focus_\w+)/.exec(url)[1]; clearCustomSearch();
if (focus) { for (var key in focus) {
setFocus(focus); if (key.startsWith("engine_") && focus[key] == 'on') {
addSumaToCustomSearch(key);
}
} }
} }
function clearCustomSearch() {
$('.custom-search-hidden').empty();
}
function addSumaToCustomSearch(sumaId) {
$('.custom-search-hidden').append('<input type="hidden" name="' + sumaId + '" value="on">');
}
function getFocusInUrl() {
var url = window.location;
var focReg = /focus=(focus_\w+)/.exec(url);
if (focReg && focReg[1]) {
return focReg[1];
}
}
//# sourceMappingURL=searchbar.js.map //# sourceMappingURL=searchbar.js.map
...@@ -2,14 +2,14 @@ $(function () { ...@@ -2,14 +2,14 @@ $(function () {
loadLocalStorage(); loadLocalStorage();
setSearchbarActionListeners(); setSearchbarActionListeners();
loadInitialCustomFocuses(); loadInitialCustomFocuses();
checkFocusEditable(); loadInitialSelectedFocus();
loadSelectedFocus(); focusChanged();
}); });
/** /**
* Loads the user theme and stored settings from local storage * Loads the user theme and stored settings from local storage
*/ */
function loadLocalStorage () { function loadLocalStorage() {
if (localStorage) { if (localStorage) {
setSettings(); setSettings();
} }
...@@ -18,13 +18,13 @@ function loadLocalStorage () { ...@@ -18,13 +18,13 @@ function loadLocalStorage () {
/** /**
* Sets all action listeners for this page * Sets all action listeners for this page
*/ */
function setSearchbarActionListeners () { function setSearchbarActionListeners() {
$('.focusCheckbox').click(toggleDeleteButton); $('.focusCheckbox').click(toggleDeleteButton);
$('#addFocusBtn').click(() => showFocusCreateDialog('')); $('#addFocusBtn').click(() => showFocusCreateDialog(''));
$('#editFocusBtn').click(editCurrentFocus); $('#editFocusBtn').click(editCurrentFocus);
$('.save-focus-btn').click(saveFocus); $('.save-focus-btn').click(saveFocus);
$('.delete-focus-btn').click(deleteFocus); $('.delete-focus-btn').click(deleteFocus);
$('#focus-select').change(checkFocusEditable); $('#focus-select').change(focusChanged);
// Save Focus on clicking enter while in the focus name input // Save Focus on clicking enter while in the focus name input
$('#focus-name').keyup(function (event) { $('#focus-name').keyup(function (event) {
if (event.keyCode == 13) { if (event.keyCode == 13) {
...@@ -36,7 +36,7 @@ function setSearchbarActionListeners () { ...@@ -36,7 +36,7 @@ function setSearchbarActionListeners () {
}); });
} }
function setSettings () { function setSettings() {
var acceptedParams = ['autocomplete', 'key', 'lang', 'newtab', 'sprueche']; var acceptedParams = ['autocomplete', 'key', 'lang', 'newtab', 'sprueche'];
for (var key in localStorage) { for (var key in localStorage) {
var value = localStorage.getItem(key); var value = localStorage.getItem(key);
...@@ -66,7 +66,7 @@ function setSettings () { ...@@ -66,7 +66,7 @@ function setSettings () {
/** /**
* Loads all the custom focuses stored in local storage * Loads all the custom focuses stored in local storage
*/ */
function loadInitialCustomFocuses () { function loadInitialCustomFocuses() {
for (var key in localStorage) { for (var key in localStorage) {
if (key.startsWith('focus_')) { if (key.startsWith('focus_')) {
var focus = loadFocusById(key); var focus = loadFocusById(key);
...@@ -75,11 +75,15 @@ function loadInitialCustomFocuses () { ...@@ -75,11 +75,15 @@ function loadInitialCustomFocuses () {
} }
} }
function loadInitialSelectedFocus() {
setFocus(getFocusInUrl());
}
/** /**
* Shows the focus create dialog * Shows the focus create dialog
* If an id is given it will try to load a focus for the given id * If an id is given it will try to load a focus for the given id
*/ */
function showFocusCreateDialog (id) { function showFocusCreateDialog(id) {
if (id === undefined) { if (id === undefined) {
id = ''; id = '';
} }
...@@ -109,28 +113,26 @@ function showFocusCreateDialog (id) { ...@@ -109,28 +113,26 @@ function showFocusCreateDialog (id) {
/** /**
* Shows the focus create dialog for a given id * Shows the focus create dialog for a given id
*/ */
function showFocusEditDialog (id) { function showFocusEditDialog(id) {
showFocusCreateDialog(id); showFocusCreateDialog(id);
} }
function getCurrentFocus () { function getCurrentFocus() {
return document.getElementById('focus-select').value; return document.getElementById('focus-select').value;
} }
/** /**
* Shows an edit dialog for the current selected focus * Shows an edit dialog for the current selected focus
*/ */
function editCurrentFocus () { function editCurrentFocus() {
console.log('hi');
var currentFocus = getCurrentFocus(); var currentFocus = getCurrentFocus();
console.log(currentFocus);
showFocusEditDialog(currentFocus); showFocusEditDialog(currentFocus);
} }
/** /**
* Shows/Hides the delete button if (no) checkboxes are selected * Shows/Hides the delete button if (no) checkboxes are selected
*/ */
function toggleDeleteButton () { function toggleDeleteButton() {
if (atLeastOneChecked()) { if (atLeastOneChecked()) {
$('.delete-focus-btn').show(); $('.delete-focus-btn').show();
} else {