#!/mod/bin/jimsh

package require cgi
source /mod/webif/lib/setup
require ts.class system.class pretty_size

jscss script.js style.css
jqplugin touchpunch
header

set rfile [cgi_get file]
set ts [ts fetch $rfile]
set dir [string map {' \\'} [file dirname $rfile]]
set erfile [string map {' \\'} $rfile]

set len [$ts duration 1]

set start -1
set incr 1
set limit $(1-$start)

puts "
<script type=text/javascript>
var len = [$ts duration 1];
var file = '$erfile';
var dir = '$dir';
</script>
<fieldset class=cleft>
<legend>Manage Bookmarks</legend>

<table class=keyval>
<tr><th>File:</th><td>$rfile</td></tr>
<tr><th>Length:</th><td>[clock format $len -format %T]</td></tr>
<tr><th>Size:</th><td>[pretty_size [$ts size]] ([$ts get definition])</td></tr>
<tr><th>Bookmarks<br><span class=footnote>(enter in seconds)</span></th><td>
<input id=bookmarks size=80 maxlength=255 value=\"[$ts bookmarks]\" />
<button id=update>Update</button>
<br>
<span id=bookmarkstime></span>
</td></tr><tr><td class=cell-align-right>
<button class=left id=addbmark>Add Bookmark</button>
<button class=left id=delbmark>Remove Bookmark</button>
</td><td><div id=slider></div></td></tr>
<tr><td class=cell-align-right>
<span class=left>Current: <span id=curbmk></span></span><br><br><br>
"
if {![$ts flag "ODEncrypted"]} {
	puts "
<button id=genthumbs title=\"Generate Thumbnails\"
    class=left>Generate Thumbnails</button>
"
}
puts "
</td><td>
<div id=thumbs class=hidden>
<table><tr>
"
set times {}
loop v $start $limit $incr {
	lappend times $v
	puts "
		<th class=mark><span class=mark>
		[format "%+d" $v]</span>s</th>
	"
}
puts "</tr><tr>"
foreach v $times {
	puts "<td><img class=bmp data-pos=$v alt=\"thumbnail @ $v s\"></td>"
}
puts "
</tr></table>
</div></td></tr>
</table>
<div id=buttons>
<button id=save>Save Bookmarks</button>
<button id=back>Back to Media Browser</button>
"
if {[system pkginst nicesplice]} {
	puts "<button id=crop>Go to Crop</button>"
}
puts "
</div>
<div id=results class=\"hidden blood\"></div>
</fieldset>
"

footer

