#!/mod/bin/jimsh

puts {

<div id=jbar></div>

<ul id=optmenu class=contextMenu style="width: 160px">
	<li class=delete><a href=#delete>Delete</a></li>
	<li class=cut><a href=#cut>Cut to clipboard</a></li>
	<li class=pwcopy><a href=#copy>Copy to clipboard</a></li>

	<li class="separator rename"><a href=#rename>Rename</a></li>
	<li class=download><a href=#download>Download</a></li>

	<li class="separator decrypt"><a href=#decrypt>Decrypt</a></li>
	<li class="compress"><a href=#strip>Shrink</a></li>
}
if {[system pkginst ffmpeg]} {
	puts {
		<li class=mp3><a href=#audio>Extract Audio</a></li>
		<li class=mpg><a href=#mpg>Extract to MPG</a></li>
		<li class=thm><a href=#thm>Set Thumbnail</a></li>
	}
}

puts { <li class=thm><a href=#vthm>View Thumbnail</a></li> }

puts { <li class=bookmark><a href=#bmarks>Bookmarks</a></li> }

if {$nicesplice} {
	puts {
		<li class="cut"><a href=#crop>Crop</a></li>
		<li class="cut"><a href=#chunk>Split (45m parts)</a></li>
	}
}
puts {
	<li class="separator lock"><a href=#lock>Toggle Lock</a></li>
	<li class=new><a href=#new>Toggle New</a></li>
}

if {[llength $plugins(menu)]} {
	foreach plugin $plugins(menu) {
		lassign $plugin tag options
		puts "<li class=$tag><a href=#$tag>$options(desc)</a></li>"
	}
}

puts {
</ul>

<ul id=ooptmenu class=contextMenu style="width: 160px">
	<li class=delete><a href=#delete>Delete</a></li>
	<li class=cut><a href=#cut>Cut to clipboard</a></li>
	<li class=pwcopy><a href=#copy>Copy to clipboard</a></li>

	<li class="separator rename"><a href=#rename>Rename</a></li>
	<li class="download"><a href=#download>Download</a></li>
}
if {[llength $plugins(omenu)]} {
	foreach plugin $plugins(omenu) {
		lassign $plugin tag options
		puts "<li class=$tag><a href=#$tag>$options(desc)</a></li>"
	}
}

puts {
</ul>

<ul id=dooptmenu class=contextMenu style="width: 250px">
	<li class=delete><a href=#delete>Delete</a></li>
	<li class=cut><a href=#cut>Cut to clipboard</a></li>
	<li class=pwcopy><a href=#copy>Copy to clipboard</a></li>
	<li class=pwpaste><a href=#paste>Paste to folder</a></li>
	<li class=separator><a href=#rename>Rename</a></li>
</ul>

<ul id=doptmenu class=contextMenu style="width: 250px">
	<li class=delete><a class=notself href=#delete>Delete</a></li>
	<li class=cut><a class=notself href=#cut>Cut to clipboard</a></li>
	<li class=pwcopy><a class=notself href=#copy>Copy to clipboard</a></li>
	<li class=pwpaste><a class=notself href=#paste>Paste to folder</a></li>
	<li class="separator rename"><a class=notself href=#rename>Rename</a></li>
	<li class=separator><a href=#resetnew>Reset new flag</a></li>
	<li class="separator compress"><a href=#shrink>Auto-Shrink</a></li>
	<li class=compressr><a href=#shrinkr>Recursive Auto-Shrink</a></li>
	<li class=dedup><a href=#dedup>Auto-Dedup</a></li>
	<li class=decrypt><a href=#decrypt>Auto-Decrypt</a></li>
	<li class=decryptr><a href=#decryptr>Recursive Auto-Decrypt</a></li>
	<li class=clock><a href=#expire>Auto-Expire Options</a></li>
}

if {[system pkginst ffmpeg]} {
	puts {
		<li class=mp3><a href=#mp3>Auto-Audio Extract</a></li>
		<li class=mpg><a href=#mpg>Auto-MPG Extract</a></li>
	}
}

if {[llength $plugins(dmenu)]} {
	foreach plugin $plugins(dmenu) {
		lassign $plugin tag options
		puts "<li class=$tag><a href=#$tag>$options(desc)</a></li>"
	}
}

puts {
</ul>

<div id=renameform title="Rename media file" style="display: none">
	<form id=renameform_form>
	<input type=hidden name="renamefile" id="renamefile" value="">
	<table border=0>
	<tr>
	<th>
		<label for="rename">
			<b>New Filename</b>
		</label>
	</th>
	<td>
		<input type=text name="rename" id="rename"
		    value="" size=70 maxlength=255
		    class="text ui-widget-content ui-corner-all">
	</td>
	</tr>

	<tr style="display: none" class=tstype>
	<th>
		<label for="rename_title" style="padding-top: 0.5em">
			<b>New Medialist Title</b>
		</label>
	</th>
	<td>
		<input type=text name="rename_title" id="rename_title"
		    value="" size=70 maxlength=48
		    class="text ui-widget-content ui-corner-all">
	</td>
	</tr>

	<tr style="display: none" class=tstype>
	<th>
		<label for="rename_synopsis" style="padding-top: 0.5em">
			<b>New Synopsis</b>
		</label>
	</th>
	<td>
		<textarea name="rename_synopsis" id="rename_synopsis"
		    value="" cols=70 rows=4
		    class="text ui-widget-content ui-corner-all"></textarea>
	</td>
	</tr>

	<tr style="display: none" class=tstype>
	<th>
		<label for="rename_guidance" style="padding-top: 0.5em">
			<b>New Guidance Text</b>
		</label>
	</th>
	<td>
		<input type=text name="rename_guidance" id="rename_guidance"
		    value="" size=70 maxlength=74
		    class="text ui-widget-content ui-corner-all">
	</td>
	</tr>

	<tr style="display: none" class=tstype>
	<th>
		<label for="rename_genre" style="padding-top: 0.5em">
			<b>New Genre</b>
		</label>
	</th>
	<td>
		<select name="rename_genre" id="rename_genre"
		    style="vertical-align: middle"
		    class="text ui-widget-content ui-corner-all">
}

foreach genre [dict keys $::epg::genrelist] {
	lassign $::epg::genrelist($genre) txt img
	if {$txt eq "Unknown" } continue
	if {$img eq "Unclassified"} {
		set img /images/173_3_26_G3_$img.png
	} else {
		set img /images/173_3_00_G3_$img.png
	}
	puts "<option value=$genre style=\"
	    background: url($img) no-repeat left;
	    padding: 8px 0 8px 30px;
	    vertical-align: middle;
	    \" onclick=\"this.parentNode.setAttribute('style',
            this.getAttribute('style'));\">$txt"
}

puts {
		</select>
	</td>
	</tr>

	</table>
	</form>
</div>

<div id=drenameform title="Rename directory" style="display: none">
	<form id=drenameform_form>
	<input type=hidden name="renamefile" id="drenameorig" value="">
	<table border=0>
	<tr>
	<th>
		<label for="drename">
			<b>New Directory Name</b>
		</label>
	</th>
	<td>
		<input type=text name="rename" id="drename"
		    value="" size=70 maxlength=255
		    class="text ui-widget-content ui-corner-all">
	</td>
	</tr>
	</table>
	</form>
</div>

<div id=savestreamform title="Save streamed content"
    style="display: none">
	<div class=pre id=savestream_detail></div>
	<div id=savestream_retrieving>
		<img src=/img/spin.gif> Retrieving details...
	</div>
	<form id=savestream_form class=hidden>
}
puts "<input type=hidden name=dir value=\"$dir\">"
puts {
	<table border=0>
	<tr>
	<th>
		<label for="savestream_name">
			<b>Enter Filename</b>
		</label>
	</th>
	<td>
		<input type=text name="savestream_name"
		    id="savestream_name"
		    value="" size=70 maxlength=255
		    class="text ui-widget-content ui-corner-all">
		<span id=savestream_spin>
			<img src=/img/spin.gif> Saving...
		</span>
	</td>
	</tr>
	</table>
	</form>
</div>

<div id=newdirform title="New Folder" style="display: none">
	<form id=newdirform_form>
}
puts "<input type=hidden name=dir value=\"$dir\">"
puts {
	<table border=0>
	<tr>
	<th>
		<label for="newdirname">
			<b>New Folder Name</b>
		</label>
	</th>
	<td>
		<input type=text name="newdirname" id="newdirname"
		    value="" size=70 maxlength=255
		    class="text ui-widget-content ui-corner-all">
	</td>
	</tr>
	</table>
	</form>
</div>

<div id=aexpiry title="Auto-Expiry Settings"
    style="display: none; line-height: 1em;">
	<form id=aexpiry_form>
	<input type=hidden name="dir" id="aexpiry_ldir" value="">
}
puts {
	<table border=0>

	<tr><th align=right>
		<label for="aexpiry_days">
			<b>Remove recordings after</b> (in days)
			<br><span class=footnote>
			(Leave blank to skip age check)
			</span>
		</label>
	</th><td>
		<input name="aexpiry_days" id="aexpiry_days"
		    type=number value=0 size=5 maxlength=3
		    class="text ui-widget-content ui-corner-all">
	</td></tr>

	<tr><th>
		<label for="aexpiry_min">
			<b>Keep at least</b>
			(number of recordings)
			<br>
			<span class=footnote>(Oldest will be deleted first)
			    </span>
		</label>
	</th><td>
		<input name="aexpiry_min" id="aexpiry_min"
		    type=number value=0 size=5 maxlength=3
		    class="text ui-widget-content ui-corner-all">
	</td></tr>

	<tr><th>
		<label for="aexpiry_timetype">
			<b>For date of recording, use</b>
		</label>
	</th><td>
		<input name="aexpiry_timetype" id="aexpiry_timetype0"
		    type=radio value=0 checked
		    class="text ui-widget-content ui-corner-all">
		Recording end time
		<br>
		<input name="aexpiry_timetype" id="aexpiry_timetype1"
		    type=radio value=1
		    class="text ui-widget-content ui-corner-all">
		<span>
		When last watched
		<span class=bfootnote>(or end time if unwatched)</span>
		</span>
	</td></tr>

	<tr><th>
		<label for="aexpiry_unwatched">
			<b>Never delete unwatched recordings</b>
		</label>
	</th><td>
		<input name="aexpiry_unwatched" id="aexpiry_unwatched"
		    type=checkbox value=1
		    class="ui-widget-content ui-corner-all">
	</td></tr>

	</table>
	<div id=aexpiry_working class=hidden>
		<img src=/img/spin.gif> Applying changes...
	</div>
	<div id=aexpiry_loading class=hidden>
		<img src=/img/spin.gif> Retrieving data...
	</div>
	</form>
</div>

<div id=dialogue>
<img src=/img/spin.gif>Retrieving data...
</div>

<div id=confirm title="Confirmation Required"></div>

<div id=pwdialogue style="display: none">
<center>
<img src=/img/spin.gif>
<br><br>
Please wait...
<div id=pwfeedback></div>
</center>
</div>

<div id=bmpdialogue title="Recording Thumbnail" class=hidden>
<img id=thmbmp class=doublebmp src="about:blank">
</div>
}

