element_upload.erl 1017 B

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