SunRiseGG 2 лет назад
Родитель
Сommit
be66db9d28
6 измененных файлов с 45 добавлено и 17 удалено
  1. 1 0
      include/comboLookup.hrl
  2. 10 0
      lib/combo.ex
  3. 1 1
      mix.exs
  4. 15 2
      priv/js/comboLookup.js
  5. 17 14
      priv/js/sortable.js
  6. 1 0
      src/elements/combo/element_comboLookup.erl

+ 1 - 0
include/comboLookup.hrl

@@ -6,6 +6,7 @@
 -record(comboKey,    { uid=[], value=[], dom=[], feed=[], delegate=[]}).
 -record(comboKeyup,  { value=[], dom=[], feed=[], delegate=[]}).
 -record(comboSelect, { uid=[], value=[], dom=[], feed=[], delegate=[], update=[]}).
+-record(comboVecAdd, { list_id=[], value=[], feed=[], delegate=[]}).
 -record(comboNext,   { pos=[],  count=[], feed=[]}).
 -record(comboScroll, { uid=[], dom=[], delegate=[] }).
 -record(comboInsert, { uid=[], dom=[], rows=[], chunks=[], status=[], delegate=[], feed=[] }).

+ 10 - 0
lib/combo.ex

@@ -56,6 +56,13 @@ defmodule NITRO.Combo do
     end
   end
 
+  def proto(NITRO.comboVecAdd(delegate: module) = msg) do
+    case has_function(module, :comboVecAdd) do
+      true -> module.comboVecAdd(msg)
+      false -> comboVecAdd(msg)
+    end
+  end
+
   def proto(NITRO.comboModify(delegate: module) = msg) do
     case has_function(module, :comboModify) do
       true -> module.comboModify(msg)
@@ -116,6 +123,9 @@ defmodule NITRO.Combo do
     )
   end
 
+  def comboVecAdd(NITRO.comboVecAdd(list_id: list, value: value, delegate: mod, feed: feed)), do:
+    :nitro.wire("appendItemFromBind('#{list}', '#{view_value(value, mod, feed)}', '#{:base64.encode(:erlang.term_to_binary(value))}');")
+
   def comboModify(NITRO.comboModify(list_id: list, item_id: item, value: value, bind: bind, modify_bind: modify_bind, delegate: module, pos: pos, feed: feed)) do
     new_bind = :erlang.setelement(pos, bind, modify_bind)
     :nitro.update(

+ 1 - 1
mix.exs

@@ -4,7 +4,7 @@ defmodule NITRO.Mixfile do
   def project do
     [
       app: :nitro,
-      version: "7.9.1",
+      version: "7.9.2",
       description: "NITRO Nitrogen Web Framework",
       package: package(),
       deps: deps()

+ 15 - 2
priv/js/comboLookup.js

@@ -124,10 +124,23 @@ function comboSelectVector(uid, dom, row, feed, mod, id) {
   comboSelectDefault(...arguments);
   let listSplit = dom.split('_');
   listSplit.pop();
-  const list = '#' + listSplit.join('_') + '_list';
-  addSortableItemFrom(list, dom);
+  const listId = listSplit.join('_') + '_list';
+  const input = qi(dom);
+  const list = qi(listId);
+  if (list && input && input.value != '') {
+    const data = querySourceRaw(dom);
+    if (data && data.hasOwnProperty('text') && data.hasOwnProperty('bind')) {
+      const bind = data.bind;
+      const value = data.text;
+      if (bind !== '' && bind !== 'null') {
+        clearInput(dom);
+        direct(tuple(atom('comboVecAdd'), string(listId), dec(unbase64(bind)), string(feed), atom(mod)));
+      }
+    }
+  }
 }
 
+
 function comboSelectGroup(uid, dom, row, feed, mod, id) {
   const selected = qi(id);
   if (selected) {

+ 17 - 14
priv/js/sortable.js

@@ -229,18 +229,21 @@ function getSortableValues(list) {
 
 function appendItemFromBind(dom,value,bind) {
   var sortable = SortableMap.get('#'+dom);
-  var template = document.createElement('template');
-  template.innerHTML =
-    '<div class="list__item" data-sortable-item="data-sortable-item" style="" data-bind="'+ bind + '">' +
-       '<div class="list__item-close" onclick="removeSortableItem(\'#' + sortable.list.id + '\', this.parentNode);"></div>' +
-       '<div class="list__item-content" list-item-content="list-item-content"><div class="list__item-title">' + value + '</div></div>' +
-       '<div class="list__item-handle" data-sortable-handle="data-sortable-handle"></div>' +
-    '</div>'
-  var new_item = template.content.firstChild;
-  if(bind instanceof Date) {
-    new_item.setAttribute("date-bind", bind);
-    new_item.setAttribute("data-bind", "");
+  var isAdded = sortable.items.map(el => el.textContent).includes(value || {"text": value, "bind": bind});
+  if(!isAdded) {
+    var template = document.createElement('template');
+    template.innerHTML =
+      '<div class="list__item" data-sortable-item="data-sortable-item" style="" data-bind="'+ bind + '">' +
+         '<div class="list__item-close" onclick="removeSortableItem(\'#' + sortable.list.id + '\', this.parentNode);"></div>' +
+         '<div class="list__item-content" list-item-content="list-item-content"><div class="list__item-title">' + value + '</div></div>' +
+         '<div class="list__item-handle" data-sortable-handle="data-sortable-handle"></div>' +
+      '</div>'
+    var new_item = template.content.firstChild;
+    if(bind instanceof Date) {
+      new_item.setAttribute("date-bind", bind);
+      new_item.setAttribute("data-bind", "");
+    }
+    sortable.list.appendChild(new_item);
+    sortable.items.push(new_item);
   }
-  sortable.list.appendChild(new_item);
-  sortable.items.push(new_item);
-}
+}

+ 1 - 0
src/elements/combo/element_comboLookup.erl

@@ -8,6 +8,7 @@ proto(#comboKeyup{delegate=Module}=Msg)  -> Module:proto(Msg);
 proto(#comboSelect{delegate=Module}=Msg) -> Module:proto(Msg);
 proto(#comboScroll{delegate=Module}=Msg) -> Module:proto(Msg);
 proto(#comboInsert{delegate=Module}=Msg) -> Module:proto(Msg);
+proto(#comboVecAdd{delegate=Module}=Msg) -> Module:proto(Msg);
 proto(#comboAdd{delegate=Module}=Msg)    -> Module:proto(Msg);
 proto(#comboModify{delegate=Module}=Msg) -> Module:proto(Msg);
 proto(#comboGroup{delegate=Module}=Msg)  -> Module:proto(Msg);