Hi Tomas, > in picoLisp-3.0.4 you introduced drag & drop upload field. How can I > enable it in the following script?
Basically by just using the '+Drop' prefix class for the button. > #!/home/tomas/picoLisp-3.0.4/bin/picolisp /home/tomas/picoLisp-3.0.4/lib.l > > (load "@lib/misc.l") > > (allowed () "@start" "@stop" "favicon.ico" "lib.css") > > (load "@lib/http.l" "@lib/xhtml.l" "@lib/form.l") > > (de *Dir "data/") > (de *Port0 . 4542) > > (de upload () > (let F (val> (field -1)) > (ifn (and F > (=T (call 'mv (tmp F) *Dir)) ) > (html 0 "Upload" *Css NIL > (<div> '(id . main) > (<p> NIL "Nothing uploaded") > (<href> "Back" (pack "http://" *Host ":" *Port0)) ) ) > (html 0 "Upload" *Css NIL > (<div> '(id . main) > (<p> NIL "Upload successful") > (<href> "Back" (pack "http://" *Host ":" *Port0)) ) ) ) ) > (bye) ) > > (de start () > (setq *Url "@start") > (and (app) (setq *Menu 3)) > (action > (html 0 "Upload" *Css NIL > (<div> '(id . main) > (<h2> NIL "Upload File") > (form NIL > (gui '(+UpField)) > (gui '(+Button) "Upload" '(upload)) ) ) ) ) ) Change this to (form NIL (gui '(+UpField)) (gui '(+Drop +Button) '(field -1) "Upload" '(upload) ) ) ) ) ) ) Then you just drag the file onto the button. The button changes to a percentage progress display until all data are transferred. However: This will probably not work this way, for two reasons: 1. The action for the button 'upload' does some strange things by generating its own HTML page. This is not the intended way, because a button press should usually not generate a new page. The old page (the form) must stay in control. 2. For the same reason, the (bye) at the end of 'upload' will stop things from working. I would write 'upload' this way (de upload () (let F (val> (field -1)) (ifn (and F (call 'mv (tmp F) *Dir)) (alert NIL "Nothing uploaded") (alert NIL "Upload successful") ) ) ) Instead of the alerts, you could also put a +TextField onto the original form to display proper messages, or (this is how I would do it), display no message on success, and an error on failure: (de upload () (let F (val> (field -1)) (unless (and F (call 'mv (tmp F) *Dir)) (err "Nothing uploaded") ) ) ) A separate function is not needed (just takes up space when the page is not loaded), I would write the button action directly in place: (form NIL (gui '(+UpField)) (gui '(+Drop +Button) '(field -1) "Upload" '(let F (val> (field -1)) (unless (and F (call 'mv (tmp F) *Dir)) (err "Nothing uploaded") ) ) ) ) ) ) ) ) Cheers, - Alex -- UNSUBSCRIBE: mailto:[email protected]?subject=unsubscribe
