element_upload.erl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -module(element_upload).
  2. %%-author('Maxim Sokhatsky').
  3. -include_lib("nitro/include/nitro.hrl").
  4. -include_lib("nitro/include/event.hrl").
  5. -export([
  6. render_element/1
  7. ]).
  8. render_element(Record) when Record#upload.show_if == false -> [<<>>];
  9. render_element(#upload{id=Id}) ->
  10. Uid = case Id of
  11. [] -> wf:temp_id();
  12. I -> I
  13. end,
  14. wf:wire("ftp_file=undefined;"),
  15. %% wf:wire( #bind{target = Control, type = Event, postback = Code} )
  16. wf:wire( #bind{target = ftp_open, type = click, postback = wf:f("qi('~s').click();event.preventDefault();", [ nitro:to_list(Uid) ] ) } ),
  17. wf:wire( #bind{target = ftp_start, type = click, postback = "ftp.start(ftp_file);"} ),
  18. wf:wire( #bind{target = ftp_stop, type = click, postback = "ftp.stop(ftp_file);"} ),
  19. wf:wire( #bind{target = nitro:to_atom(Uid), type = change, postback = "ftp_file=ftp.init(this.files[0]);"} ),
  20. Upload = #panel{ body = [
  21. #input{ id = Uid, type = <<"file">>, style = "display:none" },
  22. #span { id = ftp_status, body = [] },
  23. #span { body = [
  24. #button{ id = ftp_open, body = "Browse" },
  25. #button{ id = ftp_start, body = "Upload" },
  26. #button{ id = ftp_stop, body = "Stop" } %% todo customisation
  27. ]}
  28. ]},
  29. wf:render(Upload).