Skip to content

Instantly share code, notes, and snippets.

@5HT
Created September 21, 2015 11:47
Show Gist options
  • Save 5HT/37decb5d7f7ecc96b611 to your computer and use it in GitHub Desktop.
Save 5HT/37decb5d7f7ecc96b611 to your computer and use it in GitHub Desktop.
-module(upload).
-compile(export_all).
-include_lib("nitro/include/nitro.hrl").
-include_lib("kernel/include/file.hrl").
-record(upload, {?CTRL_BASE(element_upload), name, value, post_write, img_tool, post_target }).
render_element(#upload{id=Id} = R) ->
Uid = case Id of undefined -> wf:temp_id(); I -> I end,
Uel = R#upload{id=Uid},
wire(Uel), render(Uel).
render(#upload{id=Id} = R) ->
[wf_tags:emit_tag(<<"input">>, [], [
{<<"id">>, Id},
{<<"type">>, <<"file">>},
{<<"class">>, R#upload.class},
{<<"style">>, <<"display:none">>},
{<<"name">>, R#upload.name} ])].
wire(#upload{id=Id}=R) ->
JsS = wf:json([{value, R#upload.value}]),
error_logger:info_msg("wire option:~p", [JsS]),
wf:wire(wf:f("Upload('#~s',~s);", [Id, JsS])).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment