From 535f433817600dadddd03b55b7a95b3514a15c95 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 29 Oct 2021 15:50:17 +0200 Subject: [PATCH] fix(ui): pre-select value for enum --- app/views/console/database/document.phtml | 4 ++-- gulpfile.js | 1 + public/dist/scripts/app-all.js | 2 +- public/dist/scripts/app.js | 2 +- public/scripts/views/forms/selected.js | 16 ++++++++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 public/scripts/views/forms/selected.js diff --git a/app/views/console/database/document.phtml b/app/views/console/database/document.phtml index 352600b04..ebd570353 100644 --- a/app/views/console/database/document.phtml +++ b/app/views/console/database/document.phtml @@ -262,8 +262,8 @@ $logs = $this->getParam('logs', null); diff --git a/gulpfile.js b/gulpfile.js index 5f745cc56..e58969872 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -63,6 +63,7 @@ const configApp = { 'public/scripts/views/forms/remove.js', 'public/scripts/views/forms/run.js', 'public/scripts/views/forms/select-all.js', + 'public/scripts/views/forms/selected.js', 'public/scripts/views/forms/show-secret.js', 'public/scripts/views/forms/switch.js', 'public/scripts/views/forms/tags.js', diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index cacafd4d3..81db4ac64 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -2520,7 +2520,7 @@ score+=(variationCount-1)*10;return parseInt(score);};var callback=function(){va if(rtl.isRTL(content)){paragraph.style.direction='rtl';paragraph.style.textAlign='right';} else{paragraph.style.direction='ltr';paragraph.style.textAlign='left';} last=paragraph;}};var santize=function(e){clean(e);alignText(e);};element.addEventListener("change",function(){editor.content.innerHTML=markdown.render(element.value);alignText();});editor.content.setAttribute("placeholder",element.placeholder);editor.content.innerHTML=markdown.render(element.value);editor.content.tabIndex=0;alignText();editor.content.onkeydown=function preventTab(event){if(event.which===9){event.preventDefault();if(document.activeElement){var focussable=Array.prototype.filter.call(document.querySelectorAll('a:not([disabled]), button:not([disabled]), select:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex="-1"])'),function(element){return(element.offsetWidth>0||element.offsetHeight>0||element===document.activeElement);});var index=focussable.indexOf(document.activeElement);if(index>-1){if(event.shiftKey){var prevElement=focussable[index-1]||focussable[focussable.length-1];prevElement.focus();}else{var nextElement=focussable[index+1]||focussable[0];nextElement.focus();}}}}};div.addEventListener("paste",santize);div.addEventListener("drop",santize);}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-required",controller:function(element,expression){const isRequired=expression.parse(element.getAttribute('data-forms-required'))==="true";if(isRequired){element.setAttribute("required",true);}else{element.removeAttribute("disabled");}}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-remove",controller:function(element){Array.prototype.slice.call(element.querySelectorAll("[data-remove]")).map(function(obj){obj.addEventListener("click",function(){element.parentNode.removeChild(element);});});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-run",repeat:false,controller:function(element,expression,container){let action=expression.parse(element.dataset["formsRun"]||'');element.addEventListener('click',function(){return container.path(action)();});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-select-all",controller:function(element){let select=document.createElement("button");let unselect=document.createElement("button");select.textContent='Select All';unselect.textContent='Unselect All';select.classList.add('link');select.classList.add('margin-top-tiny');select.classList.add('margin-start-small');select.classList.add('text-size-small');select.classList.add('pull-end');unselect.classList.add('link');unselect.classList.add('margin-top-tiny');unselect.classList.add('margin-start-small');unselect.classList.add('text-size-small');unselect.classList.add('pull-end');select.type='button';unselect.type='button';element.parentNode.insertBefore(select,element);element.parentNode.insertBefore(unselect,element);select.addEventListener('click',function(){let checkboxes=element.querySelectorAll("input[type='checkbox']");for(var i=0;i0){array.push(add.value);add.value="";element.value=JSON.stringify(array);check();if(event.key!=="Tab"){event.preventDefault();}} if((event.key==="Backspace"||event.key==="Delete")&&add.value===""){array.splice(-1,1);element.value=JSON.stringify(array);check();} return false;};let check=function(){try{array=JSON.parse(element.value)||[];}catch(error){array=[];} diff --git a/public/dist/scripts/app.js b/public/dist/scripts/app.js index c9ed2c2fd..1e39fbbb6 100644 --- a/public/dist/scripts/app.js +++ b/public/dist/scripts/app.js @@ -426,7 +426,7 @@ score+=(variationCount-1)*10;return parseInt(score);};var callback=function(){va if(rtl.isRTL(content)){paragraph.style.direction='rtl';paragraph.style.textAlign='right';} else{paragraph.style.direction='ltr';paragraph.style.textAlign='left';} last=paragraph;}};var santize=function(e){clean(e);alignText(e);};element.addEventListener("change",function(){editor.content.innerHTML=markdown.render(element.value);alignText();});editor.content.setAttribute("placeholder",element.placeholder);editor.content.innerHTML=markdown.render(element.value);editor.content.tabIndex=0;alignText();editor.content.onkeydown=function preventTab(event){if(event.which===9){event.preventDefault();if(document.activeElement){var focussable=Array.prototype.filter.call(document.querySelectorAll('a:not([disabled]), button:not([disabled]), select:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex="-1"])'),function(element){return(element.offsetWidth>0||element.offsetHeight>0||element===document.activeElement);});var index=focussable.indexOf(document.activeElement);if(index>-1){if(event.shiftKey){var prevElement=focussable[index-1]||focussable[focussable.length-1];prevElement.focus();}else{var nextElement=focussable[index+1]||focussable[0];nextElement.focus();}}}}};div.addEventListener("paste",santize);div.addEventListener("drop",santize);}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-required",controller:function(element,expression){const isRequired=expression.parse(element.getAttribute('data-forms-required'))==="true";if(isRequired){element.setAttribute("required",true);}else{element.removeAttribute("disabled");}}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-remove",controller:function(element){Array.prototype.slice.call(element.querySelectorAll("[data-remove]")).map(function(obj){obj.addEventListener("click",function(){element.parentNode.removeChild(element);});});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-run",repeat:false,controller:function(element,expression,container){let action=expression.parse(element.dataset["formsRun"]||'');element.addEventListener('click',function(){return container.path(action)();});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-select-all",controller:function(element){let select=document.createElement("button");let unselect=document.createElement("button");select.textContent='Select All';unselect.textContent='Unselect All';select.classList.add('link');select.classList.add('margin-top-tiny');select.classList.add('margin-start-small');select.classList.add('text-size-small');select.classList.add('pull-end');unselect.classList.add('link');unselect.classList.add('margin-top-tiny');unselect.classList.add('margin-start-small');unselect.classList.add('text-size-small');unselect.classList.add('pull-end');select.type='button';unselect.type='button';element.parentNode.insertBefore(select,element);element.parentNode.insertBefore(unselect,element);select.addEventListener('click',function(){let checkboxes=element.querySelectorAll("input[type='checkbox']");for(var i=0;i0){array.push(add.value);add.value="";element.value=JSON.stringify(array);check();if(event.key!=="Tab"){event.preventDefault();}} if((event.key==="Backspace"||event.key==="Delete")&&add.value===""){array.splice(-1,1);element.value=JSON.stringify(array);check();} return false;};let check=function(){try{array=JSON.parse(element.value)||[];}catch(error){array=[];} diff --git a/public/scripts/views/forms/selected.js b/public/scripts/views/forms/selected.js new file mode 100644 index 000000000..92b247799 --- /dev/null +++ b/public/scripts/views/forms/selected.js @@ -0,0 +1,16 @@ +(function(window) { + "use strict"; + + window.ls.container.get("view").add({ + selector: "data-forms-selected", + controller: function(element, expression) { + const isSelected = expression.parse(element.getAttribute('data-forms-selected')) === element.getAttribute('value'); + + if (isSelected) { + element.setAttribute("selected", true); + } else { + element.removeAttribute("selected"); + } + } + }); +})(window);