Patrick Kolla's wizard stuff

This commit is contained in:
Ron Pedde 2005-11-01 23:55:20 +00:00
parent de86bbd5ad
commit 5da8c6a44e
5 changed files with 359 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $Id$ */
* $Id$ */
I've received lots of help from people on this project.
@ -110,6 +110,5 @@ Phil Packer
Diego Penneno
* Patches for multiple PID files to facilitate gentoo init scripts
Patrick Kolla
* Popup "wizard" for smart playlists

View File

@ -14,5 +14,5 @@ EXTRA_DIST = ftr.html linkOpaque.gif status.html aspl-license.txt \
mt-daapd.css mt-daapd.png config.html index.html required.gif \
gpl-license.html aspl-license.html thanks.html feedback.html \
playlist.html playlist.js smart.html smart.js DAAPApplet-0.1.jar \
applet.html CREDITS
smartpopup.html applet.html CREDITS

View File

@ -3,9 +3,8 @@
<div class="stx">
<h2>Smart Playlists</h2>
<table width="400">
<thead><th>ID</th><th>Playlist Name</th><th>Type</th><th>Action</th></thead>
<thead><tr><th>ID</th><th>Playlist Name</th><th>Type</th><th>Action</th></tr></thead>
<tbody id="playlists">
</tbody>
</table>
@ -16,12 +15,12 @@
<div id="pl_editor" style="display:none">
<h3>Playlist Spec</h3>
<form name="pl_form">
<input type="hidden" name="playlist_id">
<form name="pl_form" action="">
<input type="hidden" name="playlist_id"/>
<table width="400">
<tr>
<th>Name</th>
<td><input type="text" name="playlist_name"></td>
<td><input type="text" name="playlist_name"/></td>
</tr>
<tr>
@ -30,8 +29,9 @@
</tr>
</table>
<input type="button" onclick="javascript:pl_update();" name="submit_button" value="Submit">
<input type="button" onclick="javascript:pl_cancel();" value="Cancel">
<input type="button" onclick="javascript:pl_update();" name="submit_button" value="Submit"/>
<input type="button" onclick="javascript:pl_cancel();" value="Cancel"/>
<input type="button" onclick="javascript:pl_popup('smartpopup.html');" value="Wizard"/>
</form>
</div>

View File

@ -2,6 +2,12 @@ var req;
var playlist_info={};
function pl_popup(URL) {
day = new Date();
id = day.getTime();
eval("pagemtdaapdplPop = window.open(URL, 'mtdaapdple', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=240,left = 320,top = 448');");
}
function pl_editor_state(state) {
var pleditor = document.getElementById("pl_editor");
if(!pleditor)

342
admin-root/smartpopup.html Executable file
View File

@ -0,0 +1,342 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>mt-daapd playlist wizard</title></head>
<script language="JavaScript" type="text/javascript">
function loadOpenerCriteria()
{
objSpec = window.opener.document.getElementsByName("playlist_spec");
args = objSpec[0].value.split(" ");
comb = '';
// 1. Convert string params with spaces to single array entries
i = 2;
while (i<args.length)
{ s = args[i];
cB = s.charAt(0);
cE = s.charAt(s.length-1);
if ( (cB=='"') & (cE!='"'))
{ j = i;
do
{ j++;
s += (" "+args[j]);
cE = s.charAt(s.length-1);
} while (cE!='"');
args.splice(i,(j-i+1),s);
}
i += 4;
}
// 2. Parse array into list
if (((args.length%4)==3))
{ critIndex = Math.round(args.length / 4);
critMax = critIndex;
while (args.length>=3)
{ eleData = args.pop();
eleComp = args.pop();
eleField = args.pop();
plSetCriterion(critIndex,eleField,eleComp,eleData);
if (args.length>0)
{ if (critIndex==critMax)
{ comb = args.pop(); }
else { blub = args.pop(); }
critIndex--;
}
}
if (comb=='AND') plSetCriteriaCombination(0);
else if (comb=='OR') plSetCriteriaCombination(1);
}
}
function blocking(nr)
{
if (document.layers)
{
current = (document.layers[nr].display == 'none') ? 'block' : 'none';
document.layers[nr].display = current;
}
else if (document.all)
{
current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
document.all[nr].style.display = current;
}
else if (document.getElementById)
{
vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
document.getElementById(nr).style.display = vista;
}
}
function visi(nr)
{
if (document.layers)
{
vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
document.layers[nr].visibility = vista;
}
else if (document.all)
{
vista = (document.all[nr].style.visibility == 'hidden') ? 'visible' : 'hidden';
document.all[nr].style.visibility = vista;
}
else if (document.getElementById)
{
vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
document.getElementById(nr).style.visibility = vista;
}
}
function plRowHide(x)
{ //objRow = document.getElementById("rowcrit"+x);
//objRow.visible = false;
//visi("rowcrit"+x);
}
function plRowShow(x)
{ //objRow = document.getElementById("rowcrit"+x);
//objRow.visible = true;
//visi("rowcrit"+x);
// vista = (document.getElementById("rowcrit"+x).style.visibility == 'hidden') ? 'visible' : 'hidden';
// vista = 'visible';
// document.getElementById("rowcrit"+x).style.visibility = vista;
}
function plOutputRow(x,vis)
{ document.write('<tr id="rowcrit',x,'" style="visibility:');
document.write(vis?'visible':'hidden');
document.write(';"><th>Criterion ',x,':<\/th>',
'<td><select name="playlist_crit',x,'field" style="width:100%" onChange="javascript:plUpdateComp(\'',x,'\');plTemplateWizard()">',
'<optgroup label="Basic">',
'<option value="title">Title<\/option>',
'<option value="artist">Artist<\/option>',
'<option value="album">Album<\/option>',
'<option value="genre">Genre<\/option>',
'<option value="year">Year<\/option>',
'<option value="rating">Rating<\/option>',
'<option value="songlength">Length<\/option>',
'<option value="playcount">Play count<\/option>',
'<\/optgroup>',
'<optgroup label="Advanced">',
'<option value="track">Track<\/option>',
'<option value="totaltracks">Tracks total<\/option>',
'<option value="disc">Disc<\/option>',
'<option value="totaldiscs">Discs total<\/option>',
'<option value="comment">Comment<\/option>',
'<option value="type">Type<\/option>',
'<option value="composer">Composer<\/option>',
'<option value="orchestra">Orchestra<\/option>',
'<option value="grouping">Grouping<\/option>',
'<option value="url">URL<\/option>',
'<option value="description">Description<\/option>',
'<\/optgroup>',
'<optgroup label="Technical">',
'<option value="bitrate">Bitrate<\/option>',
'<option value="samplerate">Samplerate<\/option>',
'<option value="filesize">Filesize<\/option>',
'<option value="bpm">Beats per minute<\/option>',
'<option value="compilation">Compilation<\/option>',
'<\/optgroup>',
'<\/select><\/td>',
'<td><select name="playlist_crit',x,'comp" style="width:100%" onChange="javascript:plTemplateWizard()">',
'<option value="=">=<\/option>',
'<\/select><\/td>',
'<td><input name="playlist_crit',x,'data" onChange="javascript:plTemplateWizard()" style="width:100%"/><\/td>');
document.write('<\/tr>');
}
function plGetCriterion(x)
{ objField = document.getElementsByName("playlist_crit"+x+"field");
objComp = document.getElementsByName("playlist_crit"+x+"comp");
objData = document.getElementsByName("playlist_crit"+x+"data");
y = '';
if ((objField[0].value=='artist')
|| (objField[0].value=='title')
|| (objField[0].value=='album')
|| (objField[0].value=='genre')
|| (objField[0].value=='comment')
|| (objField[0].value=='type')
|| (objField[0].value=='composer')
|| (objField[0].value=='orchestra')
|| (objField[0].value=='conductor')
|| (objField[0].value=='grouping')
|| (objField[0].value=='url')
|| (objField[0].value=='description')
|| (objField[0].value=='codectype'))
y = '"';
return objField[0].value+' '+objComp[0].value+' '+y+objData[0].value+y;
}
function plSetCriterion(x,field,comp,data)
{ objField = document.getElementsByName("playlist_crit"+x+"field");
objField[0].value = field;
plUpdateComp(x);
objComp = document.getElementsByName("playlist_crit"+x+"comp");
objData = document.getElementsByName("playlist_crit"+x+"data");
objComp[0].value = comp;
objData[0].value = data;
}
function plSetCriteriaCombination(x)
{ objSep = document.getElementsByName("playlist_combine");
objSep[x].checked = true;
}
function plIsUsed(x)
{ objData = document.getElementsByName("playlist_crit"+x+"data");
if (objData[0].value!='') return true; else return false;
}
function plTemplateWizard()
{ objSpec = window.opener.document.getElementsByName("playlist_spec");
objSep = document.getElementsByName("playlist_combine");
if (objSep[0].checked) sep = ' AND '; else sep = ' OR ';
criteria = plGetCriterion('1');
if (plIsUsed('2')) criteria = criteria + sep + plGetCriterion('2');
objSpec[0].value = criteria;
}
function plUpdateComp(x)
{ objField = document.getElementsByName("playlist_crit"+x+"field");
objComp = document.getElementsByName("playlist_crit"+x+"comp");
objComp[0].options.length = 0;
objComp[0].options[0] = new Option('=','=');
if ((objField[0].value=='artist')
|| (objField[0].value=='title')
|| (objField[0].value=='album')
|| (objField[0].value=='genre')
|| (objField[0].value=='comment')
|| (objField[0].value=='type')
|| (objField[0].value=='composer')
|| (objField[0].value=='orchestra')
|| (objField[0].value=='conductor')
|| (objField[0].value=='grouping')
|| (objField[0].value=='url')
|| (objField[0].value=='codectype'))
{ objComp[0].options[1] = new Option('includes','includes');
} else
{ objComp[0].options[1] = new Option('>','>');
objComp[0].options[2] = new Option('>=','>=');
objComp[0].options[3] = new Option('<','<');
objComp[0].options[4] = new Option('<=','<=');
}
}
function plTemplatePlaylist()
{ objSpec = window.opener.document.getElementsByName("playlist_spec");
objName = window.opener.document.getElementsByName("playlist_name");
objTemplate = document.getElementsByName("playlist_template");
switch (objTemplate[0].value)
{ case "60s":
objSpec[0].value = 'year >= 1960 AND year <= 1970';
objName[0].value = 'Music from the 60\'s';
plSetCriterion(1,'year','>=','1960');
plSetCriterion(2,'year','<=','1970');
plSetCriterion(3,'title','=','');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(0);
break;
case "70s":
objSpec[0].value = 'year >= 1970 AND year <= 1980';
objName[0].value = 'Music from the 70\'s';
plSetCriterion(1,'year','>=','1970');
plSetCriterion(2,'year','<=','1980');
plSetCriterion(3,'title','=','');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(0);
break;
case "80s":
objSpec[0].value = 'year >= 1980 AND year <= 1990';
objName[0].value = 'Music from the 80\'s';
plSetCriterion(1,'year','>=','1980');
plSetCriterion(2,'year','<=','1990');
plSetCriterion(3,'title','=','');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(0);
break;
case "90s":
objSpec[0].value = 'year >= 1990 AND year <= 2000';
objName[0].value = 'Music from the 90\'s';
plSetCriterion(1,'year','>=','1990');
plSetCriterion(2,'year','<=','2000');
plSetCriterion(3,'title','=','');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(0);
break;
case "00s":
objSpec[0].value = 'year >= 2000';
objName[0].value = 'Music from today';
plSetCriterion(1,'year','>=','2000');
plSetCriterion(2,'title','=','');
plSetCriterion(3,'title','=','');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(0);
break;
case "metal":
objSpec[0].value = 'genre includes "Metal" OR genre includes "Goth" OR genre includes "Hard"';
objName[0].value = 'Metalheads';
plSetCriterion(1,'genre','includes','Metal');
plSetCriterion(2,'genre','includes','Goth');
plSetCriterion(3,'genre','includes','Hard');
plSetCriterion(4,'title','=','');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(1);
break;
case "psych":
objSpec[0].value = 'genre includes "psych" OR genre includes "Psych" OR genre includes "Synth" OR ARTIST = "Pink Floyd"';
objName[0].value = 'Psychosynth';
plSetCriterion(1,'genre','includes','psych');
plSetCriterion(2,'genre','includes','Psych');
plSetCriterion(3,'genre','includes','Synth');
plSetCriterion(4,'artist','=','Pink Floyd');
plSetCriterion(5,'title','=','');
plSetCriteriaCombination(1);
break;
case "":
objName[0].value = 'Custom playlist';
break;
}
}
</script>
<body onLoad="loadOpenerCriteria();">
<form name="pleditor" action="">
<input type="hidden" name="playlist_id"/>
<table style="border:1px solid black;" width="100%">
<tr><th colspan="4">Wizard</th></tr>
<tr><th>Template:</th>
<td colspan="3"><select name="playlist_template" style="width:100%" onChange="javascript:plTemplatePlaylist()">
<option value="" selected="SELECTED">Custom playlist</option>
<option value="60s">Music from the 60's</option>
<option value="70s">Music from the 70's</option>
<option value="80s">Music from the 80's</option>
<option value="90s">Music from the 90's</option>
<option value="00s">Music from today</option>
<option value="metal">Metalheads</option>
<option value="psych">Psychosynth</option>
</select></td></tr>
<script language="JavaScript" type="text/javascript">
plOutputRow(1,true);
plOutputRow(2,true);
plOutputRow(3,true);
plOutputRow(4,true);
plOutputRow(5,true);
</script>
<tr><th>Combine:</th>
<td colspan="3">
<input type="radio" name="playlist_combine" value=" AND " checked="CHECKED" onChange="javascript:plTemplateWizard()"> match all
<input type="radio" name="playlist_combine" value=" OR " onChange="javascript:plTemplateWizard()"> match some
</td></tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
loadOpenerCriteria();
</script>
</body></html>