|
@@ -1,5 +1,6 @@
|
|
-module(wf_event).
|
|
-module(wf_event).
|
|
-author('Maxim Sokhatsky').
|
|
-author('Maxim Sokhatsky').
|
|
|
|
+-author('Andrey Martemyanov').
|
|
-include_lib ("nitro/include/nitro.hrl").
|
|
-include_lib ("nitro/include/nitro.hrl").
|
|
-compile(export_all).
|
|
-compile(export_all).
|
|
|
|
|
|
@@ -7,17 +8,21 @@
|
|
-record(cx, { handlers, actions, req, module, lang, path, session, formatter, params, form, state=[] }).
|
|
-record(cx, { handlers, actions, req, module, lang, path, session, formatter, params, form, state=[] }).
|
|
-define(CTX, (get(context))).
|
|
-define(CTX, (get(context))).
|
|
|
|
|
|
|
|
+-define(B(E), nitro:to_binary(E)).
|
|
|
|
+target({qs,S}) -> ["qs('",S,"')"];
|
|
|
|
+target(Id) -> ["qi('",?B(Id),"')"].
|
|
|
|
+
|
|
new(P,E,D,N,Data,Source) -> new(P,E,D,N,Data,Source,<<>>).
|
|
new(P,E,D,N,Data,Source) -> new(P,E,D,N,Data,Source,<<>>).
|
|
|
|
|
|
new(bin,Data) -> <<"ws.send(enc(tuple(atom('bin'),bin('",(nitro:pickle(Data))/binary,"'))));">>.
|
|
new(bin,Data) -> <<"ws.send(enc(tuple(atom('bin'),bin('",(nitro:pickle(Data))/binary,"'))));">>.
|
|
new(undefined, _, _, _, _, _, _) -> <<>>;
|
|
new(undefined, _, _, _, _, _, _) -> <<>>;
|
|
new(Postback, Element, Delegate, Name, Data, Source, Validation) ->
|
|
new(Postback, Element, Delegate, Name, Data, Source, Validation) ->
|
|
Module = nitro:coalesce([Delegate, ?CTX#cx.module]),
|
|
Module = nitro:coalesce([Delegate, ?CTX#cx.module]),
|
|
- Join=fun([]) -> []; ([E]) -> [$'|E]++[$'];
|
|
|
|
- ([H|T]) -> [[$'|H]++[$']] ++ [ [$,,$'|E]++[$'] || E <- T ] end,
|
|
|
|
|
|
+ Join=fun([]) -> [];
|
|
|
|
+ ([E]) -> [$'|E]++[$'];
|
|
|
|
+ ([H|T]) -> [[$'|H]++[$']] ++ [ [$,,$'|E]++[$'] || E <- T ] end,
|
|
Event = #ev{name=Name, module=Module, msg=Postback, trigger=Element},
|
|
Event = #ev{name=Name, module=Module, msg=Postback, trigger=Element},
|
|
- erlang:list_to_binary([ <<"{ if (validateSources([">>,
|
|
|
|
- Join([ case is_atom(S) of true -> atom_to_list(S); false -> S end || S <- Source, S =/= []]),
|
|
|
|
- <<"])) { ">>,nitro:to_binary(Validation),<<" ws.send(enc(tuple(atom('">>,
|
|
|
|
- nitro:to_binary(application:get_env(n2o,event,pickle)),<<"'),bin('">>,Element,<<"'),bin('">>,
|
|
|
|
- nitro:pickle(Event),<<"'),">>,Data,<<"))); } else console.log('Validation Error'); }">> ]).
|
|
|
|
|
|
+ list_to_binary(["{ if (validateSources([",
|
|
|
|
+ Join([ case is_atom(S) of true -> ?B(S); false -> S end || S <- Source, S =/= []]),
|
|
|
|
+ "])) { ",?B(Validation)," ws.send(enc(tuple(atom('",?B(application:get_env(n2o,event,pickle)),"'),bin('",
|
|
|
|
+ Element,"'),bin('",nitro:pickle(Event),"'),",Data,"))); } else console.log('Validation Error'); }"]).
|