diff --git a/css/admin.css b/css/admin.css index 0d3cc7f77..65966417a 100644 --- a/css/admin.css +++ b/css/admin.css @@ -568,4 +568,19 @@ body #post-body-content p.wp-clearfix:nth-child(1){ .oo-poststuff .key-of-field-block { display: flex; +} + +.oo-poststuff .custom-input-field .onoffice-input-radio { + border-radius: 4px; + width: 50%; + display: grid; + float: left; + justify-content: initial; + border: 1px solid #8c8f94; +} + +.oo-poststuff .custom-input-field .onoffice-input-radio label { + display: flex; + justify-content: space-between; + margin: 10px; } \ No newline at end of file diff --git a/dist/onoffice-default-form-values.min.js b/dist/onoffice-default-form-values.min.js index ea9e45987..504eb5ff6 100644 --- a/dist/onoffice-default-form-values.min.js +++ b/dist/onoffice-default-form-values.min.js @@ -1 +1 @@ -onOffice=onOffice||{};onOffice.default_values_inputs_converted=onOffice.default_values_inputs_converted||[];if(window.NodeList&&!NodeList.prototype.forEach){NodeList.prototype.forEach=Array.prototype.forEach}onOffice.default_values_input_converter=function(){var predefinedValues=onOffice_loc_settings.defaultvalues||{};document.querySelectorAll("select[name=language-language].onoffice-input").forEach((function(element){element.backupLanguageSelection={};var mainInput=element.parentElement.parentElement.querySelector("input[name^=oopluginfieldconfigformdefaultsvalues-value].onoffice-input");var fieldname=element.parentElement.parentElement.parentElement.querySelector("span.menu-item-settings-name").textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldname)!==-1){return}onOffice.default_values_inputs_converted.push(fieldname);mainInput.name="defaultvalue-lang["+fieldname+"][native]";(function(){if(predefinedValues[fieldname]!==undefined){var predefinedValuesIsObject=typeof predefinedValues[fieldname]==="object"&&!Array.isArray(predefinedValues[fieldname]);if(predefinedValuesIsObject){for(var lang in predefinedValues[fieldname]){var relevantOption=element.querySelector("option[value="+lang+"]");if(lang!=="native"){var clone=generateClone(mainInput,lang);var label=generateLabel(relevantOption.text||"",clone);var deleteButton=generateDeleteButton(element,lang);var paragraph=generateParagraph(label,clone,deleteButton);mainInput.parentNode.parentNode.insertBefore(paragraph,element.parentNode);element.backupLanguageSelection[lang]=relevantOption;element.options[relevantOption.index]=null}var targetInput=element.parentElement.parentElement.querySelector('input[name="defaultvalue-lang['+fieldname+"]["+lang+']"]');targetInput.value=predefinedValues[fieldname][lang]}}}})();element.addEventListener("change",(function(event){var value=event.srcElement.value||"";if(value!==""){var clone=generateClone(mainInput,value);var label=generateLabel(event.srcElement.selectedOptions[0].text,clone);var deleteButton=generateDeleteButton(event.srcElement,value);var paragraph=generateParagraph(label,clone,deleteButton);element.backupLanguageSelection[event.srcElement.selectedOptions[0].value]=event.srcElement.selectedOptions[0];event.srcElement.options[event.srcElement.selectedIndex]=null;mainInput.parentNode.parentNode.insertBefore(paragraph,event.srcElement.parentNode)}}));function generateClone(mainInput,language){var clone=mainInput.cloneNode(true);clone.id="defaultvalue-lang-"+language;clone.name="defaultvalue-lang["+fieldname+"]["+language+"]";clone.style.marginLeft="20px";clone.value="";return clone}function generateLabel(labelText,clone){var label=document.createElement("label");label.classList=["howto"];label.htmlFor=clone.id;label.style.minWidth="min-content";label.textContent=onOffice_loc_settings.label_default_value.replace("%s",labelText);return label}function generateDeleteButton(srcElement,language){var deleteButton=document.createElement("span");deleteButton.id="deleteButtonLang-"+language;deleteButton.className="dashicons dashicons-dismiss deleteButtonLang";deleteButton.targetLanguage=language;deleteButton.style.display="block";deleteButton.style.verticalAlign="middle";deleteButton.addEventListener("click",(function(deleteEvent){var restoreValue=element.backupLanguageSelection[deleteEvent.srcElement.targetLanguage];srcElement.options.add(restoreValue);srcElement.selectedIndex=0;deleteEvent.srcElement.parentElement.remove()}));return deleteButton}function generateParagraph(label,clone,deleteButton){var paragraph=document.createElement("p");paragraph.classList=["wp-clearfix custom-input-field custom-label-language"];paragraph.appendChild(label);paragraph.appendChild(clone);paragraph.appendChild(deleteButton);return paragraph}}));document.querySelectorAll("select[name^=oopluginfieldconfigformdefaultsvalues-value]").forEach((function(mainInput){var mainElement=mainInput.parentElement.parentElement.querySelector("span.menu-item-settings-name");if(mainElement===null){return}var fieldName=mainElement.textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldName)!==-1){return}onOffice.default_values_inputs_converted.push(fieldName);mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";var predefinedValuesIsArray=typeof predefinedValues[fieldName]==="object"&&Array.isArray(predefinedValues[fieldName]);if(predefinedValuesIsArray){mainInput.value=predefinedValues[fieldName][0]}var fieldList=onOffice_loc_settings.fieldList||{};var fieldDefinition=getFieldDefinition(fieldName);for(var module in fieldList){if(fieldList[module][fieldName]!==undefined){fieldDefinition=fieldList[module][fieldName]}}if(fieldDefinition.type==="multiselect"){var parent=mainInput.parentElement;mainInput.remove();var div=document.createElement("div");div.setAttribute("data-name","oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][]");div.classList.add("multiselect");var button=document.createElement("input");button.setAttribute("type","button");button.setAttribute("value",onOffice_loc_settings.field_multiselect_edit_values);button.classList.add("onoffice-multiselect-edit");div.appendChild(button);parent.appendChild(div);var multiselectOptions={name_is_array:true,cb_class:"onoffice-input"};var multiselect=new onOffice.multiselect(div,fieldDefinition.permittedvalues,onOffice_loc_settings.defaultvalues[fieldName]||[],multiselectOptions);button.onclick=function(multiselect){return function(){multiselect.show()}}(multiselect)}else if(fieldDefinition.type==="boolean"){mainInput.innerHTML="";mainInput.options.add(new Option(fieldDefinition.permittedvalues[0],"0"));mainInput.options.add(new Option(fieldDefinition.permittedvalues[1],"1"));mainInput.selectedIndex=onOffice_loc_settings.defaultvalues[fieldName]||"0"}}));document.querySelectorAll("input[name^=oopluginfieldconfigformdefaultsvalues-value]").forEach((function(mainInput){var mainElement=mainInput.parentElement.parentElement.querySelector("span.menu-item-settings-name");if(mainElement===null){return}var fieldName=mainElement.textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldName)!==-1||fieldName==="dummy_key"){return}onOffice.default_values_inputs_converted.push(fieldName);var fieldDefinition=getFieldDefinition(fieldName);if(!fieldDefinition.rangefield&&["integer","float","date","datetime","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:float","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:int","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:integer","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal"].indexOf(fieldDefinition.type)>=0){if(fieldDefinition.type==="date"||fieldDefinition.type==="datetime"){mainInput.setAttribute("type","text")}mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";mainInput.value=predefinedValues[fieldName][0]||"";return}mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][min]";var mainInputClone=mainInput.cloneNode(true);mainInputClone.id="input_js_"+onOffice.js_field_count;onOffice.js_field_count+=1;var labelFrom=mainInput.parentElement.querySelector("label[for="+mainInput.id+"]");var labelUpTo=labelFrom.cloneNode(true);labelUpTo.htmlFor=mainInputClone.id;labelFrom.textContent=onOffice_loc_settings.label_default_value_from;labelUpTo.textContent=onOffice_loc_settings.label_default_value_up_to;mainInputClone.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][max]";mainInput.parentElement.appendChild(labelUpTo);mainInput.parentElement.appendChild(mainInputClone);mainInput.parentElement.classList.add("custom-from-to-input");var predefinedValuesIsObject=typeof predefinedValues[fieldName]==="object"&&!Array.isArray(predefinedValues[fieldName]);if(predefinedValuesIsObject){mainInput.value=predefinedValues[fieldName]["min"]||"";mainInputClone.value=predefinedValues[fieldName]["max"]||""}}))};onOffice.js_field_count=onOffice.js_field_count||0;document.addEventListener("addFieldItem",(function(e){var fieldName=e.detail.fieldname;var p=document.createElement("p");p.classList.add("wp-clearfix","custom-input-field","custom-label-language");var fieldDefinition=getFieldDefinition(fieldName);if(["varchar","text","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:varchar","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:Text"].indexOf(fieldDefinition.type)>=0){var select=document.createElement("select");select.id="select_js_"+onOffice.js_field_count;select.name="language-language";select.className="onoffice-input";select.options.add(new Option(onOffice_loc_settings.label_choose_language,""));var keys=Object.keys(onOffice_loc_settings.installed_wp_languages);keys.forEach((function(k){var v=onOffice_loc_settings.installed_wp_languages[k];if(k===onOffice_loc_settings.language_native){k="native"}select.options.add(new Option(v,k))}));onOffice.js_field_count+=1;select.options.selectedIndex=0;var label=document.createElement("label");label.htmlFor=select.id;label.className="howto";label.textContent=onOffice_loc_settings.label_add_language;p.appendChild(label);p.appendChild(select)}else if(["singleselect","multiselect","boolean"].indexOf(fieldDefinition.type)>=0){var element=e.detail.item.querySelector("input[name^=oopluginfieldconfigformdefaultsvalues-value]");var select=document.createElement("select");select.id="select_js_"+onOffice.js_field_count;select.name="oopluginfieldconfigformdefaultsvalues-value[]";select.className="onoffice-input";select.options.add(new Option("",""));var keys=Object.keys(fieldDefinition.permittedvalues);keys.forEach((function(k){var v=fieldDefinition.permittedvalues[k];if(fieldDefinition.labelOnlyValues.indexOf(k)!==-1){var group=document.createElement("optgroup");group.label=v;select.options.add(group)}else{select.options.add(new Option(v,k));if(k===fieldDefinition.selectedvalue){select.selectedIndex=select.options.length-1}}}));onOffice.js_field_count+=1;select.options.selectedIndex=0;element.parentNode.replaceChild(select,element)}var paragraph=e.detail.item.querySelectorAll(".menu-item-settings p")[2];paragraph.parentNode.insertBefore(p,paragraph.nextSibling);var index=onOffice.default_values_inputs_converted.indexOf(fieldName);if(index!==-1){delete onOffice.default_values_inputs_converted[index]}onOffice.default_values_input_converter()}));function getFieldDefinition(fieldName){var fieldList=onOffice_loc_settings.fieldList||{};for(var module in fieldList){if(fieldList[module][fieldName]!==undefined){return fieldList[module][fieldName]}}return{}}onOffice.default_values_input_converter(); \ No newline at end of file +onOffice=onOffice||{};onOffice.default_values_inputs_converted=onOffice.default_values_inputs_converted||[];if(window.NodeList&&!NodeList.prototype.forEach){NodeList.prototype.forEach=Array.prototype.forEach}onOffice.default_values_input_converter=function(){var predefinedValues=onOffice_loc_settings.defaultvalues||{};document.querySelectorAll("select[name=language-language].onoffice-input").forEach((function(element){element.backupLanguageSelection={};var mainInput=element.parentElement.parentElement.querySelector("input[name^=oopluginfieldconfigformdefaultsvalues-value].onoffice-input");var fieldname=element.parentElement.parentElement.parentElement.querySelector("span.menu-item-settings-name").textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldname)!==-1){return}onOffice.default_values_inputs_converted.push(fieldname);mainInput.name="defaultvalue-lang["+fieldname+"][native]";(function(){if(predefinedValues[fieldname]!==undefined){var predefinedValuesIsObject=typeof predefinedValues[fieldname]==="object"&&!Array.isArray(predefinedValues[fieldname]);if(predefinedValuesIsObject){for(var lang in predefinedValues[fieldname]){var relevantOption=element.querySelector("option[value="+lang+"]");if(lang!=="native"){var clone=generateClone(mainInput,lang);var label=generateLabel(relevantOption.text||"",clone);var deleteButton=generateDeleteButton(element,lang);var paragraph=generateParagraph(label,clone,deleteButton);mainInput.parentNode.parentNode.insertBefore(paragraph,element.parentNode);element.backupLanguageSelection[lang]=relevantOption;element.options[relevantOption.index]=null}var targetInput=element.parentElement.parentElement.querySelector('input[name="defaultvalue-lang['+fieldname+"]["+lang+']"]');targetInput.value=predefinedValues[fieldname][lang]}}}})();element.addEventListener("change",(function(event){var value=event.srcElement.value||"";if(value!==""){var clone=generateClone(mainInput,value);var label=generateLabel(event.srcElement.selectedOptions[0].text,clone);var deleteButton=generateDeleteButton(event.srcElement,value);var paragraph=generateParagraph(label,clone,deleteButton);element.backupLanguageSelection[event.srcElement.selectedOptions[0].value]=event.srcElement.selectedOptions[0];event.srcElement.options[event.srcElement.selectedIndex]=null;mainInput.parentNode.parentNode.insertBefore(paragraph,event.srcElement.parentNode)}}));function generateClone(mainInput,language){var clone=mainInput.cloneNode(true);clone.id="defaultvalue-lang-"+language;clone.name="defaultvalue-lang["+fieldname+"]["+language+"]";clone.style.marginLeft="20px";clone.value="";return clone}function generateLabel(labelText,clone){var label=document.createElement("label");label.classList=["howto"];label.htmlFor=clone.id;label.style.minWidth="min-content";label.textContent=onOffice_loc_settings.label_default_value.replace("%s",labelText);return label}function generateDeleteButton(srcElement,language){var deleteButton=document.createElement("span");deleteButton.id="deleteButtonLang-"+language;deleteButton.className="dashicons dashicons-dismiss deleteButtonLang";deleteButton.targetLanguage=language;deleteButton.style.display="block";deleteButton.style.verticalAlign="middle";deleteButton.addEventListener("click",(function(deleteEvent){var restoreValue=element.backupLanguageSelection[deleteEvent.srcElement.targetLanguage];srcElement.options.add(restoreValue);srcElement.selectedIndex=0;deleteEvent.srcElement.parentElement.remove()}));return deleteButton}function generateParagraph(label,clone,deleteButton){var paragraph=document.createElement("p");paragraph.classList=["wp-clearfix custom-input-field custom-label-language"];paragraph.appendChild(label);paragraph.appendChild(clone);paragraph.appendChild(deleteButton);return paragraph}}));document.querySelectorAll("select[name^=oopluginfieldconfigformdefaultsvalues-value]").forEach((function(mainInput){var mainElement=mainInput.parentElement.parentElement.querySelector("span.menu-item-settings-name");if(mainElement===null){return}var fieldName=mainElement.textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldName)!==-1){return}onOffice.default_values_inputs_converted.push(fieldName);mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";var predefinedValuesIsArray=typeof predefinedValues[fieldName]==="object"&&Array.isArray(predefinedValues[fieldName]);if(predefinedValuesIsArray){mainInput.value=predefinedValues[fieldName][0]}var fieldList=onOffice_loc_settings.fieldList||{};var fieldDefinition=getFieldDefinition(fieldName);for(var module in fieldList){if(fieldList[module][fieldName]!==undefined){fieldDefinition=fieldList[module][fieldName]}}if(fieldDefinition.type==="multiselect"){var parent=mainInput.parentElement;mainInput.remove();var div=document.createElement("div");div.setAttribute("data-name","oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][]");div.classList.add("multiselect");var button=document.createElement("input");button.setAttribute("type","button");button.setAttribute("value",onOffice_loc_settings.field_multiselect_edit_values);button.classList.add("onoffice-multiselect-edit");div.appendChild(button);parent.appendChild(div);var multiselectOptions={name_is_array:true,cb_class:"onoffice-input"};var multiselect=new onOffice.multiselect(div,fieldDefinition.permittedvalues,onOffice_loc_settings.defaultvalues[fieldName]||[],multiselectOptions);button.onclick=function(multiselect){return function(){multiselect.show()}}(multiselect)}else if(fieldDefinition.type==="boolean"){mainInput.innerHTML="";mainInput.options.add(new Option(fieldDefinition.permittedvalues[0],"0"));mainInput.options.add(new Option(fieldDefinition.permittedvalues[1],"1"));mainInput.selectedIndex=onOffice_loc_settings.defaultvalues[fieldName]||"0"}}));document.querySelectorAll("input[name^=oopluginfieldconfigformdefaultsvalues-value]").forEach((function(mainInput){var mainElement=mainInput.parentElement.parentElement.querySelector("span.menu-item-settings-name");if(mainElement===null){return}var fieldName=mainElement.textContent;if(onOffice.default_values_inputs_converted.indexOf(fieldName)!==-1||fieldName==="dummy_key"){return}onOffice.default_values_inputs_converted.push(fieldName);var fieldDefinition=getFieldDefinition(fieldName);if(fieldDefinition.type==="urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint"){const parent=mainInput;const element=document.createElement("fieldset");const keys=Object.keys(fieldDefinition.permittedvalues).sort();parent.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";element.className="onoffice-input-radio";keys.forEach((k=>{const mainInputClone=parent.cloneNode(true);const label=document.createElement("label");onOffice.js_field_count+=1;mainInputClone.id="input_radio_js_"+onOffice.js_field_count;mainInputClone.value=k;label.textContent=fieldDefinition.permittedvalues[k];if(k==onOffice_loc_settings.defaultvalues[fieldName]){mainInputClone.checked=true}label.appendChild(mainInputClone);element.appendChild(label);parent.parentElement.appendChild(element)}));const labels=parent.parentElement.getElementsByTagName("label")[1];parent.parentElement.removeChild(labels);mainInput.remove();return}if(!fieldDefinition.rangefield&&["integer","float","date","datetime","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:float","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:int","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:integer","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint"].indexOf(fieldDefinition.type)>=0){if(fieldDefinition.type==="date"||fieldDefinition.type==="urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date"){mainInput.setAttribute("type","date")}if(fieldDefinition.type==="datetime"){mainInput.setAttribute("type","datetime-local");mainInput.setAttribute("step",1)}mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";mainInput.value=predefinedValues[fieldName][0]||"";return}mainInput.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][min]";var mainInputClone=mainInput.cloneNode(true);mainInputClone.id="input_js_"+onOffice.js_field_count;onOffice.js_field_count+=1;var labelFrom=mainInput.parentElement.querySelector("label[for="+mainInput.id+"]");var labelUpTo=labelFrom.cloneNode(true);labelUpTo.htmlFor=mainInputClone.id;labelFrom.textContent=onOffice_loc_settings.label_default_value_from;labelUpTo.textContent=onOffice_loc_settings.label_default_value_up_to;mainInputClone.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"][max]";mainInput.parentElement.appendChild(labelUpTo);mainInput.parentElement.appendChild(mainInputClone);mainInput.parentElement.classList.add("custom-from-to-input");var predefinedValuesIsObject=typeof predefinedValues[fieldName]==="object"&&!Array.isArray(predefinedValues[fieldName]);if(predefinedValuesIsObject){mainInput.value=predefinedValues[fieldName]["min"]||"";mainInputClone.value=predefinedValues[fieldName]["max"]||""}}))};onOffice.js_field_count=onOffice.js_field_count||0;document.addEventListener("addFieldItem",(function(e){var fieldName=e.detail.fieldname;var p=document.createElement("p");p.classList.add("wp-clearfix","custom-input-field","custom-label-language");var fieldDefinition=getFieldDefinition(fieldName);if(["varchar","text","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:varchar","urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:Text"].indexOf(fieldDefinition.type)>=0){var select=document.createElement("select");select.id="select_js_"+onOffice.js_field_count;select.name="language-language";select.className="onoffice-input";select.options.add(new Option(onOffice_loc_settings.label_choose_language,""));var keys=Object.keys(onOffice_loc_settings.installed_wp_languages);keys.forEach((function(k){var v=onOffice_loc_settings.installed_wp_languages[k];if(k===onOffice_loc_settings.language_native){k="native"}select.options.add(new Option(v,k))}));onOffice.js_field_count+=1;select.options.selectedIndex=0;var label=document.createElement("label");label.htmlFor=select.id;label.className="howto";label.textContent=onOffice_loc_settings.label_add_language;p.appendChild(label);p.appendChild(select)}else if(["singleselect","multiselect","boolean"].indexOf(fieldDefinition.type)>=0){var element=e.detail.item.querySelector("input[name^=oopluginfieldconfigformdefaultsvalues-value]");var select=document.createElement("select");select.id="select_js_"+onOffice.js_field_count;select.name="oopluginfieldconfigformdefaultsvalues-value[]";select.className="onoffice-input";select.options.add(new Option("",""));var keys=Object.keys(fieldDefinition.permittedvalues);keys.forEach((function(k){var v=fieldDefinition.permittedvalues[k];if(fieldDefinition.labelOnlyValues.indexOf(k)!==-1){var group=document.createElement("optgroup");group.label=v;select.options.add(group)}else{select.options.add(new Option(v,k));if(k===fieldDefinition.selectedvalue){select.selectedIndex=select.options.length-1}}}));onOffice.js_field_count+=1;select.options.selectedIndex=0;element.parentNode.replaceChild(select,element)}else if(["urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint"].indexOf(fieldDefinition.type)>=0){const element=e.detail.item.querySelector("input[name^=oopluginfieldconfigformdefaultsvalues-value]");const fieldset=document.createElement("fieldset");const keys=Object.keys(fieldDefinition.permittedvalues).sort();fieldset.className="onoffice-input-radio";keys.forEach((function(k){const label=document.createElement("label");const input=document.createElement("input");input.name="oopluginfieldconfigformdefaultsvalues-value["+fieldName+"]";input.type="radio";input.value=k;input.className="onoffice-input";onOffice.js_field_count+=1;label.htmlFor="input_radio_js_"+onOffice.js_field_count;label.textContent=fieldDefinition.permittedvalues[k];if(k==onOffice_loc_settings.defaultvalues[fieldName]){input.checked=true}label.appendChild(input);fieldset.appendChild(label)}));element.parentNode.replaceChild(fieldset,element)}var paragraph=e.detail.item.querySelectorAll(".menu-item-settings p")[2];paragraph.parentNode.insertBefore(p,paragraph.nextSibling);var index=onOffice.default_values_inputs_converted.indexOf(fieldName);if(index!==-1){delete onOffice.default_values_inputs_converted[index]}onOffice.default_values_input_converter()}));function getFieldDefinition(fieldName){var fieldList=onOffice_loc_settings.fieldList||{};for(var module in fieldList){if(fieldList[module][fieldName]!==undefined){return fieldList[module][fieldName]}}return{}}onOffice.default_values_input_converter(); \ No newline at end of file diff --git a/js/onoffice-default-form-values.js b/js/onoffice-default-form-values.js index 989b90bea..163a60a9a 100644 --- a/js/onoffice-default-form-values.js +++ b/js/onoffice-default-form-values.js @@ -186,16 +186,49 @@ onOffice.default_values_input_converter = function () { onOffice.default_values_inputs_converted.push(fieldName); var fieldDefinition = getFieldDefinition(fieldName); + if (fieldDefinition.type === "urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint") { + const parent = mainInput; + const element = document.createElement('fieldset'); + const keys = Object.keys(fieldDefinition.permittedvalues).sort(); + parent.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']'; + + element.className = 'onoffice-input-radio'; + keys.forEach(k => { + const mainInputClone = parent.cloneNode(true); + const label = document.createElement('label'); + onOffice.js_field_count += 1; + mainInputClone.id = 'input_radio_js_' + onOffice.js_field_count; + mainInputClone.value = k; + label.textContent = fieldDefinition.permittedvalues[k]; + if (k == onOffice_loc_settings.defaultvalues[fieldName]) { + mainInputClone.checked = true; + } + label.appendChild(mainInputClone); + element.appendChild(label); + parent.parentElement.appendChild(element); + }); + const labels = parent.parentElement.getElementsByTagName('label')[1]; + parent.parentElement.removeChild(labels); + mainInput.remove(); + return; + } + if (!fieldDefinition.rangefield && [ 'integer', 'float', 'date', 'datetime', 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:float', 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:int', 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:integer', - 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal' + 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal', + 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date', + 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint' ].indexOf(fieldDefinition.type) >= 0) { - if (fieldDefinition.type === 'date' || fieldDefinition.type === 'datetime') { - mainInput.setAttribute('type', 'text'); + if (fieldDefinition.type === 'date' || fieldDefinition.type === 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date') { + mainInput.setAttribute('type', 'date'); + } + if (fieldDefinition.type === 'datetime') { + mainInput.setAttribute('type', 'datetime-local'); + mainInput.setAttribute('step', 1); } mainInput.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']'; mainInput.value = predefinedValues[fieldName][0] || ''; @@ -286,6 +319,29 @@ document.addEventListener("addFieldItem", function(e) { onOffice.js_field_count += 1; select.options.selectedIndex = 0; element.parentNode.replaceChild(select, element); + } else if (['urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'].indexOf(fieldDefinition.type) >= 0) { + const element = e.detail.item.querySelector('input[name^=oopluginfieldconfigformdefaultsvalues-value]'); + const fieldset = document.createElement('fieldset'); + const keys = Object.keys(fieldDefinition.permittedvalues).sort(); + fieldset.className = 'onoffice-input-radio'; + keys.forEach(function (k) { + const label = document.createElement('label'); + const input = document.createElement('input'); + input.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']'; + input.type = 'radio'; + input.value = k; + input.className = 'onoffice-input'; + onOffice.js_field_count += 1; + label.htmlFor = 'input_radio_js_' + onOffice.js_field_count; + label.textContent = fieldDefinition.permittedvalues[k]; + if(k == onOffice_loc_settings.defaultvalues[fieldName]){ + input.checked = true; + } + label.appendChild(input); + fieldset.appendChild(label); + }); + + element.parentNode.replaceChild(fieldset, element); } var paragraph = e.detail.item.querySelectorAll('.menu-item-settings p')[2]; diff --git a/plugin/Field/Collection/FieldLoaderSupervisorValues.php b/plugin/Field/Collection/FieldLoaderSupervisorValues.php new file mode 100644 index 000000000..e354c4e0e --- /dev/null +++ b/plugin/Field/Collection/FieldLoaderSupervisorValues.php @@ -0,0 +1,117 @@ +_pSDKWrapper = $_pSDKWrapper; + } + + /** + * @throws ApiClientException + */ + public function load(): Generator + { + $fullNameSupervisor = $this->getFullNameSupervisor(); + $supervisorElementsRecord = $this->getSupervisorField(); + + if (empty($supervisorElementsRecord)) { + return; + } + + foreach ($supervisorElementsRecord as $fieldName => $fieldProperties) { + if ($fieldName === 'benutzer') { + $fieldProperties['type'] = FieldTypes::FIELD_TYPE_SINGLESELECT; + $fieldProperties['module'] = onOfficeSDK::MODULE_SEARCHCRITERIA; + $fieldProperties['permittedvalues'] = $fullNameSupervisor; + $fieldProperties['content'] = __('Search Criteria', 'onoffice-for-wp-websites'); + yield $fieldName => $fieldProperties; + } + } + } + + + /** + * @return array + * @throws ApiClientException + */ + private function getSupervisorField(): array + { + $parametersGetFieldList = [ + 'labels' => true, + 'showContent' => true, + 'showTable' => true, + 'fieldList' => ['benutzer'], + 'language' => Language::getDefault(), + 'modules' => [onOfficeSDK::MODULE_ESTATE], + 'realDataTypes' => true + ]; + + $pApiClientActionFields = new APIClientActionGeneric + ($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'fields'); + $pApiClientActionFields->setParameters($parametersGetFieldList); + $pApiClientActionFields->addRequestToQueue()->sendRequests(); + $result = $pApiClientActionFields->getResultRecords(); + + if (empty($result[0]['elements'])) { + return []; + } + + return $result[0]['elements']; + } + + /** + * @return array + * @throws ApiClientException + */ + private function getFullNameSupervisor(): array + { + $pApiClientAction = new APIClientActionGeneric + ($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'users'); + + $pApiClientAction->addRequestToQueue(); + $this->_pSDKWrapper->sendRequests(); + $result = $pApiClientAction->getResultRecords(); + $fullNameSupervisor = []; + + if (empty($result)) { + return []; + } + + foreach ($result as $value) { + $fullName = ''; + $firstName = $value['elements']['firstname']; + $lastName = $value['elements']['lastname']; + $userName = $value['elements']['username']; + + if (!empty($firstName) && !empty($lastName)) { + $fullName = $lastName . ', ' . $firstName; + } else { + if (!empty($firstName) && empty($lastName)) { + $fullName = $firstName; + } elseif (empty($firstName) && !empty($lastName)) { + $fullName = $lastName; + } else { + $fullName = '(' .$userName . ')'; + } + } + + $fullNameSupervisor[$value['elements']['id']] = $fullName; + } + + return $fullNameSupervisor; + } +} \ No newline at end of file diff --git a/plugin/Field/Collection/FieldsCollectionBuilderShort.php b/plugin/Field/Collection/FieldsCollectionBuilderShort.php index 208f4bb47..61375fcd4 100644 --- a/plugin/Field/Collection/FieldsCollectionBuilderShort.php +++ b/plugin/Field/Collection/FieldsCollectionBuilderShort.php @@ -280,4 +280,22 @@ public function addFieldsEstateGeoPositionFrontend(FieldsCollection $pFieldsColl $pFieldsCollection->merge($pFieldsCollectionTmp); return $this; } + + /** + * @param FieldsCollection $pFieldsCollection + * @return $this + * @throws DependencyException + * @throws NotFoundException + */ + public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCollection): self + { + if (!$pFieldsCollection->containsFieldByModule(onOfficeSDK::MODULE_SEARCHCRITERIA, 'benutzer')) { + return $this; + }; + $pFieldLoader = $this->_pContainer->get(FieldLoaderSupervisorValues::class); + $pFieldCollectionSupervisor = $this->_pContainer->get(FieldsCollectionBuilder::class) + ->buildFieldsCollection($pFieldLoader); + $pFieldsCollection->merge($pFieldCollectionSupervisor); + return $this; + } } diff --git a/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueModelToOutputConverter.php b/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueModelToOutputConverter.php index 6b11ef864..36fa5c7e1 100644 --- a/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueModelToOutputConverter.php +++ b/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueModelToOutputConverter.php @@ -90,6 +90,8 @@ public function getConvertedMultiFields(int $formId, array $pFields): array case FieldTypes::isDateOrDateTime($pField->getType()): case FieldTypes::isNumericType($pField->getType()): case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT: + case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT: + case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE: $pDataModel = $this->convertGeneric($formId, $pField, $rowData); $pDataModels[ $pField->getName() ] = $pDataModel[0] ?? ''; break; @@ -139,6 +141,8 @@ public function getConvertedMultiFieldsForAdmin(int $formId, array $pFields): ar case FieldTypes::isDateOrDateTime($pField->getType()): case FieldTypes::isNumericType($pField->getType()): case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT: + case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT: + case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE: $pDataModel = $this->convertGeneric($formId, $pField, $rowData); break; case $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT; @@ -194,7 +198,16 @@ private function convertGeneric(int $formId, Field $pField, array $rows): array { $pDataModel = new DefaultValueModelSingleselect($formId, $pField); $pDataModel->setDefaultsId(isset($rows[0]->defaults_id) ? (int) $rows[0]->defaults_id : 0); - $pDataModel->setValue($rows[0]->value ?? ''); + + if ($pField->getType() === FieldTypes::FIELD_TYPE_DATE || $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE) { + $formattedDate = date_i18n('Y-m-d', strtotime($rows[0]->value ?? '')); + $pDataModel->setValue($formattedDate); + } elseif ($pField->getType() === FieldTypes::FIELD_TYPE_DATETIME) { + $formattedDate = date_i18n('Y-m-d H:i:s', strtotime($rows[0]->value ?? '')); + $pDataModel->setValue($formattedDate); + } else { + $pDataModel->setValue($rows[0]->value ?? ''); + } $pConverter = $this->_pOutputConverterFactory->createForSingleSelect(); return $pConverter->convertToRow($pDataModel); diff --git a/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueRowSaver.php b/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueRowSaver.php index 21eeaad8f..8739d43bd 100644 --- a/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueRowSaver.php +++ b/plugin/Field/DefaultValue/ModelToOutputConverter/DefaultValueRowSaver.php @@ -88,7 +88,9 @@ private function saveForFoundType(int $formId, Field $pField, $values) { $isSingleValue = FieldTypes::isDateOrDateTime($pField->getType()) || FieldTypes::isNumericType($pField->getType()) || - $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT; + $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT || + $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT || + $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE; $isMultiSelect = $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT; $isBoolean = $pField->getType() === FieldTypes::FIELD_TYPE_BOOLEAN; $isStringType = FieldTypes::isStringType($pField->getType()); diff --git a/plugin/Field/OutputFields.php b/plugin/Field/OutputFields.php index 8773319a7..cdb512522 100644 --- a/plugin/Field/OutputFields.php +++ b/plugin/Field/OutputFields.php @@ -76,7 +76,11 @@ public function getVisibleFilterableFields( $allFields = array_merge($fieldsArray, array_keys($geoFields)); $valuesDefault = array_map(function($field) use ($geoFields, $pInputVariableReader) { - return $pInputVariableReader->getFieldValueFormatted($field) ?: $geoFields[$field] ?? null; + $fieldValue = $pInputVariableReader->getFieldValueFormatted($field); + if ($fieldValue === false) { + return false; + } + return $fieldValue ?: $geoFields[$field] ?? null; }, $allFields); $resultDefault = array_combine($allFields, $valuesDefault); diff --git a/plugin/Field/SearchcriteriaFields.php b/plugin/Field/SearchcriteriaFields.php index 6f3be262a..f40e64024 100644 --- a/plugin/Field/SearchcriteriaFields.php +++ b/plugin/Field/SearchcriteriaFields.php @@ -101,7 +101,8 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn $pFieldsCollection = new FieldsCollection(); $this->_pFieldsCollectionBuilder ->addFieldsSearchCriteria($pFieldsCollection) - ->addFieldsAddressEstate($pFieldsCollection); + ->addFieldsAddressEstate($pFieldsCollection) + ->addFieldSupervisorForSearchCriteria($pFieldsCollection); $pGeoFieldsCollection = new FieldModuleCollectionDecoratorGeoPositionFrontend(new FieldsCollection); $pFieldsCollection->merge($pGeoFieldsCollection); @@ -116,6 +117,9 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn $aliasedFieldName = $geoRangeFields[$name]; } $module = onOfficeSDK::MODULE_ESTATE; + if ($name === 'benutzer') { + $module = onOfficeSDK::MODULE_SEARCHCRITERIA; + } $pField = $pFieldsCollection->getFieldByModuleAndName($module, $aliasedFieldName); if ($name === 'regionaler_zusatz') { $pField = $pFieldsCollection->getFieldByModuleAndName($listDataInputs[$name], $aliasedFieldName); @@ -141,6 +145,14 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn else { $output[$pField->getLabel()] = (array_key_exists($value, $pField->getPermittedvalues()) ? $pField->getPermittedvalues()[$value] : $value); } + } elseif (FieldTypes::FIELD_TYPE_DATATYPE_TINYINT === $pField->getType() || FieldTypes::FIELD_TYPE_BOOLEAN === $pField->getType()) { + if ($value === '') { + $output[$pField->getLabel()] = __('Not Special', 'onoffice-for-wp-websites'); + } elseif ($value === '0') { + $output[$pField->getLabel()] = __('No', 'onoffice-for-wp-websites'); + } elseif ($value === '1') { + $output[$pField->getLabel()] = __('Yes', 'onoffice-for-wp-websites'); + } } else { $output[$pField->getLabel()] = $value; } diff --git a/plugin/Form.php b/plugin/Form.php index 2a373b5a8..692150b29 100644 --- a/plugin/Form.php +++ b/plugin/Form.php @@ -112,6 +112,10 @@ public function __construct(string $formName, string $type, Container $pContaine ->addCustomLabelFieldsFormFrontend($pFieldsCollection, $formName) ->addFieldsAddressEstateWithRegionValues($pFieldsCollection); + if ($type === self::TYPE_INTEREST || $type === self::TYPE_APPLICANT_SEARCH) { + $pFieldBuilderShort->addFieldSupervisorForSearchCriteria($pFieldsCollection); + } + $pFormPost = FormPostHandler::getInstance($type); FormPost::incrementFormNo(); $this->_formNo = $pFormPost->getFormNo(); @@ -559,7 +563,10 @@ private function getDefaultValues(): array $pDefaultFields = $pDefaultValueRead->getConvertedMultiFields($formId, $fields); if (count($pDefaultFields)) $values = array_merge($values, $pDefaultFields); } - return array_filter($values); + + return array_filter($values, function($value) { + return ($value === "0" || !empty($value)); + }); } /** diff --git a/plugin/Gui/AdminPageFormSettingsBase.php b/plugin/Gui/AdminPageFormSettingsBase.php index 7b18b6f04..5b12940b1 100644 --- a/plugin/Gui/AdminPageFormSettingsBase.php +++ b/plugin/Gui/AdminPageFormSettingsBase.php @@ -357,6 +357,12 @@ private function getFieldList(): array '0' => __('No', 'onoffice-for-wp-websites'), '1' => __('Yes', 'onoffice-for-wp-websites'), ]; + } elseif ($pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT) { + $result[ $pField->getModule() ][ $pField->getName() ]['permittedvalues'] = [ + '' => __('Not Specified', 'onoffice-for-wp-websites'), + '0' => __('No', 'onoffice-for-wp-websites'), + '1' => __('Yes', 'onoffice-for-wp-websites'), + ]; } } return $result; @@ -511,7 +517,8 @@ private function buildFieldsCollectionForCurrentForm(): FieldsCollection if (in_array(onOfficeSDK::MODULE_SEARCHCRITERIA, $modules)) { $pFieldsCollectionBuilder ->addFieldsSearchCriteria($pDefaultFieldsCollection) - ->addFieldsSearchCriteriaSpecificBackend($pDefaultFieldsCollection); + ->addFieldsSearchCriteriaSpecificBackend($pDefaultFieldsCollection) + ->addFieldSupervisorForSearchCriteria($pDefaultFieldsCollection); } $pFieldsCollectionBuilder->addFieldsFormBackend($pDefaultFieldsCollection,$this->getType()); diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php index 34e258f7a..95f0d3929 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php @@ -156,6 +156,11 @@ private function getFieldsCollection(): FieldsCollection ->addFieldsAddressEstate($pFieldsCollection) ->addFieldsSearchCriteria($pFieldsCollection) ->addFieldsFormBackend($pFieldsCollection,$this->getFormType()); + + if ($this->getFormType() === Form::TYPE_INTEREST || $this->getFormType() === Form::TYPE_APPLICANT_SEARCH) { + $pFieldsCollectionBuilder->addFieldSupervisorForSearchCriteria($pFieldsCollection); + } + return $pFieldsCollection; } diff --git a/plugin/Model/InputModelBuilder/InputModelBuilderDefaultValue.php b/plugin/Model/InputModelBuilder/InputModelBuilderDefaultValue.php index 77f6b264a..6227f7cfe 100644 --- a/plugin/Model/InputModelBuilder/InputModelBuilderDefaultValue.php +++ b/plugin/Model/InputModelBuilder/InputModelBuilderDefaultValue.php @@ -46,6 +46,7 @@ class InputModelBuilderDefaultValue FieldTypes::FIELD_TYPE_MULTISELECT => InputModelOption::HTML_TYPE_SELECT, FieldTypes::FIELD_TYPE_SINGLESELECT => InputModelOption::HTML_TYPE_SELECT, FieldTypes::FIELD_TYPE_BOOLEAN => InputModelOption::HTML_TYPE_SELECT, + FieldTypes::FIELD_TYPE_DATATYPE_TINYINT => InputModelOption::HTML_TYPE_RADIO ]; diff --git a/plugin/Types/FieldTypes.php b/plugin/Types/FieldTypes.php index f36bab307..8052f05b6 100644 --- a/plugin/Types/FieldTypes.php +++ b/plugin/Types/FieldTypes.php @@ -58,6 +58,15 @@ abstract class FieldTypes /** */ const FIELD_TYPE_DATETIME = 'datetime'; + /** */ + const FIELD_TYPE_DATATYPE_TINYINT = 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'; + + /** */ + const FIELD_TYPE_DATATYPE_DATE = 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date'; + + /** */ + const FIELD_TYPE_DATATYPE_USER = 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:User'; + /** @var array */ const TYPES_STRING = [ self::FIELD_TYPE_TEXT, @@ -78,6 +87,9 @@ abstract class FieldTypes self::FIELD_TYPE_DATE => FILTER_SANITIZE_STRING, self::FIELD_TYPE_BLOB => FILTER_UNSAFE_RAW, self::FIELD_TYPE_DATETIME => FILTER_SANITIZE_STRING, + self::FIELD_TYPE_DATATYPE_USER => FILTER_SANITIZE_STRING, + self::FIELD_TYPE_DATATYPE_TINYINT => FILTER_VALIDATE_INT, + self::FIELD_TYPE_DATATYPE_DATE => FILTER_SANITIZE_STRING ]; /** @var array */ diff --git a/templates.dist/fields.php b/templates.dist/fields.php index 85a001725..6630d60ca 100644 --- a/templates.dist/fields.php +++ b/templates.dist/fields.php @@ -190,6 +190,15 @@ function renderFormField(string $fieldName, onOffice\WPlugin\Form $pForm, bool $ $typeCurrentInput === 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal' ) { $inputType = 'type="number" step="1" '; + } elseif ( + $typeCurrentInput === FieldTypes::FIELD_TYPE_DATE || + $typeCurrentInput === FieldTypes::FIELD_TYPE_DATATYPE_DATE + ) { + $inputType = 'type="date" '; + } elseif ( + $typeCurrentInput === FieldTypes::FIELD_TYPE_DATETIME + ) { + $inputType = 'type="datetime-local" step="1" '; } if ( @@ -202,6 +211,18 @@ function renderFormField(string $fieldName, onOffice\WPlugin\Form $pForm, bool $ $output .= ''; } + } elseif ($typeCurrentInput === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT) { + $output = '
+ + + + + + +
'; } else { $output .= ''; } diff --git a/tests/TestClassFieldLoaderSupervisorValues.php b/tests/TestClassFieldLoaderSupervisorValues.php new file mode 100644 index 000000000..1145904da --- /dev/null +++ b/tests/TestClassFieldLoaderSupervisorValues.php @@ -0,0 +1,72 @@ + true, + 'showContent' => true, + 'showTable' => true, + 'fieldList' => ['benutzer'], + 'language' => Language::getDefault(), + 'modules' => [onOfficeSDK::MODULE_ESTATE], + 'realDataTypes' => true + ]; + + $pSDKWrapper = new SDKWrapperMocker(); + $responseSupervisorFieldJson = file_get_contents(__DIR__ . '/resources/ApiResponseSupervisorFields.json'); + $responseSupervisorField = json_decode($responseSupervisorFieldJson, true); + $pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'fields', '', + $parametersGetFieldList, null, $responseSupervisorField); + $responseListSupervisorsJson = file_get_contents(__DIR__ . '/resources/ApiResponseListSupervisors.json'); + $responseListSupervisors = json_decode($responseListSupervisorsJson, true); + $pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'users', '', + [], null, $responseListSupervisors); + + $this->_pFieldLoader = new FieldLoaderSupervisorValues($pSDKWrapper); + } + + /* + * + */ + public function testLoadFieldSupervisor() + { + $result = iterator_to_array($this->_pFieldLoader->load()); + $expectation = [ + "benutzer" => [ + "type" => FieldTypes::FIELD_TYPE_SINGLESELECT, + "length" => null, + "permittedvalues" => [ + 69 => 'aa, aa', + 45 => 'Test first name', + 42 => 'Test last name', + 30 => '(Test Username)' + ], + "default" => null, + "label" => 'Supervisor', + "tablename" => 'ObjTech', + "content" => __('Search Criteria', 'onoffice-for-wp-websites'), + "module" => onOfficeSDK::MODULE_SEARCHCRITERIA, + ] + ]; + + $this->assertCount(1, $result); + $this->assertEquals($expectation, $result); + } +} \ No newline at end of file diff --git a/tests/TestClassFieldsCollectionBuilderShort.php b/tests/TestClassFieldsCollectionBuilderShort.php index a0c2045c7..2d45013ed 100644 --- a/tests/TestClassFieldsCollectionBuilderShort.php +++ b/tests/TestClassFieldsCollectionBuilderShort.php @@ -36,6 +36,7 @@ use onOffice\WPlugin\Region\RegionController; use onOffice\WPlugin\SDKWrapper; use onOffice\WPlugin\Types\FieldsCollection; +use onOffice\WPlugin\Types\Field; use WP_UnitTestCase; use function json_decode; @@ -121,6 +122,26 @@ public function prepare() (file_get_contents(__DIR__.'/resources/ApiResponseGetSearchcriteriaFieldsENG.json'), true); $pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'searchCriteriaFields', '', $searchCriteriaFieldsParameters, null, $responseGetSearchcriteriaFields); + + $parametersGetFieldList = [ + 'labels' => true, + 'showContent' => true, + 'showTable' => true, + 'fieldList' => ['benutzer'], + 'language' => 'ENG', + 'modules' => [onOfficeSDK::MODULE_ESTATE], + 'realDataTypes' => true + ]; + + $responseGetSupervisorFields = json_decode + (file_get_contents(__DIR__.'/resources/ApiResponseSupervisorFields.json'), true); + $pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'fields', '', + $parametersGetFieldList, null, $responseGetSupervisorFields); + + $responseGetListSupervisors = json_decode + (file_get_contents(__DIR__.'/resources/ApiResponseListSupervisors.json'), true); + $pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'users', '', + [], null, $responseGetListSupervisors); $pRegionController = $this->getMockBuilder(RegionController::class) ->disableOriginalConstructor() ->getMock(); @@ -223,4 +244,18 @@ public function testCombination() ->addFieldsSearchCriteriaSpecificBackend($pFieldsCollection); $this->assertCount(30, $pFieldsCollection->getAllFields()); } + + /** + * + * @covers onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort::addFieldSupervisorForSearchCriteria + * + */ + public function testAddFieldSupervisorForSearchCriteria() + { + $pFieldsCollection = new FieldsCollection(); + $field = new Field('benutzer', onOfficeSDK::MODULE_SEARCHCRITERIA, 'testLabel'); + $pFieldsCollection->addField($field); + $this->assertSame($this->_pSubject, $this->_pSubject->addFieldSupervisorForSearchCriteria($pFieldsCollection)); + $this->assertCount(2, $pFieldsCollection->getAllFields()); + } } diff --git a/tests/TestClassFormPostInterest.php b/tests/TestClassFormPostInterest.php index ecb6b8b5e..dab3d675d 100644 --- a/tests/TestClassFormPostInterest.php +++ b/tests/TestClassFormPostInterest.php @@ -112,7 +112,7 @@ public function prepare() ])); $this->_pFieldsCollectionBuilderShort = $this->getMockBuilder(FieldsCollectionBuilderShort::class) - ->setMethods(['addFieldsAddressEstate', 'addFieldsSearchCriteria', 'addFieldsFormFrontend']) + ->setMethods(['addFieldsAddressEstate', 'addFieldsSearchCriteria', 'addFieldsFormFrontend', 'addFieldSupervisorForSearchCriteria']) ->setConstructorArgs([new Container]) ->getMock(); diff --git a/tests/TestClassFormPostOwner.php b/tests/TestClassFormPostOwner.php index ff39ae2bf..0a1579421 100644 --- a/tests/TestClassFormPostOwner.php +++ b/tests/TestClassFormPostOwner.php @@ -128,6 +128,7 @@ public function prepare() $pFieldEnergieausweistyp = new Field('energieausweistyp', onOfficeSDK::MODULE_ESTATE); $pFieldEnergieausweistyp->setType(FieldTypes::FIELD_TYPE_SINGLESELECT); + $pFieldEnergieausweistyp->setLabel('Energieausweistyp'); $pFieldEnergieausweistyp->setPermittedvalues(['Bedarfsausweis' => 'Bedarfsausweis']); $pFieldEnergieausweistyp->setLabel('Energieausweistyp'); $pFieldsCollection->addField($pFieldEnergieausweistyp); diff --git a/tests/resources/ApiResponseListSupervisors.json b/tests/resources/ApiResponseListSupervisors.json new file mode 100644 index 000000000..5471e5679 --- /dev/null +++ b/tests/resources/ApiResponseListSupervisors.json @@ -0,0 +1,62 @@ +{ + "actionid": "urn:onoffice-de-ns:smart:2.5:smartml:action:get", + "resourceid": "", + "resourcetype": "users", + "cacheable": true, + "identifier": "", + "data": { + "meta": { + "cntabsolute": null + }, + "records": [ + { + "id": 69, + "type": null, + "elements": { + "id": 69, + "username": "duong", + "firstname": "aa", + "lastname": "aa", + "email": "daoduong@abc.abc" + } + }, + { + "id": 45, + "type": null, + "elements": { + "id": 45, + "username": "tester1", + "firstname": "Test first name", + "lastname": "", + "email": "dtd010196@gmail.com" + } + }, + { + "id": 42, + "type": null, + "elements": { + "id": 42, + "username": "tester2", + "firstname": "", + "lastname": "Test last name", + "email": "test2@gmail.com" + } + }, + { + "id": 30, + "type": null, + "elements": { + "id": 30, + "username": "Test Username", + "firstname": "", + "lastname": "", + "email": "test3@gmail.com" + } + } + ] + }, + "status": { + "errorcode": 0, + "message": "OK" + } +} \ No newline at end of file diff --git a/tests/resources/ApiResponseSupervisorFields.json b/tests/resources/ApiResponseSupervisorFields.json new file mode 100644 index 000000000..8c705dbaa --- /dev/null +++ b/tests/resources/ApiResponseSupervisorFields.json @@ -0,0 +1,34 @@ +{ + "actionid": "urn:onoffice-de-ns:smart:2.5:smartml:action:get", + "resourceid": "", + "resourcetype": "fields", + "cacheable": true, + "identifier": "", + "data": { + "meta": { + "cntabsolute": null + }, + "records": [ + { + "id": "estate", + "type": "", + "elements": { + "label": "Properties", + "benutzer": { + "type": "user", + "length": null, + "permittedvalues": null, + "default": null, + "label": "Supervisor", + "tablename": "ObjTech", + "content": "Technical-data" + } + } + } + ] + }, + "status": { + "errorcode": 0, + "message": "OK" + } +}