From 23e0b1e570603748e61b466bc916aaaedc5ab23b Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Mon, 11 Mar 2024 17:36:23 +0700 Subject: [PATCH 01/12] 45380 multiple contact types in form specific options --- css/admin.css | 11 +++ dist/admin.min.js | 2 +- js/admin.js | 4 + .../DataFormConfiguration.php | 12 +-- .../DataFormConfigurationFactory.php | 6 +- plugin/Form/FormAddressCreator.php | 4 +- plugin/Gui/AdminPageFormSettingsBase.php | 12 +++ plugin/Installer/DatabaseChanges.php | 47 ++++++++++- .../FormModelBuilderDBForm.php | 8 +- .../InputModelDBFactoryConfigForm.php | 2 +- plugin/Model/InputModelBase.php | 3 + plugin/Model/InputModelDBAdapterRow.php | 5 ++ plugin/Record/RecordManager.php | 3 + .../RecordManagerDuplicateListViewForm.php | 9 ++ plugin/Record/RecordManagerRead.php | 21 +++++ plugin/Record/RecordManagerReadForm.php | 3 + plugin/Record/RecordManagerUpdateForm.php | 21 +++++ plugin/Record/RecordStructure.php | 6 ++ .../InputFieldMultipleSelectTwoRenderer.php | 47 +++++++++++ plugin/Renderer/InputModelRenderer.php | 8 ++ tests/TestClassDatabaseChanges.php | 2 +- ...assInputFieldMultipleSelectTwoRenderer.php | 82 +++++++++++++++++++ tests/TestClassRecordManagerReadForm.php | 25 ++++++ 23 files changed, 326 insertions(+), 17 deletions(-) create mode 100644 plugin/Renderer/InputFieldMultipleSelectTwoRenderer.php create mode 100644 tests/TestClassInputFieldMultipleSelectTwoRenderer.php diff --git a/css/admin.css b/css/admin.css index c8d4768f1..7583a63a7 100644 --- a/css/admin.css +++ b/css/admin.css @@ -743,3 +743,14 @@ body #post-head-content p.wp-clearfix:nth-child(1) { margin: 0 !important; } } + +.oo-poststuff .custom-input-field .select2 { + width: 50% !important; +} + +.oo-poststuff .custom-input-field .select2 .select2-selection { + display: flex; + border: 1px solid #8c8f94; + min-height: 30px; + height: 100%; +} \ No newline at end of file diff --git a/dist/admin.min.js b/dist/admin.min.js index efd6ac163..be5a70848 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");const data=$("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",1);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$(this).parent().parent().remove()}));$(".oo-search-field .input-search").on("input",(function(){let filter=$(this).val().toUpperCase();let clearIcon=$(".clear-icon");if($(this).val().trim()!==""){clearIcon.removeClass("dashicons-search").addClass("dashicons-no-alt")}else{clearIcon.removeClass("dashicons-no-alt").addClass("dashicons-search")}$(".oo-search-field .field-lists .search-field-item").each((function(){let dataLabel=$(this).data("label").toUpperCase();let dataKey=$(this).data("key").toUpperCase();let dataContent=$(this).data("content").toUpperCase();if(dataLabel.indexOf(filter)>-1||dataKey.indexOf(filter)>-1||dataContent.indexOf(filter)>-1){$(this).show()}else{$(this).hide()}}))})).on("keypress",(function(event){if(event.which==13){event.preventDefault()}}));$(document).on("click",(function(event){let $fieldLists=$(".oo-search-field .field-lists");let $inputSearch=$(".oo-search-field .input-search");if(!$(event.target).closest($fieldLists).length&&event.target!==$inputSearch[0]){$fieldLists.hide()}}));$(".oo-search-field .input-search").on("click",(function(event){event.stopPropagation();$(".field-lists").show()}));$(".oo-search-field #clear-input").on("click",(function(){$(".input-search").val("").trigger("input")}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");const valElLabel=$(btn).attr("data-onoffice-label");var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-insert").addClass("dashicons-remove").attr("typeField",removeField);parentItem.find(".check-action").addClass("action-remove");parentItem.find(".field-item-detail").css("opacity","0.5")}));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=[];const actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",addField);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$("*#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)}));if($(".custom-multi-select2").length>0){$(".custom-multi-select2").select2()}$(".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");const data=$("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",1);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$(this).parent().parent().remove()}));$(".oo-search-field .input-search").on("input",(function(){let filter=$(this).val().toUpperCase();let clearIcon=$(".clear-icon");if($(this).val().trim()!==""){clearIcon.removeClass("dashicons-search").addClass("dashicons-no-alt")}else{clearIcon.removeClass("dashicons-no-alt").addClass("dashicons-search")}$(".oo-search-field .field-lists .search-field-item").each((function(){let dataLabel=$(this).data("label").toUpperCase();let dataKey=$(this).data("key").toUpperCase();let dataContent=$(this).data("content").toUpperCase();if(dataLabel.indexOf(filter)>-1||dataKey.indexOf(filter)>-1||dataContent.indexOf(filter)>-1){$(this).show()}else{$(this).hide()}}))})).on("keypress",(function(event){if(event.which==13){event.preventDefault()}}));$(document).on("click",(function(event){let $fieldLists=$(".oo-search-field .field-lists");let $inputSearch=$(".oo-search-field .input-search");if(!$(event.target).closest($fieldLists).length&&event.target!==$inputSearch[0]){$fieldLists.hide()}}));$(".oo-search-field .input-search").on("click",(function(event){event.stopPropagation();$(".field-lists").show()}));$(".oo-search-field #clear-input").on("click",(function(){$(".input-search").val("").trigger("input")}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");const valElLabel=$(btn).attr("data-onoffice-label");var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-insert").addClass("dashicons-remove").attr("typeField",removeField);parentItem.find(".check-action").addClass("action-remove");parentItem.find(".field-item-detail").css("opacity","0.5")}));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=[];const actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",addField);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$("*#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 5c3044ee7..208e52c9f 100644 --- a/js/admin.js +++ b/js/admin.js @@ -45,6 +45,10 @@ jQuery(document).ready(function($){ getCheckedFieldButton(this); }); + if ($('.custom-multi-select2').length > 0) { + $('.custom-multi-select2').select2(); + } + $('.item-edit').click(function() { $(this).parent().parent().parent().parent().find('.menu-item-settings').toggle(); }); diff --git a/plugin/DataFormConfiguration/DataFormConfiguration.php b/plugin/DataFormConfiguration/DataFormConfiguration.php index d44a7537a..e66ec936f 100644 --- a/plugin/DataFormConfiguration/DataFormConfiguration.php +++ b/plugin/DataFormConfiguration/DataFormConfiguration.php @@ -67,8 +67,8 @@ class DataFormConfiguration /** @var bool */ private $_showEstateContext = false; - /** @var bool */ - private $_contactType = ''; + /** @var array */ + private $_contactType = []; /** @var string */ private $_recipient = ''; @@ -139,8 +139,8 @@ public function addAvailableOptionsField(string $availableOptionsField) public function setShowEstateContext(bool $showEstateContext) { $this->_showEstateContext = $showEstateContext; } - /** @param string $contactTypeField */ - public function setContactTypeField(string $contactTypeField) + /** @param array $contactTypeField */ + public function setContactTypeField(array $contactTypeField) { $this->_contactType = $contactTypeField; } /** @return array */ @@ -208,8 +208,8 @@ public function setId(int $id) public function getShowEstateContext(): bool { return $this->_showEstateContext; } - /** @return string */ - public function getContactType(): string + /** @return array */ + public function getContactType(): array { return $this->_contactType; } /** @return bool */ diff --git a/plugin/DataFormConfiguration/DataFormConfigurationFactory.php b/plugin/DataFormConfiguration/DataFormConfigurationFactory.php index bb6fb3641..317afd188 100644 --- a/plugin/DataFormConfiguration/DataFormConfigurationFactory.php +++ b/plugin/DataFormConfiguration/DataFormConfigurationFactory.php @@ -276,7 +276,7 @@ private function configureContact(array $row, DataFormConfigurationContact $pCon $pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']); $pConfig->setNewsletterCheckbox((bool)$row['newsletter']); $pConfig->setShowEstateContext((bool)$row['show_estate_context']); - $pConfig->setContactTypeField($row['contact_type'] ?? ''); + $pConfig->setContactTypeField($row['contact_type'] ?? []); } @@ -329,7 +329,7 @@ private function configureOwner(array $row, DataFormConfigurationOwner $pConfig) $pConfig->setPages($row['pages']); $pConfig->setCreateOwner((bool)$row['createaddress']); $pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']); - $pConfig->setContactTypeField($row['contact_type'] ?? ''); + $pConfig->setContactTypeField($row['contact_type'] ?? []); } @@ -347,7 +347,7 @@ private function configureInterest(array $row, DataFormConfigurationInterest $pC $pConfig->setSubject($row['subject']); $pConfig->setCreateInterest((bool)$row['createaddress']); $pConfig->setCheckDuplicateOnCreateAddress($row['checkduplicates']); - $pConfig->setContactTypeField($row['contact_type'] ?? ''); + $pConfig->setContactTypeField($row['contact_type'] ?? []); } diff --git a/plugin/Form/FormAddressCreator.php b/plugin/Form/FormAddressCreator.php index 1fb949b82..cf670075f 100644 --- a/plugin/Form/FormAddressCreator.php +++ b/plugin/Form/FormAddressCreator.php @@ -61,7 +61,7 @@ public function __construct( /** * @param FormData $pFormData * @param bool $mergeExisting - * @param string $contactType + * @param array $contactType * @param int|null $estateId * @return int the new (or updated) address ID * @throws ApiClientException @@ -70,7 +70,7 @@ public function __construct( * @throws NotFoundException */ public function createOrCompleteAddress( - FormData $pFormData, bool $mergeExisting = false, string $contactType = '', int $estateId = null): int + FormData $pFormData, bool $mergeExisting = false, array $contactType = [], int $estateId = null): int { $requestParams = $this->getAddressDataForApiCall($pFormData); $requestParams['checkDuplicate'] = $mergeExisting; diff --git a/plugin/Gui/AdminPageFormSettingsBase.php b/plugin/Gui/AdminPageFormSettingsBase.php index 63296beaf..358d766e2 100644 --- a/plugin/Gui/AdminPageFormSettingsBase.php +++ b/plugin/Gui/AdminPageFormSettingsBase.php @@ -211,6 +211,10 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null) $result = $result && $pRecordManagerUpdateForm->updateFieldConfigByRow ($row[RecordManager::TABLENAME_FIELDCONFIG_FORMS]); } + + if (array_key_exists(RecordManager::TABLENAME_CONTACT_TYPES, $row)) { + $result = $result && $pRecordManagerUpdateForm->updateContactTypeByRow($row[RecordManager::TABLENAME_CONTACT_TYPES]); + } } else { $action = RecordManagerFactory::ACTION_INSERT; // insert @@ -223,6 +227,8 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null) $rowFieldConfig = $this->prepareRelationValues (RecordManager::TABLENAME_FIELDCONFIG_FORMS, 'form_id', $row, $recordId); $row[RecordManager::TABLENAME_FIELDCONFIG_FORMS] = $rowFieldConfig; + $row[RecordManager::TABLENAME_CONTACT_TYPES] = + $this->prepareRelationValues(RecordManager::TABLENAME_CONTACT_TYPES, 'form_id', $row, $recordId); $pRecordManagerInsertForm->insertAdditionalValues($row); $result = true; } catch (RecordManagerInsertException $pException) { @@ -696,6 +702,12 @@ public function doExtraEnqueues() wp_localize_script('oo-sanitize-shortcode-name', 'shortcode', ['name' => 'oopluginforms-name']); wp_enqueue_script('oo-sanitize-shortcode-name'); wp_enqueue_script('oo-copy-shortcode'); + + if ($this->getType() !== Form::TYPE_APPLICANT_SEARCH) { + wp_enqueue_script('select2', plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . 'vendor/select2/select2/dist/js/select2.min.js'); + wp_enqueue_style('select2', plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . 'vendor/select2/select2/dist/css/select2.min.css'); + wp_enqueue_script('onoffice-custom-select', plugins_url('/dist/onoffice-custom-select.min.js', $pluginPath)); + } } diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 3bcfbbd4a..1a72569aa 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -45,7 +45,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 42; + const MAX_VERSION = 43; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -303,6 +303,12 @@ public function install() $dbversion = 42; } + if ($dbversion == 42) { + dbDelta($this->getCreateQueryContactTypes()); + $this->migrateContactTypes(); + $dbversion = 43; + } + $this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true ); } @@ -589,6 +595,44 @@ private function getCreateQuerySortByUserValues() return $sql; } + /** + * @return string + */ + private function getCreateQueryContactTypes() + { + $prefix = $this->getPrefix(); + $charsetCollate = $this->getCharsetCollate(); + $tableName = $prefix."oo_plugin_contacttypes"; + $sql = "CREATE TABLE $tableName ( + `contacttype_id` bigint(20) NOT NULL AUTO_INCREMENT, + `form_id` int(11) NOT NULL, + `contact_type` varchar(100) NOT NULL, + PRIMARY KEY (`contacttype_id`) + ) $charsetCollate;"; + + return $sql; + } + + /** + * @return void + */ + private function migrateContactTypes() + { + $prefix = $this->getPrefix(); + $tableForm = $prefix."oo_plugin_forms"; + $tableContactTypes = $prefix."oo_plugin_contacttypes"; + $contactTypes = $this->_pWPDB->get_results("SELECT form_id, contact_type + FROM $tableForm + WHERE contact_type IS NOT NULL + AND contact_type != '' ", ARRAY_A); + foreach ($contactTypes as $contactType) { + $formId = esc_sql((int) $contactType['form_id']); + $value = esc_sql($contactType['contact_type']); + $this->_pWPDB->insert($tableContactTypes, ['form_id' => $formId, 'contact_type' => $value]); + } + + $this->_pWPDB->get_results("ALTER TABLE $tableForm DROP COLUMN contact_type;"); + } /** * @@ -879,6 +923,7 @@ public function deinstall() $prefix."oo_plugin_fieldconfig_form_translated_labels", $prefix."oo_plugin_fieldconfig_estate_customs_labels", $prefix."oo_plugin_fieldconfig_estate_translated_labels", + $prefix."oo_plugin_contacttypes", ); foreach ($tables as $table) { diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php index 27ee19db0..a06391f41 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php @@ -407,10 +407,14 @@ public function createInputModelContactType() $pInputModelFormContactType = $this->getInputModelDBFactory()->create (InputModelDBFactoryConfigForm::INPUT_FORM_CONTACT_TYPE, $labelContactType); $field = $pInputModelFormContactType->getField(); - $pInputModelFormContactType->setHtmlType(InputModelOption::HTML_TYPE_SELECT); - $availableContactType = array('' => 'No contact type') + $this->getDataContactType(onOfficeSDK::MODULE_ADDRESS); + $pInputModelFormContactType->setHtmlType(InputModelOption::HTML_TYPE_SELECT_TWO); + $availableContactType = $this->getDataContactType(onOfficeSDK::MODULE_ADDRESS); $pInputModelFormContactType->setValuesAvailable($availableContactType); + $pInputModelFormContactType->setIsMulti(true); $selectedValue = $this->getValue($field); + if ($selectedValue == null) { + $selectedValue = []; + } $pInputModelFormContactType->setValue($selectedValue); return $pInputModelFormContactType; diff --git a/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php b/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php index 8e6713b95..f1fe286a1 100644 --- a/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php +++ b/plugin/Model/InputModel/InputModelDBFactoryConfigForm.php @@ -166,7 +166,7 @@ class InputModelDBFactoryConfigForm self::KEY_FIELD => 'show_estate_context', ], self::INPUT_FORM_CONTACT_TYPE => [ - self::KEY_TABLE => 'oo_plugin_forms', + self::KEY_TABLE => 'oo_plugin_contacttypes', self::KEY_FIELD => 'contact_type', ], diff --git a/plugin/Model/InputModelBase.php b/plugin/Model/InputModelBase.php index d1dd7212e..82729b1db 100644 --- a/plugin/Model/InputModelBase.php +++ b/plugin/Model/InputModelBase.php @@ -80,6 +80,9 @@ abstract class InputModelBase /** */ const HTML_SEARCH_FIELD_FOR_FIELD_LISTS = 'searchFieldForFieldLists'; + /** */ + const HTML_TYPE_SELECT_TWO = 'select2'; + /** @var string */ private $_name = null; diff --git a/plugin/Model/InputModelDBAdapterRow.php b/plugin/Model/InputModelDBAdapterRow.php index 8fd8407f1..890f65497 100644 --- a/plugin/Model/InputModelDBAdapterRow.php +++ b/plugin/Model/InputModelDBAdapterRow.php @@ -70,6 +70,11 @@ class InputModelDBAdapterRow 'sortbyvalue_id' => null, 'listview_id' => ['oo_plugin_listviews', 'listview_id'], ], + + 'oo_plugin_contacttypes' => [ + 'contacttype_id' => null, + 'form_id' => ['oo_plugin_forms', 'form_id'], + ], ]; diff --git a/plugin/Record/RecordManager.php b/plugin/Record/RecordManager.php index a186fd575..caad9fb04 100644 --- a/plugin/Record/RecordManager.php +++ b/plugin/Record/RecordManager.php @@ -77,6 +77,9 @@ abstract class RecordManager /** */ const TABLENAME_FIELDCONFIG_ESTATE_TRANSLATED_LABELS = 'oo_plugin_fieldconfig_estate_translated_labels'; + /** */ + const TABLENAME_CONTACT_TYPES = 'oo_plugin_contacttypes'; + /** * * @deprecated get wpdb via DI diff --git a/plugin/Record/RecordManagerDuplicateListViewForm.php b/plugin/Record/RecordManagerDuplicateListViewForm.php index 14097f812..f6a9ba370 100644 --- a/plugin/Record/RecordManagerDuplicateListViewForm.php +++ b/plugin/Record/RecordManagerDuplicateListViewForm.php @@ -163,6 +163,15 @@ public function duplicateByName(string $name) $tableFieldFormTranslatedLabel, 'input_id', 'translated_label_id' ); } } + + $contactTypes = $listViewRoot['contact_type']; + foreach ($contactTypes as $contactType) { + $this->_pWPDB->insert($prefix.'oo_plugin_contacttypes', [ + 'form_id' => esc_sql((int) $duplicateListViewId), + 'contact_type' => esc_sql($contactType) + ] + ); + } } } } diff --git a/plugin/Record/RecordManagerRead.php b/plugin/Record/RecordManagerRead.php index c9ad362ae..4ca78caf3 100644 --- a/plugin/Record/RecordManagerRead.php +++ b/plugin/Record/RecordManagerRead.php @@ -131,10 +131,31 @@ public function getRowById(int $recordId): array WHERE `".esc_sql($this->getIdColumnMain())."` = ".esc_sql((int)$recordId); $result = $pWpDb->get_row($sql, ARRAY_A); + if ($result !== null) { + $result['contact_type'] = $this->readContactTypesByFormId($recordId); + } return $result; } + /** + * @param int $formId + * + * @return array + */ + public function readContactTypesByFormId(int $formId): array + { + $prefix = $this->getTablePrefix(); + $pWpDb = $this->getWpdb(); + $sql = "SELECT `contact_type` + FROM {$prefix}oo_plugin_contacttypes + WHERE `form_id` = ".esc_sql($formId); + + $contactTypes = $pWpDb->get_col($sql); + + return $contactTypes ?? []; + } + /** @return int */ public function getCountOverall(): int diff --git a/plugin/Record/RecordManagerReadForm.php b/plugin/Record/RecordManagerReadForm.php index 5822cc6e3..2d8eb78c8 100644 --- a/plugin/Record/RecordManagerReadForm.php +++ b/plugin/Record/RecordManagerReadForm.php @@ -167,6 +167,9 @@ public function getRowByName($formName) $result['filterable'] = array_keys(array_filter(array_column($resultFieldConfig, 'filterable', 'fieldname'))); $result['hidden'] = array_keys(array_filter(array_column($resultFieldConfig, 'hidden', 'fieldname'))); + $formId = $result['form_id']; + $result['contact_type'] = $this->readContactTypesByFormId($formId); + return $result; } diff --git a/plugin/Record/RecordManagerUpdateForm.php b/plugin/Record/RecordManagerUpdateForm.php index c3eafdc77..87c9ce7dc 100644 --- a/plugin/Record/RecordManagerUpdateForm.php +++ b/plugin/Record/RecordManagerUpdateForm.php @@ -70,4 +70,25 @@ public function updateFieldConfigByRow(array $fieldConfig): bool return $result; } + + /** + * @param array $contactTypes + * + * @return bool + */ + public function updateContactTypeByRow(array $contactTypes): bool + { + $prefix = $this->getTablePrefix(); + $pWpDb = $this->getWpdb(); + $pWpDb->delete($prefix.self::TABLENAME_CONTACT_TYPES, ['form_id' => $this->getRecordId()]); + + $result = true; + foreach ($contactTypes as $row) { + if (is_array($row)) { + $result = $result && $pWpDb->insert($pWpDb->prefix.self::TABLENAME_CONTACT_TYPES, $row); + } + } + + return $result; + } } diff --git a/plugin/Record/RecordStructure.php b/plugin/Record/RecordStructure.php index d751bc05c..4435e2fc2 100644 --- a/plugin/Record/RecordStructure.php +++ b/plugin/Record/RecordStructure.php @@ -199,6 +199,12 @@ class RecordStructure self::EMPTY_VALUE => '', ), ], + RecordManager::TABLENAME_CONTACT_TYPES => array( + 'contact_type' => array( + self::NULL_ALLOWED => false, + self::EMPTY_VALUE => '', + ), + ), ); diff --git a/plugin/Renderer/InputFieldMultipleSelectTwoRenderer.php b/plugin/Renderer/InputFieldMultipleSelectTwoRenderer.php new file mode 100644 index 000000000..731036022 --- /dev/null +++ b/plugin/Renderer/InputFieldMultipleSelectTwoRenderer.php @@ -0,0 +1,47 @@ +getMultiple() ? $this->getName() . '[]' : $this->getName(); + $output = ''; + echo $output; + } + + /** + * @return bool + */ + public function getMultiple(): bool + { return $this->_multiple; } + + /** + * @param bool $multiple + */ + public function setMultiple(bool $multiple) + { $this->_multiple = $multiple; } + +} \ No newline at end of file diff --git a/plugin/Renderer/InputModelRenderer.php b/plugin/Renderer/InputModelRenderer.php index faa390bfe..38bde409a 100644 --- a/plugin/Renderer/InputModelRenderer.php +++ b/plugin/Renderer/InputModelRenderer.php @@ -270,6 +270,13 @@ private function createInputField(InputModelBase $pInputModel, FormModel $pFormM $pInstance->setCheckedValues($pInputModel->getValue()); $pInstance->setOoModule($pFormModel->getOoModule()); break; + + case InputModelOption::HTML_TYPE_SELECT_TWO: + $pInstance = new InputFieldMultipleSelectTwoRenderer($pInputModel->getIdentifier(), $pInputModel->getValuesAvailable()); + $pInstance->addAdditionalAttribute('class', 'select2 custom-multi-select2'); + $pInstance->setMultiple($pInputModel->getIsMulti()); + $pInstance->setSelectedValue($pInputModel->getValue()); + break; } if ($pInstance !== null) { @@ -312,6 +319,7 @@ private function getHtmlElementName(InputModelBase $pInputModel): string case InputModelOption::HTML_TYPE_EMAIL: case InputModelOption::HTML_TYPE_BUTTON_FIELD: case InputModelOption::HTML_SEARCH_FIELD_FOR_FIELD_LISTS: + case InputModelOption::HTML_TYPE_SELECT_TWO: if ($pInputModel->getIsMulti()) { $name .= '[]'; } diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 428b47b08..0f59f2559 100644 --- a/tests/TestClassDatabaseChanges.php +++ b/tests/TestClassDatabaseChanges.php @@ -271,7 +271,7 @@ public function testDeleteMessageFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(42, DatabaseChanges::MAX_VERSION); + $this->assertEquals(43, DatabaseChanges::MAX_VERSION); } diff --git a/tests/TestClassInputFieldMultipleSelectTwoRenderer.php b/tests/TestClassInputFieldMultipleSelectTwoRenderer.php new file mode 100644 index 000000000..b990e35a5 --- /dev/null +++ b/tests/TestClassInputFieldMultipleSelectTwoRenderer.php @@ -0,0 +1,82 @@ +. + * + */ + +declare (strict_types=1); + +namespace onOffice\tests; + +use onOffice\WPlugin\Renderer\InputFieldMultipleSelectTwoRenderer; + +class TestClassInputFieldMultipleSelectTwoRenderer + extends \WP_UnitTestCase +{ + /** + * + */ + public function testRenderWithoutValues() + { + $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); + ob_start(); + $pSubject->setMultiple(true); + $pSubject->render(); + $output = ob_get_clean(); + $this->assertEquals('', $output); + } + + /** + * + */ + public function testRenderWithoutSelectedValue() + { + $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); + $values = [ + 'Owner' => 'Eigentümer', + 'Investor' => 'Investor' + ]; + $pSubject->setValue($values); + ob_start(); + $pSubject->setMultiple(true); + $pSubject->render(); + $output = ob_get_clean(); + $this->assertEquals('', + $output); + } + + /** + * + */ + public function testRenderWithSelectedValues() + { + $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); + $values = [ + 'Owner' => 'Eigentümer', + 'Investor' => 'Investor' + ]; + $pSubject->setValue($values); + $pSubject->setSelectedValue(['Owner']); + ob_start(); + $pSubject->setMultiple(true); + $pSubject->render(); + $output = ob_get_clean(); + $this->assertEquals('', + $output); + } +} \ No newline at end of file diff --git a/tests/TestClassRecordManagerReadForm.php b/tests/TestClassRecordManagerReadForm.php index 2beb84fd8..b93989489 100644 --- a/tests/TestClassRecordManagerReadForm.php +++ b/tests/TestClassRecordManagerReadForm.php @@ -134,6 +134,19 @@ private function getBaseRow(int $formId, string $formType): array ]; } + /** + * @param int $formId + * + * @return array + */ + private function getContactTypesArray(int $formId): array + { + return [ + 'form_id' => $formId, + 'contact_type' => 'Owner' + ]; + } + public function testGetRecords() { $pFieldsForm = $this->_pRecordManagerReadForm->getRecords(); @@ -191,4 +204,16 @@ public function testReadFieldsByFormId() $pFieldsForm = $this->_pRecordManagerReadForm->readFieldsByFormId(1); $this->assertEquals(4, count($pFieldsForm)); } + + /** + * + */ + public function testReadContactTypesByFormId() + { + $this->_pRecordManagerReadForm->method('readContactTypesByFormId')->will($this->returnValueMap([ + [1, $this->getContactTypesArray(1)] + ])); + $pFieldsForm = $this->_pRecordManagerReadForm->readContactTypesByFormId(1); + $this->assertEquals(2, count($pFieldsForm)); + } } From daec1087e136d311b5bbfdfa47cabffcdbe45477 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 12 Mar 2024 16:52:40 +0700 Subject: [PATCH 02/12] 45380 update unit test --- plugin/Installer/DatabaseChanges.php | 15 +++++++++------ tests/TestClassDataFormConfigurationFactory.php | 2 +- tests/TestClassDatabaseChanges.php | 6 +++--- tests/TestClassFormAddressCreator.php | 8 ++++---- tests/TestClassFormModelBuilderDBForm.php | 2 +- tests/TestClassFormPostContact.php | 3 ++- tests/TestClassRecordManagerDuplicateForm.php | 3 ++- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 1a72569aa..10c7b49ae 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -625,13 +625,16 @@ private function migrateContactTypes() FROM $tableForm WHERE contact_type IS NOT NULL AND contact_type != '' ", ARRAY_A); - foreach ($contactTypes as $contactType) { - $formId = esc_sql((int) $contactType['form_id']); - $value = esc_sql($contactType['contact_type']); - $this->_pWPDB->insert($tableContactTypes, ['form_id' => $formId, 'contact_type' => $value]); - } - $this->_pWPDB->get_results("ALTER TABLE $tableForm DROP COLUMN contact_type;"); + if (!is_null($contactTypes)) { + foreach ($contactTypes as $contactType) { + $formId = esc_sql((int) $contactType['form_id']); + $value = esc_sql($contactType['contact_type']); + $this->_pWPDB->insert($tableContactTypes, ['form_id' => $formId, 'contact_type' => $value]); + } + + $this->_pWPDB->get_results("ALTER TABLE $tableForm DROP COLUMN contact_type;"); + } } /** diff --git a/tests/TestClassDataFormConfigurationFactory.php b/tests/TestClassDataFormConfigurationFactory.php index 343f4740d..8da31d882 100644 --- a/tests/TestClassDataFormConfigurationFactory.php +++ b/tests/TestClassDataFormConfigurationFactory.php @@ -443,7 +443,7 @@ private function getBaseRow(int $formId, string $formType): array 'newsletter' => '1', 'availableOptions' => '1', 'show_estate_context' => '0', - 'contact_type' => '', + 'contact_type' => ['Owner', 'Investor'], 'default_recipient' => 'default@my-onoffice.com' ]; } diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 0f59f2559..9c9aeaf67 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(42, $dbversion); + $this->assertEquals(43, $dbversion); return $this->_createQueries; } @@ -202,7 +202,7 @@ public function testDeleteCommentFieldApplicantSearchForm() ->setConstructorArgs(['testUser', 'testPassword', 'testDB', 'testHost']) ->getMock(); - $this->_pWPDBMock->expects($this->exactly(7)) + $this->_pWPDBMock->expects($this->exactly(8)) ->method('get_results') ->willReturnOnConsecutiveCalls($formsOutput, $fieldConfigOutput, $formsOutput, $fieldConfigOutput, $detailPageIds, $listViewOutput, $fieldListViewConfigOutput); @@ -254,7 +254,7 @@ public function testDeleteMessageFieldApplicantSearchForm() ->setConstructorArgs(['testUser', 'testPassword', 'testDB', 'testHost']) ->getMock(); - $this->_pWPDBMock->expects($this->exactly(5)) + $this->_pWPDBMock->expects($this->exactly(6)) ->method('get_results') ->willReturnOnConsecutiveCalls($formsOutput, $fieldConfigOutput, $detailPageIds, $listViewOutput, $fieldListViewConfigOutput); diff --git a/tests/TestClassFormAddressCreator.php b/tests/TestClassFormAddressCreator.php index f3cfa3eaa..4739424b1 100644 --- a/tests/TestClassFormAddressCreator.php +++ b/tests/TestClassFormAddressCreator.php @@ -152,7 +152,7 @@ public function testCreateOrCompleteAddressWithContactType() { $this->configureSDKWrapperMockerForAddressCreationWithContactType(1); $pFormData = $this->createFormData(); - $result = $this->_pSubject->createOrCompleteAddress($pFormData, false, 'Admin'); + $result = $this->_pSubject->createOrCompleteAddress($pFormData, false, ['Admin']); $this->assertEquals(1, $result); } @@ -185,7 +185,7 @@ public function testCreateOrCompleteAddressWithSupervisor() $this->configureSDKWrapperMockerForUserBySupervisorId(3); $pFormData = $this->createFormData(); - $result = $this->_pSubject->createOrCompleteAddress($pFormData, false, 'Admin', 1); + $result = $this->_pSubject->createOrCompleteAddress($pFormData, false, ['Admin'], 1); $this->assertEquals(1, $result); } @@ -331,7 +331,7 @@ private function addCreateAddressResponseToSKDWrapperWithContactType(array $resp 'testaddressfield1varchar' => 'testValue', 'testaddressfield1multiselect' => ['hut','tut'], 'checkDuplicate' => false, - 'ArtDaten' => 'Admin' + 'ArtDaten' => ['Admin'] ], null, $response); } @@ -341,7 +341,7 @@ private function addCreateAddressResponseToSKDWrapperWithSupervisor(array $respo 'testaddressfield1varchar' => 'testValue', 'testaddressfield1multiselect' => ['hut','tut'], 'checkDuplicate' => false, - 'ArtDaten' => 'Admin', + 'ArtDaten' => ['Admin'], "Benutzer" => "testUserName" ], null, $response); } diff --git a/tests/TestClassFormModelBuilderDBForm.php b/tests/TestClassFormModelBuilderDBForm.php index 01aaf4082..48e9092ef 100644 --- a/tests/TestClassFormModelBuilderDBForm.php +++ b/tests/TestClassFormModelBuilderDBForm.php @@ -200,7 +200,7 @@ public function testCreateInputModelContactType() $pInputModelDB = $pInstance->createInputModelContactType(); $this->assertInstanceOf(InputModelDB::class, $pInputModelDB); - $this->assertEquals($pInputModelDB->getHtmlType(), 'select'); + $this->assertEquals($pInputModelDB->getHtmlType(), 'select2'); } /** diff --git a/tests/TestClassFormPostContact.php b/tests/TestClassFormPostContact.php index 59b2364a6..a26e5cb30 100644 --- a/tests/TestClassFormPostContact.php +++ b/tests/TestClassFormPostContact.php @@ -313,6 +313,7 @@ private function configureSDKWrapperForCreateAddressWithDuplicateCheck() 'phone' => '0815/2345677', 'AGB_akzeptiert' => true, 'checkDuplicate' => false, + 'ArtDaten' => ['Owner', 'Customer'], ]; $responseJson = file_get_contents @@ -518,7 +519,7 @@ private function getNewDataFormConfiguration(): DataFormConfigurationContact $pDataFormConfiguration->setFormName('contactForm'); $pDataFormConfiguration->setSubject('¡A new Contact!'); $pDataFormConfiguration->setRequiredFields(['Vorname', 'Name', 'Email']); - $pDataFormConfiguration->setContactTypeField(''); + $pDataFormConfiguration->setContactTypeField(['Owner', 'Customer']); $this->mockNewsletterCall(); return $pDataFormConfiguration; diff --git a/tests/TestClassRecordManagerDuplicateForm.php b/tests/TestClassRecordManagerDuplicateForm.php index e5cf8d11c..998cf0f8d 100644 --- a/tests/TestClassRecordManagerDuplicateForm.php +++ b/tests/TestClassRecordManagerDuplicateForm.php @@ -90,7 +90,8 @@ public function prepare() ], 'filterable' => [], 'hidden' => [], - 'availableOptions' => [] + 'availableOptions' => [], + 'contact_type' => ['Owner'] ]; $this->_pWPDB = $this->getMockBuilder(wpdb::class) From 273680e03f421336c460873767d717d83151f2e9 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 12 Mar 2024 17:33:19 +0700 Subject: [PATCH 03/12] 45380 update logic migrate contact types --- plugin/Installer/DatabaseChanges.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 10c7b49ae..23d5807fc 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -626,7 +626,7 @@ private function migrateContactTypes() WHERE contact_type IS NOT NULL AND contact_type != '' ", ARRAY_A); - if (!is_null($contactTypes)) { + if (count($contactTypes)) { foreach ($contactTypes as $contactType) { $formId = esc_sql((int) $contactType['form_id']); $value = esc_sql($contactType['contact_type']); From 83ac889f2d9afdde6fc93bd39092895bf82179b6 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 12 Mar 2024 18:14:20 +0700 Subject: [PATCH 04/12] 45380 update unit test --- plugin/Installer/DatabaseChanges.php | 4 +--- tests/TestClassInputFieldMultipleSelectTwoRenderer.php | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 23d5807fc..c53bf1f3b 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -626,14 +626,12 @@ private function migrateContactTypes() WHERE contact_type IS NOT NULL AND contact_type != '' ", ARRAY_A); - if (count($contactTypes)) { + if (!empty($contactTypes) && is_array($contactTypes)) { foreach ($contactTypes as $contactType) { $formId = esc_sql((int) $contactType['form_id']); $value = esc_sql($contactType['contact_type']); $this->_pWPDB->insert($tableContactTypes, ['form_id' => $formId, 'contact_type' => $value]); } - - $this->_pWPDB->get_results("ALTER TABLE $tableForm DROP COLUMN contact_type;"); } } diff --git a/tests/TestClassInputFieldMultipleSelectTwoRenderer.php b/tests/TestClassInputFieldMultipleSelectTwoRenderer.php index b990e35a5..89ae0d107 100644 --- a/tests/TestClassInputFieldMultipleSelectTwoRenderer.php +++ b/tests/TestClassInputFieldMultipleSelectTwoRenderer.php @@ -38,7 +38,7 @@ public function testRenderWithoutValues() $pSubject->setMultiple(true); $pSubject->render(); $output = ob_get_clean(); - $this->assertEquals('', $output); + $this->assertEquals('', $output); } /** @@ -56,7 +56,7 @@ public function testRenderWithoutSelectedValue() $pSubject->setMultiple(true); $pSubject->render(); $output = ob_get_clean(); - $this->assertEquals('', + $this->assertEquals('', $output); } @@ -76,7 +76,7 @@ public function testRenderWithSelectedValues() $pSubject->setMultiple(true); $pSubject->render(); $output = ob_get_clean(); - $this->assertEquals('', + $this->assertEquals('', $output); } } \ No newline at end of file From 27d56c86f406c663b374218517fea2464be81eef Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 12 Mar 2024 18:23:28 +0700 Subject: [PATCH 05/12] 45380 refactor code --- plugin/Record/RecordManagerRead.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/Record/RecordManagerRead.php b/plugin/Record/RecordManagerRead.php index 4ca78caf3..df49921c7 100644 --- a/plugin/Record/RecordManagerRead.php +++ b/plugin/Record/RecordManagerRead.php @@ -152,8 +152,13 @@ public function readContactTypesByFormId(int $formId): array WHERE `form_id` = ".esc_sql($formId); $contactTypes = $pWpDb->get_col($sql); + $result = array(); - return $contactTypes ?? []; + if (is_array($contactTypes)) { + $result = $contactTypes; + } + + return $result; } From 14315cdb1e107608099e7bdaac3bad525dee8294 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Fri, 22 Mar 2024 14:39:41 +0700 Subject: [PATCH 06/12] 45380 refactor code --- plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php | 2 +- plugin/Record/RecordManagerRead.php | 7 +------ plugin/Record/RecordManagerReadForm.php | 3 +-- plugin/Record/RecordManagerUpdateForm.php | 6 ++++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php index a06391f41..309cbde9e 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php @@ -412,7 +412,7 @@ public function createInputModelContactType() $pInputModelFormContactType->setValuesAvailable($availableContactType); $pInputModelFormContactType->setIsMulti(true); $selectedValue = $this->getValue($field); - if ($selectedValue == null) { + if (is_null($selectedValue)) { $selectedValue = []; } $pInputModelFormContactType->setValue($selectedValue); diff --git a/plugin/Record/RecordManagerRead.php b/plugin/Record/RecordManagerRead.php index df49921c7..9c90a6f6d 100644 --- a/plugin/Record/RecordManagerRead.php +++ b/plugin/Record/RecordManagerRead.php @@ -152,13 +152,8 @@ public function readContactTypesByFormId(int $formId): array WHERE `form_id` = ".esc_sql($formId); $contactTypes = $pWpDb->get_col($sql); - $result = array(); - if (is_array($contactTypes)) { - $result = $contactTypes; - } - - return $result; + return is_array($contactTypes) ? $contactTypes : []; } diff --git a/plugin/Record/RecordManagerReadForm.php b/plugin/Record/RecordManagerReadForm.php index 2d8eb78c8..e4ce2d852 100644 --- a/plugin/Record/RecordManagerReadForm.php +++ b/plugin/Record/RecordManagerReadForm.php @@ -167,8 +167,7 @@ public function getRowByName($formName) $result['filterable'] = array_keys(array_filter(array_column($resultFieldConfig, 'filterable', 'fieldname'))); $result['hidden'] = array_keys(array_filter(array_column($resultFieldConfig, 'hidden', 'fieldname'))); - $formId = $result['form_id']; - $result['contact_type'] = $this->readContactTypesByFormId($formId); + $result['contact_type'] = $this->readContactTypesByFormId($result['form_id']); return $result; } diff --git a/plugin/Record/RecordManagerUpdateForm.php b/plugin/Record/RecordManagerUpdateForm.php index 87c9ce7dc..05d84360f 100644 --- a/plugin/Record/RecordManagerUpdateForm.php +++ b/plugin/Record/RecordManagerUpdateForm.php @@ -84,9 +84,11 @@ public function updateContactTypeByRow(array $contactTypes): bool $result = true; foreach ($contactTypes as $row) { - if (is_array($row)) { - $result = $result && $pWpDb->insert($pWpDb->prefix.self::TABLENAME_CONTACT_TYPES, $row); + if (empty($row)) { + continue; } + + $result = $result && $pWpDb->insert($pWpDb->prefix.self::TABLENAME_CONTACT_TYPES, $row); } return $result; From 4b36dbab4eba29aae7f70751a276b6cd6b803984 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Thu, 16 May 2024 17:32:42 +0700 Subject: [PATCH 07/12] 45380 update unit test --- tests/TestClassDatabaseChanges.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 9c9aeaf67..39778f7f7 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(43, $dbversion); + $this->assertEquals(44, $dbversion); return $this->_createQueries; } @@ -271,7 +271,7 @@ public function testDeleteMessageFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(43, DatabaseChanges::MAX_VERSION); + $this->assertEquals(44, DatabaseChanges::MAX_VERSION); } From 63e454d30f2679425e26339e16e97ced5879dfee Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Fri, 17 May 2024 13:21:59 +0700 Subject: [PATCH 08/12] 45380 fix conflict --- css/admin.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/css/admin.css b/css/admin.css index 3ef138574..f5659dc8b 100644 --- a/css/admin.css +++ b/css/admin.css @@ -537,6 +537,11 @@ body #post-head-content p.wp-clearfix:nth-child(1) { min-height: 30px; } +.select2-dropdown.select2-dropdown--below, +.select2-dropdown.select2-dropdown--above { + margin-top: 0 !important; +} + .oo-poststuff .custom-input-field input[name=oopluginlistviews-countryactive]:checked::before, .oo-poststuff .custom-input-field input[name=oopluginlistviews-radiusactive]:checked::before { filter: brightness(0) saturate(100%) invert(35%) sepia(4%) saturate(967%) hue-rotate(170deg) brightness(91%) contrast(94%); From eb871b9d7d19a9cf16d2f3ec920de6f9ae022cdb Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Thu, 6 Jun 2024 17:35:32 +0700 Subject: [PATCH 09/12] 45380 remove input field renderer --- ...assInputFieldMultipleSelectTwoRenderer.php | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 tests/TestClassInputFieldMultipleSelectTwoRenderer.php diff --git a/tests/TestClassInputFieldMultipleSelectTwoRenderer.php b/tests/TestClassInputFieldMultipleSelectTwoRenderer.php deleted file mode 100644 index 89ae0d107..000000000 --- a/tests/TestClassInputFieldMultipleSelectTwoRenderer.php +++ /dev/null @@ -1,82 +0,0 @@ -. - * - */ - -declare (strict_types=1); - -namespace onOffice\tests; - -use onOffice\WPlugin\Renderer\InputFieldMultipleSelectTwoRenderer; - -class TestClassInputFieldMultipleSelectTwoRenderer - extends \WP_UnitTestCase -{ - /** - * - */ - public function testRenderWithoutValues() - { - $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); - ob_start(); - $pSubject->setMultiple(true); - $pSubject->render(); - $output = ob_get_clean(); - $this->assertEquals('', $output); - } - - /** - * - */ - public function testRenderWithoutSelectedValue() - { - $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); - $values = [ - 'Owner' => 'Eigentümer', - 'Investor' => 'Investor' - ]; - $pSubject->setValue($values); - ob_start(); - $pSubject->setMultiple(true); - $pSubject->render(); - $output = ob_get_clean(); - $this->assertEquals('', - $output); - } - - /** - * - */ - public function testRenderWithSelectedValues() - { - $pSubject = new InputFieldMultipleSelectTwoRenderer('multiSelect2'); - $values = [ - 'Owner' => 'Eigentümer', - 'Investor' => 'Investor' - ]; - $pSubject->setValue($values); - $pSubject->setSelectedValue(['Owner']); - ob_start(); - $pSubject->setMultiple(true); - $pSubject->render(); - $output = ob_get_clean(); - $this->assertEquals('', - $output); - } -} \ No newline at end of file From c197abcbe757e6761e1a1978414629f0ee7f59c9 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Wed, 24 Jul 2024 11:36:59 +0700 Subject: [PATCH 10/12] 45380 update unit test --- tests/TestClassDatabaseChanges.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index 4976f6d47..2e58a0c4c 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(44, $dbversion); + $this->assertEquals(45, $dbversion); return $this->_createQueries; } From 8c865897c0a6bf087b6c2a89dc49948e86caeca6 Mon Sep 17 00:00:00 2001 From: andernath Date: Thu, 15 Aug 2024 09:13:36 +0200 Subject: [PATCH 11/12] Small refactoring for unused styling and readability #4116037 --- css/admin.css | 5 ----- dist/onoffice-custom-select.min.js | 2 +- js/onoffice-custom-select.js | 6 ++++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/css/admin.css b/css/admin.css index 165af0b73..d6bb7d6d9 100644 --- a/css/admin.css +++ b/css/admin.css @@ -527,11 +527,6 @@ body #post-head-content p.wp-clearfix:nth-child(1) { color: #999; } -.select2-dropdown.select2-dropdown--below, -.select2-dropdown.select2-dropdown--above { - margin-top: 0 !important; -} - .oo-poststuff .custom-input-field input[name=oopluginlistviews-countryactive]:checked::before, .oo-poststuff .custom-input-field input[name=oopluginlistviews-radiusactive]:checked::before { filter: brightness(0) saturate(100%) invert(35%) sepia(4%) saturate(967%) hue-rotate(170deg) brightness(91%) contrast(94%); diff --git a/dist/onoffice-custom-select.min.js b/dist/onoffice-custom-select.min.js index 6a5a9dcdd..4a2eac933 100644 --- a/dist/onoffice-custom-select.min.js +++ b/dist/onoffice-custom-select.min.js @@ -1 +1 @@ -const custom_select2=typeof custom_select2_translation!=="undefined"?custom_select2_translation:{};jQuery(document).ready((function($){const $multiSelectAdminSorting=$("#viewrecordssorting .oo-custom-select2.oo-custom-select2--multiple");const $singleSelectAdminSorting=$("#viewrecordssorting .oo-custom-select2.oo-custom-select2--single");$(".custom-multiple-select, .custom-single-select").select2({width:"100%"});if($(".oo-poststuff .custom-input-field .oo-custom-select2").length>0){$(".oo-poststuff .custom-input-field .oo-custom-select2").select2({width:"50%"})}if($multiSelectAdminSorting.length){$multiSelectAdminSorting.select2({placeholder:custom_select2.multipleSelectOptions,width:"50%"})}if($singleSelectAdminSorting.length){$singleSelectAdminSorting.select2({placeholder:custom_select2.singleSelectOption,width:"50%"})}})); \ No newline at end of file +const custom_select2=typeof custom_select2_translation!=="undefined"?custom_select2_translation:{};jQuery(document).ready((function($){const $adminSelect=$(".oo-poststuff .custom-input-field .oo-custom-select2");const $multiSelectAdminSorting=$("#viewrecordssorting .oo-custom-select2.oo-custom-select2--multiple");const $singleSelectAdminSorting=$("#viewrecordssorting .oo-custom-select2.oo-custom-select2--single");$(".custom-multiple-select, .custom-single-select").select2({width:"100%"});if($adminSelect.length>0){$adminSelect.select2({width:"50%"})}if($multiSelectAdminSorting.length){$multiSelectAdminSorting.select2({placeholder:custom_select2.multipleSelectOptions,width:"50%"})}if($singleSelectAdminSorting.length){$singleSelectAdminSorting.select2({placeholder:custom_select2.singleSelectOption,width:"50%"})}})); \ No newline at end of file diff --git a/js/onoffice-custom-select.js b/js/onoffice-custom-select.js index e896d0aea..4202bf2e9 100644 --- a/js/onoffice-custom-select.js +++ b/js/onoffice-custom-select.js @@ -1,13 +1,15 @@ const custom_select2 = (typeof custom_select2_translation !== 'undefined') ? custom_select2_translation : {}; jQuery(document).ready(function ($) { + const $adminSelect = $('.oo-poststuff .custom-input-field .oo-custom-select2'); const $multiSelectAdminSorting = $('#viewrecordssorting .oo-custom-select2.oo-custom-select2--multiple'); const $singleSelectAdminSorting = $("#viewrecordssorting .oo-custom-select2.oo-custom-select2--single"); $('.custom-multiple-select, .custom-single-select').select2({ width: '100%' }); - if ($('.oo-poststuff .custom-input-field .oo-custom-select2').length > 0) { - $('.oo-poststuff .custom-input-field .oo-custom-select2').select2({ + + if ($adminSelect.length > 0) { + $adminSelect.select2({ width: '50%' }); } From 6819a5e781278bc5279a41fa9e982525eeb1ad33 Mon Sep 17 00:00:00 2001 From: andernath Date: Thu, 15 Aug 2024 09:49:42 +0200 Subject: [PATCH 12/12] Remove unused select2 call #4116037 --- dist/admin.min.js | 2 +- js/admin.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/dist/admin.min.js b/dist/admin.min.js index 86758ae19..5baf20298 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)}));if($(".custom-multi-select2").length>0){$(".custom-multi-select2").select2()}$(".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");const data=$("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",1);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$(this).parent().parent().remove()}));$(".oo-search-field .input-search").on("input",(function(){let filter=$(this).val().toUpperCase();let clearIcon=$(".clear-icon");if($(this).val().trim()!==""){clearIcon.removeClass("dashicons-search").addClass("dashicons-no-alt")}else{clearIcon.removeClass("dashicons-no-alt").addClass("dashicons-search")}$(".oo-search-field .field-lists .search-field-item").each((function(){let dataLabel=$(this).data("label").toUpperCase();let dataKey=$(this).data("key").toUpperCase();let dataContent=$(this).data("content").toUpperCase();if(dataLabel.indexOf(filter)>-1||dataKey.indexOf(filter)>-1||dataContent.indexOf(filter)>-1){$(this).show()}else{$(this).hide()}}))})).on("keypress",(function(event){if(event.which==13){event.preventDefault()}}));$(document).on("click",(function(event){let $fieldLists=$(".oo-search-field .field-lists");let $inputSearch=$(".oo-search-field .input-search");if(!$(event.target).closest($fieldLists).length&&event.target!==$inputSearch[0]){$fieldLists.hide()}}));$(".oo-search-field .input-search").on("click",(function(event){event.stopPropagation();$(".field-lists").show()}));$(".oo-search-field #clear-input").on("click",(function(){$(".input-search").val("").trigger("input")}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");const valElLabel=$(btn).attr("data-onoffice-label");var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-insert").addClass("dashicons-remove").attr("typeField",removeField);parentItem.find(".check-action").addClass("action-remove");parentItem.find(".field-item-detail").css("opacity","0.5")}));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=[];const actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",addField);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$("*#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(fieldName==="DSGVOStatus"||fieldName==="AGB_akzeptiert"||fieldName==="gdprcheckbox"){var selectors=["oopluginformfieldconfig-hiddenfield"];var hiddenField=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");hiddenField.parent().remove()}if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(fieldName!=="ort"){const selectors=["oopluginfieldconfig-convertTextToSelectForCityField"];let convertTextToSelectForCityField=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");convertTextToSelectForCityField.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");const data=$("."+labelButtonHandleField);if(data===null){$(this).parent().parent().remove();return}$(data).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",1);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$(this).parent().parent().remove()}));$(".oo-search-field .input-search").on("input",(function(){let filter=$(this).val().toUpperCase();let clearIcon=$(".clear-icon");if($(this).val().trim()!==""){clearIcon.removeClass("dashicons-search").addClass("dashicons-no-alt")}else{clearIcon.removeClass("dashicons-no-alt").addClass("dashicons-search")}$(".oo-search-field .field-lists .search-field-item").each((function(){let dataLabel=$(this).data("label").toUpperCase();let dataKey=$(this).data("key").toUpperCase();let dataContent=$(this).data("content").toUpperCase();if(dataLabel.indexOf(filter)>-1||dataKey.indexOf(filter)>-1||dataContent.indexOf(filter)>-1){$(this).show()}else{$(this).hide()}}))})).on("keypress",(function(event){if(event.which==13){event.preventDefault()}}));$(document).on("click",(function(event){let $fieldLists=$(".oo-search-field .field-lists");let $inputSearch=$(".oo-search-field .input-search");if(!$(event.target).closest($fieldLists).length&&event.target!==$inputSearch[0]){$fieldLists.hide()}}));$(".oo-search-field .input-search").on("click",(function(event){event.stopPropagation();$(".field-lists").show()}));$(".oo-search-field #clear-input").on("click",(function(){$(".input-search").val("").trigger("input")}));var getCheckedFieldButton=function(btn){var addField=1;var removeField=2;var checkTypeField=$(btn).children().attr("typeField");if(checkTypeField==addField){var label=$(btn).attr("data-action-div");var valElName=$(btn).attr("value");const valElLabel=$(btn).attr("data-onoffice-label");var category=$(btn).attr("data-onoffice-category");var module=$(btn).attr("data-onoffice-module");var actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-insert").addClass("dashicons-remove").attr("typeField",removeField);parentItem.find(".check-action").addClass("action-remove");parentItem.find(".field-item-detail").css("opacity","0.5")}));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=[];const actionFieldName="labelButtonHandleField-"+valElName;$("."+actionFieldName).each((function(){const parentItem=$(this);parentItem.find(".dashicons").removeClass("dashicons-remove").addClass("dashicons-insert").attr("typeField",addField);parentItem.find(".check-action").removeClass("action-remove");parentItem.find(".field-item-detail").css("opacity","1")}));$("*#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(fieldName==="DSGVOStatus"||fieldName==="AGB_akzeptiert"||fieldName==="gdprcheckbox"){var selectors=["oopluginformfieldconfig-hiddenfield"];var hiddenField=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");hiddenField.parent().remove()}if(!optionsAvailable){var selectors=["oopluginformfieldconfig-availableOptions","oopluginfieldconfig-availableOptions"];var availableOptionEl=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");availableOptionEl.parent().remove()}if(fieldName!=="ort"){const selectors=["oopluginfieldconfig-convertTextToSelectForCityField"];let convertTextToSelectForCityField=clonedElement.find("input[name^="+selectors.join("],input[name^=")+"]");convertTextToSelectForCityField.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 f45e72422..4fede5e8d 100644 --- a/js/admin.js +++ b/js/admin.js @@ -45,10 +45,6 @@ jQuery(document).ready(function($){ getCheckedFieldButton(this); }); - if ($('.custom-multi-select2').length > 0) { - $('.custom-multi-select2').select2(); - } - $('.item-edit').click(function() { $(this).parent().parent().parent().parent().find('.menu-item-settings').toggle(); });