From b1af69e7f2539d859464d55c542a3c47226d318e Mon Sep 17 00:00:00 2001 From: 5HT Date: Wed, 8 Jan 2020 15:54:19 +0200 Subject: [PATCH] 5.1.3 --- mix.exs | 2 +- src/form.app.src | 2 +- src/form.erl | 1 + src/form_backend.erl | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/mix.exs b/mix.exs index d20cb73..0ec0103 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule FORM.Mixfile do def project do [ app: :form, - version: "5.1.2", + version: "5.1.3", description: "FORM Business X-Forms", package: package(), deps: deps() diff --git a/src/form.app.src b/src/form.app.src index d4af9b4..017a7bf 100644 --- a/src/form.app.src +++ b/src/form.app.src @@ -1,6 +1,6 @@ {application, form, [{description, "FORM Business X-Forms"}, - {vsn, "5.1.2"}, + {vsn, "5.1.3"}, {registered, []}, {applications, [kernel,stdlib]}, {mod, { form, []}}, diff --git a/src/form.erl b/src/form.erl index baef676..c8e72e5 100644 --- a/src/form.erl +++ b/src/form.erl @@ -17,6 +17,7 @@ type(Object) -> ?M:type(Object). kind(Options) -> ?M:kind(Options). pos(Object,X) -> ?M:pos(Object,X). extract(Object,X) -> ?M:extract(Object,X). +extract(Object,X,Ref) -> ?M:extract(Object,X,Ref). evoke(Object,X,Value) -> ?M:evoke(Object,X,Value). id() -> fun (X) -> X end. atom(List) when is_list(List) -> string:join([ nitro:to_list(L) || L <- List],"_"); diff --git a/src/form_backend.erl b/src/form_backend.erl index 38324c9..150a68e 100644 --- a/src/form_backend.erl +++ b/src/form_backend.erl @@ -25,13 +25,33 @@ pos(Object,X) -> Tab = element(1,Object), Fields = element(5,kvs:table(Tab)), P = string:rstr([Tab|Fields],[X#field.id]), -% io:format("pos: ~p~n",[{Object,X}]), + % io:format("pos: ~p~n",[{P,Object,X}]), P. - -extract({_, Value}, _X) -> Value; -extract(Object,X) -> -% io:format("extract: ~p~n",[{Object,X}]), - element(form:pos(Object,X),Object). +extract(Object,X) -> extract(Object,X,false). +extract({_, Value}, X, true) -> extract_ref(Value, X#field.module); +extract({_, Value}, _X, false) -> Value; +extract(Object, X, false) -> + Pos = form:pos(Object,X), + Value = element(Pos, Object), + % io:format("extract: ~p~n",[{Pos, Value, Object}]), + Value; +extract(Object, X, true) -> + Ref = extract(Object, X, false), + Value = extract_ref(Ref, X#field.module), + % io:format("extract ref: ~p~n",[{Value, Ref, Object, X}]), + Value +. +extract_ref(Ref, Module) when is_tuple(Ref) -> + case has_function(Module, view_value) of + true -> Module:view_value(Ref); + false -> element(3, Ref) + end; +extract_ref(Ref, _Module) -> Ref. +has_function([], _F) -> false; +has_function(M, F) -> + Functions = apply(M, module_info, [exports]), + IsF = proplists:get_value(F, Functions, -1), + IsF /= -1. evoke(Object,X,Value) -> setelement(form:pos(Object,X),Object,Value). @@ -293,8 +313,9 @@ fieldType(comboLookup,X,_Options,Object,Opt) -> #comboLookup{id=form:atom([X#field.id,form:type(Object),form:kind(Opt)]), disabled = X#field.disabled, validation=form:val(Opt,nitro:f("Validation.comboLookup(e, ~w, ~w)",[X#field.min,X#field.max])), - feed=X#field.bind, - value = form:extract(Object,X), + feed = X#field.bind, + value = form:extract(Object,X,true), + bind = form:extract(Object,X,false), delegate = X#field.module, reader=[], chunk=20};