From 725a3b45ad662876adc04dfd3139156554e29229 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Mon, 6 Nov 2023 15:42:55 +0700 Subject: [PATCH 1/3] 41662 geo range search mandatory fields --- css/admin.css | 10 ++++++++++ dist/admin.min.js | 2 +- js/admin.js | 19 +++++++++++++++++++ plugin/Controller/GeoPositionFieldHandler.php | 1 + plugin/Gui/AdminPageEstateListSettings.php | 3 ++- plugin/Installer/DatabaseChanges.php | 19 ++++++++++++++++++- tests/TestClassDatabaseChanges.php | 4 ++-- tests/TestClassGeoPositionFieldHandler.php | 1 + 8 files changed, 54 insertions(+), 5 deletions(-) diff --git a/css/admin.css b/css/admin.css index 0483f5807..3654ae798 100644 --- a/css/admin.css +++ b/css/admin.css @@ -496,4 +496,14 @@ body #post-body-content p.wp-clearfix:nth-child(1){ font-size: 14px; white-space: nowrap; } +} + +input[name=oopluginlistviews-countryactive]:checked::before, +input[name=oopluginlistviews-radiusactive]:checked::before { + filter: brightness(0) saturate(100%) invert(35%) sepia(4%) saturate(967%) hue-rotate(170deg) brightness(91%) contrast(94%); +} + +input[name=oopluginlistviews-countryactive], +input[name=oopluginlistviews-radiusactive] { + pointer-events: none; } \ No newline at end of file diff --git a/dist/admin.min.js b/dist/admin.min.js index 572006fd7..a22fa5565 100644 --- a/dist/admin.min.js +++ b/dist/admin.min.js @@ -1 +1 @@ -jQuery(document).ready((function($){$(document).on("click",".notice-save-view.notice-dismiss",(function(){$(this).parent().remove()}));$("#theme-options-form").submit((function(){$(this).ajaxSubmit({onLoading:$(".loader").show(),success:function(){$(".loader").hide();$("#save-result").fadeIn();setTimeout((function(){$("#save-result").fadeOut("fast")}),2e3)},timeout:5e3});return false}));$(".sortable-item").mouseover((function(){$(this).find(".sort-arrows").stop(true,true).show()}));$(".sortable-item").mouseout((function(){$(this).find(".sort-arrows").stop(true,true).hide()}));$(".filter-fields-list").sortable({axis:"y",handle:".menu-item-bar"});$(".property-detail-items-list").sortable({axis:"y"});$(".agent-detail-items-list").sortable({axis:"y"});$(".inputFieldCheckboxButton").click((function(){getCheckedFields(this)}));$(".inputFieldButton").click((function(){getCheckedFieldButton(this)}));$(".item-edit").click((function(){$(this).parent().parent().parent().parent().find(".menu-item-settings").toggle()}));$(".item-delete-link").click((function(){var labelButtonHandleField=$(this).parent().parent().attr("action-field-name");var data=document.querySelector("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).children().first().removeClass("dashicons-remove");$(data).children().first().addClass("dashicons-insert");$(data).children().next().css("opacity","1");$(data).children().attr("typeField",1);$(this).parent().parent().remove()}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){$(btn).children().first().removeClass("dashicons-insert");$(btn).children().first().addClass("dashicons-remove");var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");var valElLabel=$(btn).children().next().text();var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$(btn).children().first().next().css("opacity","0.5");$(btn).children().first().attr("typeField",removeField);var optionsAvailable=false;var checkedFields=[];if($(btn).attr("onoffice-multipleSelectType")){optionsAvailable=$(btn).attr("onoffice-multipleSelectType")==="1"}var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable,actionFieldName);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}else{var valElName=$(btn).attr("value");var checkedFields=[];$(btn).children().first().next().css("opacity","1");$(btn).children().first().removeClass("dashicons-remove");$(btn).children().first().addClass("dashicons-insert");$(btn).children().first().attr("typeField",addField);$("*#sortableFieldsList").find("#menu-item-"+valElName).remove()}return checkedFields};var getCheckedFields=function(but){var label=$(but).attr("data-action-div");var categoryShort=but.name;var category=$(but).attr("data-onoffice-category");var checkedFields=[];var inputConfigFields=$("#"+categoryShort).find("input.onoffice-possible-input:checked");$(inputConfigFields).each((function(index){var valElName=$(this).val();var valElLabel=$(this).next().text();var module=$(this).attr("data-onoffice-module");var optionsAvailable=false;if($(this).attr("onoffice-multipleSelectType")){optionsAvailable=$(this).attr("onoffice-multipleSelectType")==="1"}var attachField=false;if($(".attachSortableFieldsList").length==1){if($("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}else{var detailViewDivId="actionForestate";if(categoryShort.startsWith("address")){detailViewDivId="actionForaddress"}if($("#"+detailViewDivId).find("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}if(attachField){var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}}));return checkedFields};var createNewFieldItem=function(fieldName,fieldLabel,fieldCategory,module,label,optionsAvailable,actionFieldName){var myLabel=label?$("#"+label):{};var dummyKey;if(myLabel.length){dummyKey=myLabel.find("#menu-item-dummy_key")}else{dummyKey=$("#menu-item-dummy_key")}var clonedElement=dummyKey.clone(true,true);clonedElement.attr("id","menu-item-"+fieldName);clonedElement.attr("action-field-name",actionFieldName);clonedElement.find('span.item-title:contains("dummy_label")').text(fieldLabel);clonedElement.find('span.item-type:contains("dummy_category")').text(fieldCategory);clonedElement.find("input[value=dummy_key]").val(fieldName);clonedElement.find("input[name*=dummy_key]").attr("name",(function(index,name){return name.replace("dummy_key",fieldName)}));clonedElement.find("input[value=dummy_label]").val(fieldLabel);clonedElement.find("span.menu-item-settings-name").text(fieldName);clonedElement.find("input[data-onoffice-ignore=true]").removeAttr("data-onoffice-ignore");clonedElement.find("[name^=exclude]").attr("name",(function(index,name){return name.replace("exclude","")}));if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(onOffice_loc_settings.modulelabels&&module){var inputModule=clonedElement.find("input[name^=oopluginformfieldconfig-module]");inputModule.val(module);var labelIdFor=inputModule.attr("id");var moduleStr=onOffice_loc_settings.modulelabels[module];var newLabelText=onOffice_loc_settings.fieldmodule.replace("%s",moduleStr);clonedElement.find("label[for="+labelIdFor+"]").text(newLabelText)}if(onOffice!==undefined&&onOffice.checkboxAdmin){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(clonedElement)}clonedElement.show();dummyKey.parent().append(clonedElement);return clonedElement[0]}}));(function($){var refreshTemplateMouseOver=function(){var value=templateSelector.find("option:selected").text();templateSelector.attr("title",value)};var templateNameAttrs=["oopluginforms-template","oopluginlistviews-template","oopluginlistviewsaddress-template","onoffice-template"];var templateSelectorStr="select.onoffice-input[name="+templateNameAttrs.join("], select.onoffice-input[name=")+"]";var templateSelector=$(templateSelectorStr).first();templateSelector.on("change",refreshTemplateMouseOver);refreshTemplateMouseOver()})(jQuery); \ No newline at end of file +var onOffice=onOffice||{};onOffice.settings=onOffice_loc_settings;jQuery(document).ready((function($){$(document).on("click",".notice-save-view.notice-dismiss",(function(){$(this).parent().remove()}));$("#theme-options-form").submit((function(){$(this).ajaxSubmit({onLoading:$(".loader").show(),success:function(){$(".loader").hide();$("#save-result").fadeIn();setTimeout((function(){$("#save-result").fadeOut("fast")}),2e3)},timeout:5e3});return false}));$(".sortable-item").mouseover((function(){$(this).find(".sort-arrows").stop(true,true).show()}));$(".sortable-item").mouseout((function(){$(this).find(".sort-arrows").stop(true,true).hide()}));$(".filter-fields-list").sortable({axis:"y",handle:".menu-item-bar"});$(".property-detail-items-list").sortable({axis:"y"});$(".agent-detail-items-list").sortable({axis:"y"});$(".inputFieldCheckboxButton").click((function(){getCheckedFields(this)}));$(".inputFieldButton").click((function(){getCheckedFieldButton(this)}));$(".item-edit").click((function(){$(this).parent().parent().parent().parent().find(".menu-item-settings").toggle()}));$(".item-delete-link").click((function(){var labelButtonHandleField=$(this).parent().parent().attr("action-field-name");var data=document.querySelector("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).children().first().removeClass("dashicons-remove");$(data).children().first().addClass("dashicons-insert");$(data).children().next().css("opacity","1");$(data).children().attr("typeField",1);$(this).parent().parent().remove()}));const editListViewPage="admin_page_onoffice-editlistview";if(onOffice.settings.page===editListViewPage){$("#send_form").on("click",updateRequiredAttributeZipActiveField)}function updateRequiredAttributeZipActiveField(){if($("#geofields").is(":visible")){const isCityActive=$("input[name=oopluginlistviews-cityactive]:checked").is(":visible");const isZipActive=$("input[name=oopluginlistviews-zipactive]:checked").is(":visible");$("input[name=oopluginlistviews-zipactive]").attr("required","required");if(isCityActive||isZipActive){$("input[name=oopluginlistviews-zipactive]").removeAttr("required")}}}var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){$(btn).children().first().removeClass("dashicons-insert");$(btn).children().first().addClass("dashicons-remove");var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");var valElLabel=$(btn).children().next().text();var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$(btn).children().first().next().css("opacity","0.5");$(btn).children().first().attr("typeField",removeField);var optionsAvailable=false;var checkedFields=[];if($(btn).attr("onoffice-multipleSelectType")){optionsAvailable=$(btn).attr("onoffice-multipleSelectType")==="1"}var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable,actionFieldName);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}else{var valElName=$(btn).attr("value");var checkedFields=[];$(btn).children().first().next().css("opacity","1");$(btn).children().first().removeClass("dashicons-remove");$(btn).children().first().addClass("dashicons-insert");$(btn).children().first().attr("typeField",addField);$("*#sortableFieldsList").find("#menu-item-"+valElName).remove()}return checkedFields};var getCheckedFields=function(but){var label=$(but).attr("data-action-div");var categoryShort=but.name;var category=$(but).attr("data-onoffice-category");var checkedFields=[];var inputConfigFields=$("#"+categoryShort).find("input.onoffice-possible-input:checked");$(inputConfigFields).each((function(index){var valElName=$(this).val();var valElLabel=$(this).next().text();var module=$(this).attr("data-onoffice-module");var optionsAvailable=false;if($(this).attr("onoffice-multipleSelectType")){optionsAvailable=$(this).attr("onoffice-multipleSelectType")==="1"}var attachField=false;if($(".attachSortableFieldsList").length==1){if($("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}else{var detailViewDivId="actionForestate";if(categoryShort.startsWith("address")){detailViewDivId="actionForaddress"}if($("#"+detailViewDivId).find("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}if(attachField){var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}}));return checkedFields};var createNewFieldItem=function(fieldName,fieldLabel,fieldCategory,module,label,optionsAvailable,actionFieldName){var myLabel=label?$("#"+label):{};var dummyKey;if(myLabel.length){dummyKey=myLabel.find("#menu-item-dummy_key")}else{dummyKey=$("#menu-item-dummy_key")}var clonedElement=dummyKey.clone(true,true);clonedElement.attr("id","menu-item-"+fieldName);clonedElement.attr("action-field-name",actionFieldName);clonedElement.find('span.item-title:contains("dummy_label")').text(fieldLabel);clonedElement.find('span.item-type:contains("dummy_category")').text(fieldCategory);clonedElement.find("input[value=dummy_key]").val(fieldName);clonedElement.find("input[name*=dummy_key]").attr("name",(function(index,name){return name.replace("dummy_key",fieldName)}));clonedElement.find("input[value=dummy_label]").val(fieldLabel);clonedElement.find("span.menu-item-settings-name").text(fieldName);clonedElement.find("input[data-onoffice-ignore=true]").removeAttr("data-onoffice-ignore");clonedElement.find("[name^=exclude]").attr("name",(function(index,name){return name.replace("exclude","")}));if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(onOffice_loc_settings.modulelabels&&module){var inputModule=clonedElement.find("input[name^=oopluginformfieldconfig-module]");inputModule.val(module);var labelIdFor=inputModule.attr("id");var moduleStr=onOffice_loc_settings.modulelabels[module];var newLabelText=onOffice_loc_settings.fieldmodule.replace("%s",moduleStr);clonedElement.find("label[for="+labelIdFor+"]").text(newLabelText)}if(onOffice!==undefined&&onOffice.checkboxAdmin){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(clonedElement)}clonedElement.show();dummyKey.parent().append(clonedElement);return clonedElement[0]}}));(function($){var refreshTemplateMouseOver=function(){var value=templateSelector.find("option:selected").text();templateSelector.attr("title",value)};var templateNameAttrs=["oopluginforms-template","oopluginlistviews-template","oopluginlistviewsaddress-template","onoffice-template"];var templateSelectorStr="select.onoffice-input[name="+templateNameAttrs.join("], select.onoffice-input[name=")+"]";var templateSelector=$(templateSelectorStr).first();templateSelector.on("change",refreshTemplateMouseOver);refreshTemplateMouseOver()})(jQuery); \ No newline at end of file diff --git a/js/admin.js b/js/admin.js index cb263adc7..44642aea4 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,3 +1,5 @@ +var onOffice = onOffice || {}; +onOffice.settings = onOffice_loc_settings; jQuery(document).ready(function($){ $(document).on('click', '.notice-save-view.notice-dismiss', function () { $(this).parent().remove(); @@ -62,6 +64,23 @@ jQuery(document).ready(function($){ $(data).children().attr('typeField', 1); $(this).parent().parent().remove(); }); + + const editListViewPage = 'admin_page_onoffice-editlistview'; + if (onOffice.settings.page === editListViewPage) { + $('#send_form').on('click', updateRequiredAttributeZipActiveField); + } + function updateRequiredAttributeZipActiveField() { + if ($('#geofields').is(':visible')) { + const isCityActive = $('input[name=oopluginlistviews-cityactive]:checked').is(':visible'); + const isZipActive = $('input[name=oopluginlistviews-zipactive]:checked').is(':visible'); + $('input[name=oopluginlistviews-zipactive]').attr('required', 'required'); + + if (isCityActive || isZipActive) { + $('input[name=oopluginlistviews-zipactive]').removeAttr('required'); + } + } + } + var getCheckedFieldButton = function(btn) { var addField = 1; var removeField = 2; diff --git a/plugin/Controller/GeoPositionFieldHandler.php b/plugin/Controller/GeoPositionFieldHandler.php index 391e58c29..f4c12ccf2 100644 --- a/plugin/Controller/GeoPositionFieldHandler.php +++ b/plugin/Controller/GeoPositionFieldHandler.php @@ -135,6 +135,7 @@ private function getDefaultConfiguration(): array $defaultActive = [ GeoPosition::ESTATE_LIST_SEARCH_ZIP, GeoPosition::ESTATE_LIST_SEARCH_RADIUS, + GeoPosition::ESTATE_LIST_SEARCH_COUNTRY ]; $intersection = array_intersect_key($this->_booleanFields, array_flip($defaultActive)); return array_combine($intersection, array_fill(0, count($intersection), '1')); diff --git a/plugin/Gui/AdminPageEstateListSettings.php b/plugin/Gui/AdminPageEstateListSettings.php index e286e5a55..d9f74e230 100644 --- a/plugin/Gui/AdminPageEstateListSettings.php +++ b/plugin/Gui/AdminPageEstateListSettings.php @@ -188,7 +188,7 @@ protected function buildForms() $pFormModelGeoFields->addInputModel($pInputModel); } - $geoNotice = __('At least the following fields must be active: country, radius and city or postcode.', 'onoffice-for-wp-websites'); + $geoNotice = __('At least city or postcode required.', 'onoffice-for-wp-websites'); $pInputModelGeoLabel = new InputModelLabel(null, $geoNotice); $pInputModelGeoLabel->setValueEnclosure(InputModelLabel::VALUE_ENCLOSURE_ITALIC); $pFormModelGeoFields->addInputModel($pInputModelGeoLabel); @@ -310,5 +310,6 @@ public function doExtraEnqueues() wp_enqueue_style('onoffice-multiselect'); wp_enqueue_script('oo-sanitize-shortcode-name'); wp_enqueue_script('oo-copy-shortcode'); + wp_localize_script('admin-js', 'onOffice_loc_settings', ['page' => get_current_screen()->id]); } } diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index f1e1f9872..3bcfbbd4a 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -45,7 +45,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 41; + const MAX_VERSION = 42; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -298,6 +298,11 @@ public function install() $dbversion = 41; } + if ($dbversion == 41) { + $this->updateValueGeoFieldsForEsateList(); + $dbversion = 42; + } + $this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true ); } @@ -1115,4 +1120,16 @@ private function updateShowPriceOnRequestOptionForDetailView() $this->_pWpOption->updateOption('onoffice-default-view', $pDataDetailViewOptions); } } + + /** + * @return void + */ + public function updateValueGeoFieldsForEsateList() + { + $prefix = $this->getPrefix(); + $sql = "UPDATE {$prefix}oo_plugin_listviews + SET country_active = 1, radius_active = 1"; + + $this->_pWPDB->query($sql); + } } diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 3f69dacc4..428b47b08 100644 --- a/tests/TestClassDatabaseChanges.php +++ b/tests/TestClassDatabaseChanges.php @@ -118,7 +118,7 @@ public function testInstall(): array $this->assertGreaterThanOrEqual(self::NUM_NEW_TABLES, count($this->_createQueries)); $dbversion = $this->_pDbChanges->getDbVersion(); - $this->assertEquals(41, $dbversion); + $this->assertEquals(42, $dbversion); return $this->_createQueries; } @@ -271,7 +271,7 @@ public function testDeleteMessageFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(41, DatabaseChanges::MAX_VERSION); + $this->assertEquals(42, DatabaseChanges::MAX_VERSION); } diff --git a/tests/TestClassGeoPositionFieldHandler.php b/tests/TestClassGeoPositionFieldHandler.php index 4d9c500bb..c80c510a6 100644 --- a/tests/TestClassGeoPositionFieldHandler.php +++ b/tests/TestClassGeoPositionFieldHandler.php @@ -161,6 +161,7 @@ public function testDefaultValues(GeoPositionFieldHandler $pGeoPositionFieldHand $this->assertEquals([ 'radius_active' => 'radius', 'zip_active' => 'zip', + 'country_active' => 'country' ], $pGeoPositionFieldHandler->getActiveFields()); } From 457ca767ae39e50a246de23d35aff13357386666 Mon Sep 17 00:00:00 2001 From: yeneastgate Date: Fri, 16 Feb 2024 10:38:37 +0700 Subject: [PATCH 2/3] 41662 geo range search mandatory fields --- dist/admin.min.js | 2 +- js/admin.js | 19 ------------------- plugin/Gui/AdminPageEstateListSettings.php | 1 - 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/dist/admin.min.js b/dist/admin.min.js index a22fa5565..572006fd7 100644 --- a/dist/admin.min.js +++ b/dist/admin.min.js @@ -1 +1 @@ -var onOffice=onOffice||{};onOffice.settings=onOffice_loc_settings;jQuery(document).ready((function($){$(document).on("click",".notice-save-view.notice-dismiss",(function(){$(this).parent().remove()}));$("#theme-options-form").submit((function(){$(this).ajaxSubmit({onLoading:$(".loader").show(),success:function(){$(".loader").hide();$("#save-result").fadeIn();setTimeout((function(){$("#save-result").fadeOut("fast")}),2e3)},timeout:5e3});return false}));$(".sortable-item").mouseover((function(){$(this).find(".sort-arrows").stop(true,true).show()}));$(".sortable-item").mouseout((function(){$(this).find(".sort-arrows").stop(true,true).hide()}));$(".filter-fields-list").sortable({axis:"y",handle:".menu-item-bar"});$(".property-detail-items-list").sortable({axis:"y"});$(".agent-detail-items-list").sortable({axis:"y"});$(".inputFieldCheckboxButton").click((function(){getCheckedFields(this)}));$(".inputFieldButton").click((function(){getCheckedFieldButton(this)}));$(".item-edit").click((function(){$(this).parent().parent().parent().parent().find(".menu-item-settings").toggle()}));$(".item-delete-link").click((function(){var labelButtonHandleField=$(this).parent().parent().attr("action-field-name");var data=document.querySelector("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).children().first().removeClass("dashicons-remove");$(data).children().first().addClass("dashicons-insert");$(data).children().next().css("opacity","1");$(data).children().attr("typeField",1);$(this).parent().parent().remove()}));const editListViewPage="admin_page_onoffice-editlistview";if(onOffice.settings.page===editListViewPage){$("#send_form").on("click",updateRequiredAttributeZipActiveField)}function updateRequiredAttributeZipActiveField(){if($("#geofields").is(":visible")){const isCityActive=$("input[name=oopluginlistviews-cityactive]:checked").is(":visible");const isZipActive=$("input[name=oopluginlistviews-zipactive]:checked").is(":visible");$("input[name=oopluginlistviews-zipactive]").attr("required","required");if(isCityActive||isZipActive){$("input[name=oopluginlistviews-zipactive]").removeAttr("required")}}}var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){$(btn).children().first().removeClass("dashicons-insert");$(btn).children().first().addClass("dashicons-remove");var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");var valElLabel=$(btn).children().next().text();var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$(btn).children().first().next().css("opacity","0.5");$(btn).children().first().attr("typeField",removeField);var optionsAvailable=false;var checkedFields=[];if($(btn).attr("onoffice-multipleSelectType")){optionsAvailable=$(btn).attr("onoffice-multipleSelectType")==="1"}var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable,actionFieldName);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}else{var valElName=$(btn).attr("value");var checkedFields=[];$(btn).children().first().next().css("opacity","1");$(btn).children().first().removeClass("dashicons-remove");$(btn).children().first().addClass("dashicons-insert");$(btn).children().first().attr("typeField",addField);$("*#sortableFieldsList").find("#menu-item-"+valElName).remove()}return checkedFields};var getCheckedFields=function(but){var label=$(but).attr("data-action-div");var categoryShort=but.name;var category=$(but).attr("data-onoffice-category");var checkedFields=[];var inputConfigFields=$("#"+categoryShort).find("input.onoffice-possible-input:checked");$(inputConfigFields).each((function(index){var valElName=$(this).val();var valElLabel=$(this).next().text();var module=$(this).attr("data-onoffice-module");var optionsAvailable=false;if($(this).attr("onoffice-multipleSelectType")){optionsAvailable=$(this).attr("onoffice-multipleSelectType")==="1"}var attachField=false;if($(".attachSortableFieldsList").length==1){if($("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}else{var detailViewDivId="actionForestate";if(categoryShort.startsWith("address")){detailViewDivId="actionForaddress"}if($("#"+detailViewDivId).find("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}if(attachField){var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}}));return checkedFields};var createNewFieldItem=function(fieldName,fieldLabel,fieldCategory,module,label,optionsAvailable,actionFieldName){var myLabel=label?$("#"+label):{};var dummyKey;if(myLabel.length){dummyKey=myLabel.find("#menu-item-dummy_key")}else{dummyKey=$("#menu-item-dummy_key")}var clonedElement=dummyKey.clone(true,true);clonedElement.attr("id","menu-item-"+fieldName);clonedElement.attr("action-field-name",actionFieldName);clonedElement.find('span.item-title:contains("dummy_label")').text(fieldLabel);clonedElement.find('span.item-type:contains("dummy_category")').text(fieldCategory);clonedElement.find("input[value=dummy_key]").val(fieldName);clonedElement.find("input[name*=dummy_key]").attr("name",(function(index,name){return name.replace("dummy_key",fieldName)}));clonedElement.find("input[value=dummy_label]").val(fieldLabel);clonedElement.find("span.menu-item-settings-name").text(fieldName);clonedElement.find("input[data-onoffice-ignore=true]").removeAttr("data-onoffice-ignore");clonedElement.find("[name^=exclude]").attr("name",(function(index,name){return name.replace("exclude","")}));if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(onOffice_loc_settings.modulelabels&&module){var inputModule=clonedElement.find("input[name^=oopluginformfieldconfig-module]");inputModule.val(module);var labelIdFor=inputModule.attr("id");var moduleStr=onOffice_loc_settings.modulelabels[module];var newLabelText=onOffice_loc_settings.fieldmodule.replace("%s",moduleStr);clonedElement.find("label[for="+labelIdFor+"]").text(newLabelText)}if(onOffice!==undefined&&onOffice.checkboxAdmin){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(clonedElement)}clonedElement.show();dummyKey.parent().append(clonedElement);return clonedElement[0]}}));(function($){var refreshTemplateMouseOver=function(){var value=templateSelector.find("option:selected").text();templateSelector.attr("title",value)};var templateNameAttrs=["oopluginforms-template","oopluginlistviews-template","oopluginlistviewsaddress-template","onoffice-template"];var templateSelectorStr="select.onoffice-input[name="+templateNameAttrs.join("], select.onoffice-input[name=")+"]";var templateSelector=$(templateSelectorStr).first();templateSelector.on("change",refreshTemplateMouseOver);refreshTemplateMouseOver()})(jQuery); \ No newline at end of file +jQuery(document).ready((function($){$(document).on("click",".notice-save-view.notice-dismiss",(function(){$(this).parent().remove()}));$("#theme-options-form").submit((function(){$(this).ajaxSubmit({onLoading:$(".loader").show(),success:function(){$(".loader").hide();$("#save-result").fadeIn();setTimeout((function(){$("#save-result").fadeOut("fast")}),2e3)},timeout:5e3});return false}));$(".sortable-item").mouseover((function(){$(this).find(".sort-arrows").stop(true,true).show()}));$(".sortable-item").mouseout((function(){$(this).find(".sort-arrows").stop(true,true).hide()}));$(".filter-fields-list").sortable({axis:"y",handle:".menu-item-bar"});$(".property-detail-items-list").sortable({axis:"y"});$(".agent-detail-items-list").sortable({axis:"y"});$(".inputFieldCheckboxButton").click((function(){getCheckedFields(this)}));$(".inputFieldButton").click((function(){getCheckedFieldButton(this)}));$(".item-edit").click((function(){$(this).parent().parent().parent().parent().find(".menu-item-settings").toggle()}));$(".item-delete-link").click((function(){var labelButtonHandleField=$(this).parent().parent().attr("action-field-name");var data=document.querySelector("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).children().first().removeClass("dashicons-remove");$(data).children().first().addClass("dashicons-insert");$(data).children().next().css("opacity","1");$(data).children().attr("typeField",1);$(this).parent().parent().remove()}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){$(btn).children().first().removeClass("dashicons-insert");$(btn).children().first().addClass("dashicons-remove");var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");var valElLabel=$(btn).children().next().text();var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$(btn).children().first().next().css("opacity","0.5");$(btn).children().first().attr("typeField",removeField);var optionsAvailable=false;var checkedFields=[];if($(btn).attr("onoffice-multipleSelectType")){optionsAvailable=$(btn).attr("onoffice-multipleSelectType")==="1"}var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable,actionFieldName);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}else{var valElName=$(btn).attr("value");var checkedFields=[];$(btn).children().first().next().css("opacity","1");$(btn).children().first().removeClass("dashicons-remove");$(btn).children().first().addClass("dashicons-insert");$(btn).children().first().attr("typeField",addField);$("*#sortableFieldsList").find("#menu-item-"+valElName).remove()}return checkedFields};var getCheckedFields=function(but){var label=$(but).attr("data-action-div");var categoryShort=but.name;var category=$(but).attr("data-onoffice-category");var checkedFields=[];var inputConfigFields=$("#"+categoryShort).find("input.onoffice-possible-input:checked");$(inputConfigFields).each((function(index){var valElName=$(this).val();var valElLabel=$(this).next().text();var module=$(this).attr("data-onoffice-module");var optionsAvailable=false;if($(this).attr("onoffice-multipleSelectType")){optionsAvailable=$(this).attr("onoffice-multipleSelectType")==="1"}var attachField=false;if($(".attachSortableFieldsList").length==1){if($("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}else{var detailViewDivId="actionForestate";if(categoryShort.startsWith("address")){detailViewDivId="actionForaddress"}if($("#"+detailViewDivId).find("#sortableFieldsList").find("#menu-item-"+valElName).length===0){attachField=true}}if(attachField){var clonedItem=createNewFieldItem(valElName,valElLabel,category,module,label,optionsAvailable);var event=new CustomEvent("addFieldItem",{detail:{fieldname:valElName,fieldlabel:valElLabel,category:category,module:module,item:clonedItem}});document.dispatchEvent(event)}}));return checkedFields};var createNewFieldItem=function(fieldName,fieldLabel,fieldCategory,module,label,optionsAvailable,actionFieldName){var myLabel=label?$("#"+label):{};var dummyKey;if(myLabel.length){dummyKey=myLabel.find("#menu-item-dummy_key")}else{dummyKey=$("#menu-item-dummy_key")}var clonedElement=dummyKey.clone(true,true);clonedElement.attr("id","menu-item-"+fieldName);clonedElement.attr("action-field-name",actionFieldName);clonedElement.find('span.item-title:contains("dummy_label")').text(fieldLabel);clonedElement.find('span.item-type:contains("dummy_category")').text(fieldCategory);clonedElement.find("input[value=dummy_key]").val(fieldName);clonedElement.find("input[name*=dummy_key]").attr("name",(function(index,name){return name.replace("dummy_key",fieldName)}));clonedElement.find("input[value=dummy_label]").val(fieldLabel);clonedElement.find("span.menu-item-settings-name").text(fieldName);clonedElement.find("input[data-onoffice-ignore=true]").removeAttr("data-onoffice-ignore");clonedElement.find("[name^=exclude]").attr("name",(function(index,name){return name.replace("exclude","")}));if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(onOffice_loc_settings.modulelabels&&module){var inputModule=clonedElement.find("input[name^=oopluginformfieldconfig-module]");inputModule.val(module);var labelIdFor=inputModule.attr("id");var moduleStr=onOffice_loc_settings.modulelabels[module];var newLabelText=onOffice_loc_settings.fieldmodule.replace("%s",moduleStr);clonedElement.find("label[for="+labelIdFor+"]").text(newLabelText)}if(onOffice!==undefined&&onOffice.checkboxAdmin){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(clonedElement)}clonedElement.show();dummyKey.parent().append(clonedElement);return clonedElement[0]}}));(function($){var refreshTemplateMouseOver=function(){var value=templateSelector.find("option:selected").text();templateSelector.attr("title",value)};var templateNameAttrs=["oopluginforms-template","oopluginlistviews-template","oopluginlistviewsaddress-template","onoffice-template"];var templateSelectorStr="select.onoffice-input[name="+templateNameAttrs.join("], select.onoffice-input[name=")+"]";var templateSelector=$(templateSelectorStr).first();templateSelector.on("change",refreshTemplateMouseOver);refreshTemplateMouseOver()})(jQuery); \ No newline at end of file diff --git a/js/admin.js b/js/admin.js index 44642aea4..cb263adc7 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,5 +1,3 @@ -var onOffice = onOffice || {}; -onOffice.settings = onOffice_loc_settings; jQuery(document).ready(function($){ $(document).on('click', '.notice-save-view.notice-dismiss', function () { $(this).parent().remove(); @@ -64,23 +62,6 @@ jQuery(document).ready(function($){ $(data).children().attr('typeField', 1); $(this).parent().parent().remove(); }); - - const editListViewPage = 'admin_page_onoffice-editlistview'; - if (onOffice.settings.page === editListViewPage) { - $('#send_form').on('click', updateRequiredAttributeZipActiveField); - } - function updateRequiredAttributeZipActiveField() { - if ($('#geofields').is(':visible')) { - const isCityActive = $('input[name=oopluginlistviews-cityactive]:checked').is(':visible'); - const isZipActive = $('input[name=oopluginlistviews-zipactive]:checked').is(':visible'); - $('input[name=oopluginlistviews-zipactive]').attr('required', 'required'); - - if (isCityActive || isZipActive) { - $('input[name=oopluginlistviews-zipactive]').removeAttr('required'); - } - } - } - var getCheckedFieldButton = function(btn) { var addField = 1; var removeField = 2; diff --git a/plugin/Gui/AdminPageEstateListSettings.php b/plugin/Gui/AdminPageEstateListSettings.php index d9f74e230..dda47f499 100644 --- a/plugin/Gui/AdminPageEstateListSettings.php +++ b/plugin/Gui/AdminPageEstateListSettings.php @@ -310,6 +310,5 @@ public function doExtraEnqueues() wp_enqueue_style('onoffice-multiselect'); wp_enqueue_script('oo-sanitize-shortcode-name'); wp_enqueue_script('oo-copy-shortcode'); - wp_localize_script('admin-js', 'onOffice_loc_settings', ['page' => get_current_screen()->id]); } } From f10ec7e368fe981513f8598e636be45e2907379a Mon Sep 17 00:00:00 2001 From: andernath Date: Mon, 19 Feb 2024 11:30:57 +0100 Subject: [PATCH 3/3] Fix typo --- plugin/Gui/AdminPageEstateListSettings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/Gui/AdminPageEstateListSettings.php b/plugin/Gui/AdminPageEstateListSettings.php index dda47f499..53b2b2f5b 100644 --- a/plugin/Gui/AdminPageEstateListSettings.php +++ b/plugin/Gui/AdminPageEstateListSettings.php @@ -188,7 +188,7 @@ protected function buildForms() $pFormModelGeoFields->addInputModel($pInputModel); } - $geoNotice = __('At least city or postcode required.', 'onoffice-for-wp-websites'); + $geoNotice = __('At least city or postcode are required.', 'onoffice-for-wp-websites'); $pInputModelGeoLabel = new InputModelLabel(null, $geoNotice); $pInputModelGeoLabel->setValueEnclosure(InputModelLabel::VALUE_ENCLOSURE_ITALIC); $pFormModelGeoFields->addInputModel($pInputModelGeoLabel);