--- /dev/null
+var button = document.querySelector('#savebutton');
+var formdata_old = '';
+var formdata = '';
+
+function postsubmit(){
+ if ( this.status == 200 ) {
+ console.log('successful auto submit of form data');
+ button.setAttribute('style', 'display: none;');
+ } else {
+ console.log('!!! Error response while auto submitting form data');
+ button.setAttribute('style', 'display: block;');
+ }
+}
+function failsubmit(){
+ console.log('!!! Timeout while auto submitting form data');
+ button.setAttribute('style', 'display: block;');
+}
+
+function formencode(fd){
+ var send;
+ send='autosubmit=false';
+ for (var tup of fd.entries()){
+ send += '&' + encodeURIComponent(tup[0]) + '=' + encodeURIComponent(tup[1]);
+ }
+ return send;
+}
+
+function formsend(){
+ var request = new XMLHttpRequest();
+ request.open('post', '/therapies/update_therapy.sh');
+ request.timeout = 5000;
+ request.onload = postsubmit;
+ request.ontimeout = failsubmit;
+ request.onerror = failsubmit;
+ request.onabort = failsubmit;
+
+ formdata = formencode(new FormData(document.querySelector('#report')));
+
+ if ( ! (formdata == formdata_old) ) {
+ console.log( 'send' );
+ request.send( formdata );
+ formdata_old = formdata;
+ }
+}
+
+formdata_old = formencode(new FormData(document.querySelector('#report')));
+button.setAttribute('style', 'display: none;');
+setInterval(formsend, 500);
[canvas #canvas .dotmark .ov width="${bg_dim%x*}" height="${bg_dim#*x}" ]
[input type=hidden #image_serialize name=imagedata value=""]
- [button type=submit $(l10n save)]
+ [button #savebutton type=submit $(l10n save)]
]
[span #jsdebug style="display: none; position: fixed; right:0; bottom:0" Debug]
[script type="text/javascript" src="/therapies/therapy_draw.js"]
+[script type="text/javascript" src="/therapies/autosave.js"]
EOF
;;
*) printf %s:%s\\n "$key" "$(POST "$key" |sed ':X;N;$!bX; s;\n;\\n;g;')" ;;
esac
-done >"$tempfile"
+done >"$tempfile" 2>&-
if [ "$(POST delete_session)" ]; then
n="$(POST delete_session)"
mv "$tempfile" "$tpyfile"
rm -f "${_DATA}/cache/${tpy%%.*}.vcf.cache"
-REDIRECT "/therapies/${tpy%.*}/${tpy#*.}"
+if [ "$(POST autosubmit)" = "true" ]; then
+ printf 'HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n'
+else
+ REDIRECT "/therapies/${tpy%.*}/${tpy#*.}"
+fi