-module(element_upload). %%-author('Maxim Sokhatsky'). -include_lib("nitro/include/nitro.hrl"). -include_lib("nitro/include/event.hrl"). -export([ render_element/1 ]). render_element(Record) when Record#upload.show_if == false -> [<<>>]; render_element(#upload{id=Id}) -> Uid = case Id of [] -> wf:temp_id(); I -> I end, wf:wire("ftp_file=undefined;"), %% wf:wire( #bind{target = Control, type = Event, postback = Code} ) wf:wire( #bind{target = ftp_open, type = click, postback = wf:f("qi('~s').click();event.preventDefault();", [ nitro:to_list(Uid) ] ) } ), wf:wire( #bind{target = ftp_start, type = click, postback = "ftp.start(ftp_file);"} ), wf:wire( #bind{target = ftp_stop, type = click, postback = "ftp.stop(ftp_file);"} ), wf:wire( #bind{target = nitro:to_atom(Uid), type = change, postback = "ftp_file=ftp.init(this.files[0]);"} ), Upload = #panel{ body = [ #input{ id = Uid, type = <<"file">>, style = "display:none" }, #span { id = ftp_status, body = [] }, #span { body = [ #button{ id = ftp_open, body = "Browse" }, #button{ id = ftp_start, body = "Upload" }, #button{ id = ftp_stop, body = "Stop" } %% todo customisation ]} ]}, wf:render(Upload).