Browse Source

comboLookupText

SunRiseGC 4 years ago
parent
commit
002d0465e9

+ 7 - 0
include/comboLookupText.hrl

@@ -0,0 +1,7 @@
+-ifndef(COMBO_LOOKUP_TEXT_HRL).
+-define(COMBO_LOOKUP_TEXT_HRL, true).
+
+-include_lib("nitro/include/nitro.hrl").
+-record(comboLookupText, {?ELEMENT_BASE(element_comboLookupText), input, disabled, textarea, values}).
+
+-endif.

+ 21 - 0
priv/js/comboLookup.js

@@ -16,6 +16,27 @@ function comboSelect(dom, row, feed, mod, id) {
                  atom(mod)));
 }
 
+function displayTextarea(parent, input, textarea) {
+  const value = querySourceRaw(input);
+  let parentDom = qi(parent);
+  let textareaDom = qi(textarea);
+  if (parentDom && textareaDom) {
+    parentDom.style.display = 'none';
+    textareaDom.style.display = 'flex';
+    textareaDom.children[0].innerHTML = value.text ? value.text : "";
+  }
+}
+
+function hideTextarea(parent, textarea) {
+  let parentDom = qi(parent);
+  let textareaDom = qi(textarea);
+  if (parentDom && textareaDom) {
+    parentDom.style.display = 'flex';
+    textareaDom.style.display = 'none';
+    textareaDom.children[0].innerHTML = '';
+  }
+}
+
 function comboLookupChange(dom) {
   let elem = qi(dom);
   if (elem && elem.value == "" && elem.getAttribute("data-bind")) {

+ 4 - 1
priv/js/nitro.js

@@ -38,7 +38,10 @@ function querySourceRaw(Id) {
             }
             break;
         default:
-            if (el.getAttribute('data-vector-input')) {
+            if(el.getAttribute('data-text-input')) {
+              val = querySourceRaw(el.children[1].children[0].id);
+            }
+            else if (el.getAttribute('data-vector-input')) {
                 val = querySourceRaw(el.children[1].id);
             } else if (el.getAttribute('data-edit-input')) {
                 val = querySourceRaw(el.children[0].children[0].children[0].id);

+ 47 - 0
src/elements/combo/element_comboLookupText.erl

@@ -0,0 +1,47 @@
+-module(element_comboLookupText).
+-include_lib("nitro/include/comboLookupText.hrl").
+-include_lib("nitro/include/nitro.hrl").
+-export([render_element/1]).
+
+render_element(#comboLookupText{id=Id, input=Input, disabled=Disabled, validation=Validation, textarea=Textarea, values=Values}) ->
+  InputId = element(#element.id, Input),
+  LookupId = "wrap_" ++ Id ++ "_lookup",
+  TextareaId = "wrap_" ++ Id ++ "_textarea",
+  WrapId = "wrap_" ++ Id ++ "_comboLookupText",
+  TextAreaDisplay =
+    case Disabled of
+      true -> "flex";
+      _ -> "none"
+    end,
+  nitro:render(
+        #panel{
+          id = WrapId,
+          validation = Validation,
+          data_fields = [{<<"data-text-input">>,<<"data-text-input">>}],
+          body = [
+            #panel{
+              id = LookupId,
+              style = "display: flex; width: 100%; justify-content: center;",
+              body =
+                case Disabled of
+                  true -> [];
+                  _ -> [
+                    Input,
+                    #link{
+                      class = [button, sgreen],
+                      style = "min-width: 40px; text-align: center; height: fit-content; margin-left: 5px;",
+                      onclick = nitro:jse("displayTextarea('" ++ LookupId ++ "', '" ++ InputId ++ "', '" ++ TextareaId ++ "')"),
+                      body = <<"+">>} ] end },
+            #panel{
+              id = TextareaId,
+              style = "width: 100%; justify-content: center; display: " ++ TextAreaDisplay ++ ";",
+              body = [
+                Textarea |
+                case Disabled of
+                  true -> [];
+                  false ->
+                    [#link{
+                      class = [button, sgreen, back],
+                      style = "min-width: 40px; text-align: center; height: fit-content; margin-left: 5px;",
+                      onclick = nitro:jse("hideTextarea('" ++ LookupId ++ "', '" ++ TextareaId ++ "')"),
+                      body = <<"+">>}] end]}]}).