Namdak Tonpa 9 лет назад
Родитель
Сommit
07f136f8fa
2 измененных файлов с 24 добавлено и 0 удалено
  1. 3 0
      include/nitro.hrl
  2. 21 0
      src/elements/element_upload.erl

+ 3 - 0
include/nitro.hrl

@@ -176,6 +176,9 @@
 -record(u,       		?DEFAULT_BASE).
 -record(var,       		?DEFAULT_BASE).
 
+% Extras
+-record(upload,         {?CTRL_BASE(element_upload), name, value}).
+
 % Actions
 -record(action,  {?ACTION_BASE(undefined)}).
 -record(wire,    {?ACTION_BASE(action_wire)}).

+ 21 - 0
src/elements/element_upload.erl

@@ -0,0 +1,21 @@
+-module(element_upload).
+-compile(export_all).
+-include_lib("nitro/include/nitro.hrl").
+
+render_element(#upload{id=Id} = U) ->
+    Uid = case Id of undefined -> wf:temp_id(); I -> I end,
+    bind(ftp_open,  click,  "qi('upload').click(); e.preventDefault();"),
+    bind(ftp_start, click,  "ftp.start();"),
+    bind(ftp_stop,  click,  "ftp.stop();"),
+    bind(nitro:to_atom(Uid), change, "ftp.init(this.files[0],1);"),
+    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" }
+    ] } ] }, wf:render(Upload).
+
+bind(Control,Event,Code) ->
+    wf:wire(#bind{target=Control,type=Event,postback=Code}).