erlang - Nitrogen - Dynamically creating Events -


i beginner erlang/nitrogen. toying bidding system mnesia db. on index page have following code , various items , properties created dynamically database:

 %% -*- mode: nitrogen -*- -module (index). -compile(export_all). -include_lib("nitrogen/include/wf.hrl").  main() -> #template { file="./site/templates/bare.html" }.  title() -> "meir panim gala dinner silent auction".  body() ->    header = [#panel{id=header, body=[#h1{text="meir panim gala dinner silent auction"}]}],    {atomic, items} = item_database:get_all(),   elements = lists:map(fun(x) ->     {item, index, title, _, picture, _, _, reserve, currentbid} = x,         #panel{id=items, body=[                     #span{id=title, text=title},                     #image{id=image, image= "images/" ++ picture},                     #span{id=currentbid, text="current bid: £" ++ integer_to_list(currentbid)},                     #span{id=reserve, text="reserve: £" ++ wf:to_list(reserve)},                     #link{id=showalert, text="more info / place bid", postback="showalert"++integer_to_list(index)}                   ]           }     end, items),   wf:f([header, elements]).  {atomic, items} = item_database:get_all(),   actions = lists:map(fun(x) ->     {item, index, _, _, _, _, _, _, _} = x,         event("showalert"++integer_to_list(index)) ->       wf:wire(#alert{text="action "++integer_to_list(index)++" clicked"})   end, items).  

i tried create events in same manner not working. in code alerts replaced lightboxes containing form accept bids. please , tell me doing wrong.

as far know catch events in page "event".

so try :

postback={bid, index}  

and @ down catch :

event({bid, index})->   %% stuff  ok; event(_)->  ok. 

update:

this example of how can fix it, not best way.

%% -*- mode: nitrogen -*- -module (index). -compile(export_all). -include_lib("nitrogen/include/wf.hrl").  main() -> #template { file="./site/templates/bare.html" }.  title() -> "meir panim gala dinner silent auction".  body() ->    header = [#panel{id=header, body=[#h1{text="meir panim gala dinner silent auction"}]}],    {atomic, items} = item_database:get_all(),   elements = lists:map(fun(x) ->     {item, index, title, _, picture, _, _, reserve, currentbid} = x,         #panel{id=items, body=[                     #span{id=title, text=title},                     #image{id=image, image= "images/" ++ picture},                     #span{id=currentbid, text="current bid: £" ++ integer_to_list(currentbid)},                     #span{id=reserve, text="reserve: £" ++ wf:to_list(reserve)},                     #link{id=showalert, text="more info / place bid", postback={bid,index}}                   ]           }     end, items),   wf:f([header, elements]).  event({bid, idx})->    %% better have function 1 item @ time in item_database    case item_database:get_by_index(idx) of     {atomic, x} ->          %% not right way, use records         {item, index, title, _, picture, _, _, reserve, currentbid} = x,         wf:wire(#alert{text="action "++ title ++" clicked"});     _ ->         wf:wire(#alert{text="item not found"})    end;  event(_)->    ok.  

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -