From 1bcbf9f71b475070934708327cc220b1f502080a Mon Sep 17 00:00:00 2001 From: Thomas Saedt Date: Sun, 30 May 2021 13:27:39 +0200 Subject: [PATCH] [1081] Made show booking form field settings functional --- application/controllers/Backend_api.php | 18 ++++ application/views/backend/settings.php | 119 +++++++++++++----------- assets/css/backend.css | 11 ++- assets/js/backend_settings.js | 77 +++++++++++++++ assets/js/backend_settings_system.js | 50 ++++++++++ 5 files changed, 219 insertions(+), 56 deletions(-) diff --git a/application/controllers/Backend_api.php b/application/controllers/Backend_api.php index 4abc641c..0688964b 100755 --- a/application/controllers/Backend_api.php +++ b/application/controllers/Backend_api.php @@ -1444,6 +1444,24 @@ class Backend_api extends EA_Controller { $settings = json_decode($this->input->post('settings', FALSE), TRUE); + //check if phone number settings are valid + $phone_number_required = false; + $phone_number_shown = false; + foreach ($settings as $setting) + { + if ($setting['name'] == "require_phone_number"){ + $phone_number_required = $setting['value']; + } + + if ($setting['name'] == "show_phone_number"){ + $phone_number_shown = $setting['value']; + } + } + + if ($phone_number_required && !$phone_number_shown){//we have settings that break the appointments field. + throw new Exception("You cannot hide the phone number in the booking form while it's also required!"); + } + $this->settings_model->save_settings($settings); } else diff --git a/application/views/backend/settings.php b/application/views/backend/settings.php index 13040851..73840ba9 100755 --- a/application/views/backend/settings.php +++ b/application/views/backend/settings.php @@ -168,6 +168,70 @@ + + + + + + + + + + +
+
+
+ + + + + + + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
@@ -214,61 +278,6 @@
-
-
-
- - - - -
-
-
- - - - - - - -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
diff --git a/assets/css/backend.css b/assets/css/backend.css index bd6fb870..bc5a7c41 100644 --- a/assets/css/backend.css +++ b/assets/css/backend.css @@ -285,7 +285,16 @@ body legend { } .form-sub-button img{ - margin-top: -.3rem; + margin-top: -.25rem; +} + +.hidden{ + visibility: hidden; + height: 0; +} + +.hide-toggle div{ + display: flex; } @media (min-width: 768px) { diff --git a/assets/js/backend_settings.js b/assets/js/backend_settings.js index bcfe96ef..61df8787 100644 --- a/assets/js/backend_settings.js +++ b/assets/js/backend_settings.js @@ -101,6 +101,26 @@ window.BackendSettings = window.BackendSettings || {}; if (setting.name === 'privacy_policy_content') { $('#privacy-policy-content').trumbowyg('html', setting.value); } + + if (setting.name === 'show_phone_number' && setting.value === "1") { + $('#show-phone-number').find("div").toggleClass("hidden"); + } + + if (setting.name === 'show_address' && setting.value === "1") { + $('#show-address').find("div").toggleClass("hidden"); + } + + if (setting.name === 'show_city' && setting.value === "1") { + $('#show-city').find("div").toggleClass("hidden"); + } + + if (setting.name === 'show_zip_code' && setting.value === "1") { + $('#show-zip-code').find("div").toggleClass("hidden"); + } + + if (setting.name === 'show_notes' && setting.value === "1") { + $('#show-notes').find("div").toggleClass("hidden"); + } }); exports.wp = new WorkingPlan(); @@ -187,6 +207,63 @@ window.BackendSettings = window.BackendSettings || {}; settings.save(data); }); + /** + * Event: Visible/Hidden button "Click" + * + * Change the state of the Visible/Hidden button + */ + $('.hide-toggle').on('click', function () { + let $input = $(this); + $input.find("div").toggleClass("hidden"); + }); + + /** + * set a Visible/Hidden toggle button to a certain state + * + * @argument $element for which jquery element to set the state for + * @argument isVisible a boolean which is true if the button should display 'visible' and false when the button should display 'hidden' + * + */ + function setShowToggleValue($element, isVisible){ + if (getShowToggleValue($element) !== isVisible){ + $element.find("div").toggleClass("hidden"); + } + } + + /** + * get the Visible/Hidden toggle button + * + * @argument $element for which jquery element to set the state for + * + * @return the state of the button. True for visible, false for hidden. + */ + function getShowToggleValue($element){ + let visiblePartArray = $element.find(".hide-toggle-visible"); + return !visiblePartArray.hasClass("hidden"); + } + + /** + * Event: require phone number switch "Click" + * + * make sure that our phone number is visible when it is required. + */ + $('#show-phone-number').on('click', function () { + if (!getShowToggleValue($(this))){//if button is set to hidden + $('#require-phone-number').prop('checked', false); + } + }); + + /** + * Event: require phone number switch "Click" + * + * make sure that our phone number is visible when it is required. + */ + $('#require-phone-number').on('click', function () { + if ($(this).prop('checked')){ + setShowToggleValue($('#show-phone-number'), true); + } + }); + /** * Event: Username "Focusout" * diff --git a/assets/js/backend_settings_system.js b/assets/js/backend_settings_system.js index 46cb4fd8..723df1ea 100644 --- a/assets/js/backend_settings_system.js +++ b/assets/js/backend_settings_system.js @@ -63,6 +63,29 @@ }); }; + /** + * Get the state of a visible/hidden toggle button + * + * This method uses the DOM elements of the backend/settings page, so it can't be used in another page. + * + * @argument the element jquery of a button object that is a visible/hidden toggle. + * + * @return '0' when the button shows 'invisible' and '1' when the button shows 'visible'. Will always return '0' on an error. + */ + function getToggleButtonState($element) { + let visiblePartArray = $element.find(".hide-toggle-visible"); + let invisiblePartArray = $element.find(".hide-toggle-hidden"); + if (!(visiblePartArray.length === 0 || invisiblePartArray.length === 0)) { + if (visiblePartArray.hasClass("hidden")){//our button is currently invisible + return '0';//invisible + }else{//our button is currently visible + return '1';//visible + } + }else{ + return '0';//invisible + } + } + /** * Prepare the system settings array. * @@ -102,6 +125,33 @@ value: $('#display-any-provider').prop('checked') ? '1' : '0' }); + //Client Form Tab + + settings.push({ + name: 'show_phone_number', + value: getToggleButtonState($('#show-phone-number')) + }); + + settings.push({ + name: 'show_address', + value: getToggleButtonState($('#show-address')) + }); + + settings.push({ + name: 'show_city', + value: getToggleButtonState($('#show-city')) + }); + + settings.push({ + name: 'show_zip_code', + value: getToggleButtonState($('#show-zip-code')) + }); + + settings.push({ + name: 'show_notes', + value: getToggleButtonState($('#show-notes')) + }); + // Business Logic Tab