element_input_button.erl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. -module(element_input_button).
  2. % author Vladimir Galunshchikov
  3. -include_lib("nitro/include/nitro.hrl").
  4. -include_lib("nitro/include/event.hrl").
  5. -export([render_element/1]).
  6. render_element(Record) when Record#input_button.show_if == false ->
  7. [<<>>];
  8. render_element(Record) ->
  9. Id = case Record#input_button.postback of
  10. [] -> Record#input_button.id;
  11. Postback ->
  12. ID = case Record#input_button.id of
  13. [] -> n2z:temp_id();
  14. I -> I
  15. end,
  16. nitro:wire(#event{type=click, postback=Postback, target=ID,
  17. source=Record#input_button.source, delegate=Record#input_button.delegate }),
  18. ID
  19. end,
  20. List = [
  21. % global
  22. {<<"accesskey">>, Record#input_button.accesskey},
  23. {<<"class">>, Record#input_button.class},
  24. {<<"contenteditable">>,
  25. case Record#input_button.contenteditable of
  26. true -> "true";
  27. false -> "false";
  28. _ -> []
  29. end},
  30. {<<"contextmenu">>, Record#input_button.contextmenu},
  31. {<<"dir">>,
  32. case Record#input_button.dir of
  33. "ltr" -> "ltr";
  34. "rtl" -> "rtl";
  35. "auto" -> "auto";
  36. _ -> []
  37. end},
  38. {<<"draggable">>,
  39. case Record#input_button.draggable of
  40. true -> "true";
  41. false -> "false";
  42. _ -> []
  43. end},
  44. {<<"dropzone">>, Record#input_button.dropzone},
  45. {<<"hidden">>,
  46. case Record#input_button.hidden of
  47. "hidden" -> "hidden";
  48. _ -> []
  49. end},
  50. {<<"id">>, Id},
  51. {<<"lang">>, Record#input_button.lang},
  52. {<<"spellcheck">>,
  53. case Record#input_button.spellcheck of
  54. true -> "true";
  55. false -> "false";
  56. _ -> []
  57. end},
  58. {<<"style">>, Record#input_button.style},
  59. {<<"tabindex">>, Record#input_button.tabindex},
  60. {<<"title">>, Record#input_button.title},
  61. {<<"translate">>,
  62. case Record#input_button.contenteditable of
  63. "yes" -> "yes";
  64. "no" -> "no";
  65. _ -> []
  66. end},
  67. % spec
  68. {<<"autofocus">>, Record#input_button.autofocus},
  69. {<<"disabled">>,
  70. case Record#input_button.disabled of
  71. true -> "disabled";
  72. _ -> []
  73. end},
  74. {<<"name">>, Record#input_button.name},
  75. {<<"type">>, <<"button">>},
  76. {<<"value">>, Record#input_button.value} | Record#input_button.data_fields
  77. ],
  78. wf_tags:emit_tag(<<"input">>, nitro:render(Record#input_button.body), List).