element_input_button.erl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. -module(element_input_button).
  2. -author('Vladimir Galunshchikov').
  3. -include_lib("nitro/include/nitro.hrl").
  4. -include_lib("nitro/include/event.hrl").
  5. -compile(export_all).
  6. render_element(Record) when Record#input_button.show_if==false -> [<<>>];
  7. render_element(Record) ->
  8. Id = case Record#input_button.postback of
  9. [] -> Record#input_button.id;
  10. Postback ->
  11. ID = case Record#input_button.id of
  12. [] -> nitro:temp_id();
  13. I -> I end,
  14. nitro:wire(#event{type=click, postback=Postback, target=ID,
  15. source=Record#input_button.source, delegate=Record#input_button.delegate }),
  16. ID end,
  17. List = [
  18. %global
  19. {<<"accesskey">>, Record#input_button.accesskey},
  20. {<<"class">>, Record#input_button.class},
  21. {<<"contenteditable">>, case Record#input_button.contenteditable of true -> "true"; false -> "false"; _ -> [] end},
  22. {<<"contextmenu">>, Record#input_button.contextmenu},
  23. {<<"dir">>, case Record#input_button.dir of "ltr" -> "ltr"; "rtl" -> "rtl"; "auto" -> "auto"; _ -> [] end},
  24. {<<"draggable">>, case Record#input_button.draggable of true -> "true"; false -> "false"; _ -> [] end},
  25. {<<"dropzone">>, Record#input_button.dropzone},
  26. {<<"hidden">>, case Record#input_button.hidden of "hidden" -> "hidden"; _ -> [] end},
  27. {<<"id">>, Id},
  28. {<<"lang">>, Record#input_button.lang},
  29. {<<"spellcheck">>, case Record#input_button.spellcheck of true -> "true"; false -> "false"; _ -> [] end},
  30. {<<"style">>, Record#input_button.style},
  31. {<<"tabindex">>, Record#input_button.tabindex},
  32. {<<"title">>, Record#input_button.title},
  33. {<<"translate">>, case Record#input_button.contenteditable of "yes" -> "yes"; "no" -> "no"; _ -> [] end},
  34. % spec
  35. {<<"autofocus">>,Record#input_button.autofocus},
  36. {<<"disabled">>, if Record#input_button.disabled == true -> "disabled"; true -> [] end},
  37. {<<"name">>,Record#input_button.name},
  38. {<<"type">>, <<"button">>},
  39. {<<"value">>, Record#input_button.value} | Record#input_button.data_fields
  40. ],
  41. wf_tags:emit_tag(<<"input">>, nitro:render(Record#input_button.body), List).