5HT 5 лет назад
Родитель
Сommit
21d24f72d7

+ 1 - 1
mix.exs

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

+ 16 - 6
priv/js/nitro.js

@@ -25,7 +25,14 @@ function querySourceRaw(Id) {
                 case 'checkbox': val = qs('input[id='+Id+']:checked'); val = val ? val.value : ""; break;
                 case 'date': val = Date.parse(el.value);  val = val && new Date(val) || ""; break;
                 case 'calendar': val = pickers[el.id]._d || ""; break;
-                case 'comboLookup': var x = el.getAttribute('data-bind'); if (x) val=dec(unbase64(x)); break;
+                case 'comboLookup':
+                    var x = el.getAttribute('data-bind');
+                    if (x) {
+                        val = { 'text' : el.value, 'bind' : x};
+                    } else {
+                        val = el.value;
+                    }
+                    break;
                 default: var edit = el.contentEditable;
                     if (edit && edit === 'true') val = el.innerHTML;
                     else val = el.value;
@@ -49,9 +56,9 @@ function querySourceRaw(Id) {
     return val;
 }
 
-function querySource(Id) {
-    var qs = querySourceRaw(Id);
-    if (qs && qs.t && qs.v) return qs;
+function querySourceConvert(qs) {
+    if (qs && qs.text && qs.bind) {
+        return dec(unbase64(qs.bind)); }
     else if (qs instanceof Date) {
         return tuple(number(qs.getFullYear()),
                      number(qs.getMonth() + 1),
@@ -59,8 +66,11 @@ function querySource(Id) {
     else if (qs instanceof Boolean) {
         return atom(qs.valueOf()); }
     else if (qs instanceof Array) {
-        return list.apply(null, qs.map(bin)); }
+        return list.apply(null, qs.map(querySourceConvert)); }
     else { return bin(qs); }
 }
 
-
+function querySource(Id) {
+    var qs = querySourceRaw(Id);
+    return querySourceConvert(qs);
+}

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

@@ -7,8 +7,12 @@ proto(#comboKey{delegate=Module}=Msg)    -> Module:proto(Msg);
 proto(#comboKeyup{delegate=Module}=Msg)  -> Module:proto(Msg);
 proto(#comboSelect{delegate=Module}=Msg) -> Module:proto(Msg).
 
-render_element(#comboLookup{id=Id, style=Style, value = Val,
+render_element(#comboLookup{id=Id, style=Style, value = Val, bind = Object0,
   feed = Feed, disabled = Disabled, delegate = Module} = Data) ->
+  Object = case Object0 of 
+              [] -> [];
+              _ -> base64:encode(term_to_binary(Object0))
+         end,
   nitro:render(
     #panel{id=form:atom([lookup, Id]), class=[dropdown],
            body=[#input{id=Id, disabled = Disabled, type="comboLookup",
@@ -20,6 +24,7 @@ render_element(#comboLookup{id=Id, style=Style, value = Val,
                                ++ nitro:to_list(Id) ++ "','"
                                ++ nitro:to_list(Feed) ++ "','"
                                ++ nitro:to_list(Module) ++ "')"),
+                        bind = Object,
                         value = Val, style = Style, class = column},
                  #panel{id=form:atom([comboContainer, Id]),
                         class = ['dropdown-content']}]}).

+ 29 - 26
src/elements/combo/element_sortable_item.erl

@@ -4,31 +4,34 @@
 -include_lib("nitro/include/event.hrl").
 -export([render_element/1]).
 
-render_element(#sortable_item{list_id = ListId, value = Value, closeable = Close, disabled = Disabled}) ->
+render_element(#sortable_item{list_id=ListId, value=Value, bind=Bind, closeable=Close, disabled=Disabled}) ->
   Item = case Disabled of
-              true ->
-                #panel{
-                  class = <<"list__item">>,
-                  body = #panel{
-                      class = <<"list__item-content">>,
-                      style = <<"width:100%">>,
-                      body = #panel{ class = <<"list__item-title">>, body = Value}}};
-              _ ->
-                #panel{
-                  class = <<"list__item">>,
-                  data_fields = [{<<"data-sortable-item">>,<<"data-sortable-item">>}],
-                  body = [
-                    case Close of
-                      true -> 
-                        #panel{
-                          class = <<"list__item-close">>,
-                          onclick = nitro:jse("removeSortableItem('#" ++ ListId ++ "', this.parentNode);")};
-                      _ -> [] end,
-                    #panel{
-                      class = <<"list__item-content">>,
-                      style = case Close of true -> []; _ -> <<"width:100% - 40px">> end,
-                      body = #panel{ class = <<"list__item-title">>, body = Value}},
-                    #panel{
-                      class = <<"list__item-handle">>,
-                      data_fields = [{<<"data-sortable-handle">>,<<"data-sortable-handle">>}]}]} end,
+    true ->
+      #panel{
+        class = <<"list__item">>,
+        body = #panel{
+            class = <<"list__item-content">>,
+            style = <<"width:100%">>,
+            body = #panel{ class = <<"list__item-title">>, body = Value}}};
+    _ ->
+      #panel{
+        class = <<"list__item">>,
+        data_fields = [ {<<"data-sortable-item">>,<<"data-sortable-item">>} |
+          case Bind of
+            [] -> [];
+            _ -> [{<<"data-bind">>, base64:encode(term_to_binary(Bind))}] end ],
+        body = [
+          case Close of
+            true -> 
+              #panel{
+                class = <<"list__item-close">>,
+                onclick = nitro:jse("removeSortableItem('#" ++ ListId ++ "', this.parentNode);")};
+            _ -> [] end,
+          #panel{
+            class = <<"list__item-content">>,
+            style = case Close of true -> []; _ -> <<"width:100% - 40px">> end,
+            body = #panel{ class = <<"list__item-title">>, body = Value}},
+          #panel{
+            class = <<"list__item-handle">>,
+            data_fields = [{<<"data-sortable-handle">>,<<"data-sortable-handle">>}]}]} end,
   nitro:render(Item).

+ 10 - 11
src/elements/combo/element_sortable_list.erl

@@ -5,21 +5,20 @@
 -include_lib("nitro/include/event.hrl").
 -export([render_element/1]).
 
-render_element(#sortable_list{id=Id, values = Values, closeable = Close, disabled = Disabled}) ->
+render_element(#sortable_list{id = Id, values = Values, closeable = Close, disabled = Disabled}) ->
   case Disabled of
     true ->
       Closeable = false;
     _ ->
       nitro:wire("createSortable('#" ++ Id ++ "');"),
       Closeable = Close end,
-  
+  ProtoItem = #sortable_item{ list_id = Id, closeable = Closeable, disabled = Disabled},
+  Body = case Values of
+          {view_value_pairs, List} ->
+            [ ProtoItem#sortable_item{value = Val, bind = Bind} || {Val, Bind} <- List ];
+          _ ->
+            [ ProtoItem#sortable_item{value = Val} || Val <- Values ] end,
   nitro:render(
-    #panel{
-      id = Id,
-      data_fields = [{<<"data-sortable-list">>, <<"data-sortable-list">>}],
-      body = [#sortable_item{
-                list_id = Id,
-                value = Val,
-                closeable = Closeable,
-                disabled = Disabled
-              } || Val <- Values]}).
+    #panel{ id = Id,
+            data_fields = [{<<"data-sortable-list">>, <<"data-sortable-list">>}],
+            body = Body}).

+ 1 - 1
src/nitro.app.src

@@ -1,6 +1,6 @@
 {application, nitro, [
     {description,  "NITRO Nitrogen Web Framework"},
-    {vsn,          "5.1.2"},
+    {vsn,          "5.1.4"},
     {applications, [kernel, stdlib]},
     {modules, []},
     {registered,   []},