Scriptaculous Inline Edit in a php script to create mp3 playlists
Well,
I got tired of linux mp3 players and their inability to manage mp3s, so I broke down
and started doing what I have been planning for along time, creating a mp3 playlist
creator to run on my local server.
I may release it as a script, as so far, it’s pretty useful, but one thing
that came up was, some of the mp3 filenames were not exactly clear. Like Track 13.mp3.
I firmly believe in the mp3 naming standard of Artist ft. Others - Song Name - Alblum.mp3.
In order to do this with the script I got a fantabulous idea, let’s use scriptaculous to edit
them in place, making it feel a bit more like an application.
I load all the files into an array, choosing the chunk I am going to list. Note, if you
have thousands of mp3s, do not try to create thousands of inline edits, it will crash, seriously
I tried it.
Instead, I paginate my files so I can surf through them easily, checking off the ones I want
to add to my playlist, then the script moves them to the specified folder.
<script src="javascripts/prototype.js"></script> <script src="javascripts/scriptaculous.js?load=effects,controls"></script> <script type="text/javascript" language="javascript"> // <![CDATA[ Event.observe(window, 'load' , function() { <?php for ($i = $start; $i <= $limit;$i++) { ?> new Ajax.InPlaceEditor('song_<?php echo $i;?>', 'rename.php?action=rename&dir=<?php echo $_GET['dir'];?>'); <?php } ?> }); // ]]> </script>
There we go, now, I just loop through the array of songs, and place things in a paragraph
with the necessary id:
<table>
<?php
//This is the equivalent of say for instance cycle. It can
//be done a million different ways, this is one of them.
//It allows for an alternating background color.
$x = 0;
for ($i = $start; $i <= $limit;$i++) {
switch ($x) {
case 0:
$x = 1;
$style = 'table-odd';
break;
case 1:
$x = 0;
$style = 'table-even';
break;
}
?>
<tr>
<td valign="top" colspan="3">
<a name="<?php echo $i;?>" />
<table class="<?php echo $style;?>" width="100%">
<tr>
<td valign="top" width="3%"><?php echo $i;?></td>
<td valign="top" width="2%"><input type="checkbox" name="song_nums[]" value="<?php echo $i;?>"> </td>
<td valign="top" width="45%">
<p id="song_<?php echo $i;?>"><?php echo $songs[$i];?></p></td>
<td valign="top"><a href="delete.php?dir=<?php echo $_GET['dir'];?>&file=<?php echo urlencode($songs[$i]);?>&anchor=<?php echo $i;?>">Delete</a></td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
</table>If someone wants me to post the whole script when it’s done, I will.