Skip to content

Commit

Permalink
5.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Jan 8, 2020
1 parent bb8a443 commit b1af69e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/form.app.src
Original file line number Diff line number Diff line change
@@ -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, []}},
Expand Down
1 change: 1 addition & 0 deletions src/form.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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],"_");
Expand Down
37 changes: 29 additions & 8 deletions src/form_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit b1af69e

Please sign in to comment.