mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Playlist reordering with drag'n drop working.
This commit is contained in:
parent
0599214703
commit
2e1ae29f17
7 changed files with 76 additions and 67 deletions
|
@ -319,10 +319,10 @@ class Playlist extends playlist_object
|
|||
* update_track_number
|
||||
* This takes a playlist_data.id and a track (int) and updates the track value
|
||||
*/
|
||||
public function update_track_number($track_id,$track)
|
||||
public function update_track_number($track_id, $index)
|
||||
{
|
||||
$sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ? AND `playlist` = ?";
|
||||
$db_results = Dba::write($sql, array($track, $track_id, $this->id));
|
||||
$sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ?";
|
||||
$db_results = Dba::write($sql, array($index, $track_id));
|
||||
|
||||
} // update_track_number
|
||||
|
||||
|
@ -417,8 +417,7 @@ class Playlist extends playlist_object
|
|||
} // end while results
|
||||
|
||||
foreach ($results as $data) {
|
||||
$sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ?";
|
||||
$db_results = Dba::write($sql, array($data['track'], $data['id']));
|
||||
self::update_track_number($data['id'], $data['track']);
|
||||
} // foreach re-ordered results
|
||||
|
||||
return true;
|
||||
|
|
|
@ -108,20 +108,29 @@ function check_inline_song_edit(type, song) {
|
|||
$(document).ready(function () {
|
||||
$('#sortableplaylist').sortable({
|
||||
axis: 'y',
|
||||
delay: 200,
|
||||
start: function (event, ui) {
|
||||
$(ui.item).data("startindex", ui.item.index());
|
||||
},
|
||||
stop: function (event, ui) {
|
||||
playlistUpdatedIndex(ui.item);
|
||||
}
|
||||
delay: 200
|
||||
});
|
||||
});
|
||||
|
||||
function playlistUpdatedIndex(item) {
|
||||
var startIndex = item.data("startindex");
|
||||
var newIndex = item.index();
|
||||
if (newIndex != startIndex) {
|
||||
alert('Start index {' + startIndex + '} Stop index {' + newIndex + '}');
|
||||
function submitPlaylistOrder(playlistUrl, tableid) {
|
||||
|
||||
var table = document.getElementById(tableid);
|
||||
var rowLength = table.rows.length;
|
||||
var finalOrder = '';
|
||||
|
||||
for (var i = 0; i < rowLength; ++i) {
|
||||
var row = table.rows[i];
|
||||
if (row.id != '') {
|
||||
var songid = row.id.replace('track_', '');
|
||||
finalOrder += songid + ";"
|
||||
}
|
||||
}
|
||||
|
||||
if (finalOrder != '') {
|
||||
$.ajax({
|
||||
url : playlistUrl,
|
||||
type : 'GET',
|
||||
data : 'order=' + finalOrder
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
33
playlist.php
33
playlist.php
|
@ -37,7 +37,6 @@ if ($_REQUEST['action'] == 'delete_playlist') {
|
|||
|
||||
UI::show_header();
|
||||
|
||||
|
||||
/* Switch on the action passed in */
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'add_dyn_song':
|
||||
|
@ -49,7 +48,6 @@ switch ($_REQUEST['action']) {
|
|||
|
||||
$playlist->add_dyn_song();
|
||||
$_SESSION['data']['playlist_id'] = $playlist->id;
|
||||
show_playlist($playlist);
|
||||
break;
|
||||
case 'create_playlist':
|
||||
/* Check rights */
|
||||
|
@ -61,9 +59,9 @@ switch ($_REQUEST['action']) {
|
|||
$playlist_name = scrub_in($_REQUEST['playlist_name']);
|
||||
$playlist_type = scrub_in($_REQUEST['type']);
|
||||
|
||||
$playlist->create($playlist_name,$playlist_type);
|
||||
$playlist->create($playlist_name, $playlist_type);
|
||||
$_SESSION['data']['playlist_id'] = $playlist->id;
|
||||
show_confirmation(T_('Playlist Created'), sprintf(T_('%1$s (%2$s) has been created'), $playlist_name, $playlist_type),'playlist.php');
|
||||
show_confirmation(T_('Playlist Created'), sprintf(T_('%1$s (%2$s) has been created'), $playlist_name, $playlist_type), 'playlist.php');
|
||||
break;
|
||||
case 'delete_playlist':
|
||||
// If we made it here, we didn't have sufficient rights.
|
||||
|
@ -76,7 +74,6 @@ switch ($_REQUEST['action']) {
|
|||
break;
|
||||
}
|
||||
$playlist->remove_songs($_REQUEST['song']);
|
||||
show_playlist($playlist);
|
||||
break;
|
||||
case 'show_playlist':
|
||||
$playlist = new Playlist($_REQUEST['playlist_id']);
|
||||
|
@ -115,20 +112,34 @@ switch ($_REQUEST['action']) {
|
|||
show_confirmation($title, $body, Config::get('web_path') . '/playlist.php?action=' . $url);
|
||||
break;
|
||||
case 'set_track_numbers':
|
||||
debug_event('playlist', 'Set track numbers called.', '5');
|
||||
|
||||
$playlist = new Playlist($_REQUEST['playlist_id']);
|
||||
|
||||
/* Make sure they have permission */
|
||||
if (!$playlist->has_access()) {
|
||||
UI::access_denied();
|
||||
break;
|
||||
}
|
||||
$song_ids = scrub_in($_REQUEST['song']);
|
||||
foreach ($song_ids as $song_id) {
|
||||
$track = scrub_in($_REQUEST['tr_' . $song_id]);
|
||||
$changes[] = array('song_id' => $song_id, 'track' => $track);
|
||||
|
||||
// Retrieving final song order from url
|
||||
foreach ($_GET as $key => $data) {
|
||||
$_GET[$key] = unhtmlentities(scrub_in($data));
|
||||
debug_event('playlist', $key.'='.$_GET[$key], '5');
|
||||
}
|
||||
|
||||
$playlist->update_track_numbers($changes);
|
||||
if (isset($_GET['order'])) {
|
||||
$songs = explode(";", $_GET['order']);
|
||||
$track = 1;
|
||||
foreach ($songs as $song_id) {
|
||||
if ($song_id != '') {
|
||||
$playlist->update_track_number($song_id, $track);
|
||||
++$track;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show_playlist($playlist);
|
||||
//require Config::get('prefix') . '/templates/show_playlist.inc.php';
|
||||
break;
|
||||
case 'prune_empty':
|
||||
/* Make sure they have permission */
|
||||
|
|
|
@ -40,6 +40,10 @@ UI::show_box_top('<div id="playlist_row_' . $playlist->id . '">' . $title .
|
|||
<a href="<?php echo Config::get('web_path'); ?>/playlist.php?action=normalize_tracks&playlist_id=<?php echo $playlist->id; ?>"><?php echo UI::get_icon('statistics', T_('Normalize Tracks')); ?></a>
|
||||
<?php echo T_('Normalize Tracks'); ?>
|
||||
</li>
|
||||
<li>
|
||||
<a onclick="submitPlaylistOrder('<?php echo Config::get('web_path'); ?>/playlist.php?action=set_track_numbers&playlist_id=<?php echo $playlist->id; ?>', 'reorder_playlist_table');"><?php echo UI::get_icon('download', T_('Save Tracks Order')); ?></a>
|
||||
<?php echo T_('Save Tracks Order'); ?>
|
||||
</li>
|
||||
<?php if (Access::check_function('batch_download')) { ?>
|
||||
<li>
|
||||
<a href="<?php echo Config::get('web_path'); ?>/batch.php?action=playlist&id=<?php echo $playlist->id; ?>"><?php echo UI::get_icon('batch_download', T_('Batch Download')); ?></a>
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
<td class="cel_artist"><?php echo $song->f_artist_link; ?></td>
|
||||
<td class="cel_album"><?php echo $song->f_album_link; ?></td>
|
||||
<td class="cel_genre"><?php echo $song->f_tags; ?></td>
|
||||
<td class="cel_track"><?php echo $song->f_track; ?></td>
|
||||
<td class="cel_time"><?php echo $song->f_time; ?></td>
|
||||
<?php if (Config::get('ratings')) { ?>
|
||||
<td class="cel_rating" id="rating_<?php echo $song->id; ?>_song"><?php Rating::show($song->id,'song'); ?></td>
|
||||
|
|
|
@ -23,22 +23,8 @@
|
|||
$web_path = Config::get('web_path');
|
||||
?>
|
||||
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||
<table class="tabledata" cellpadding="0" cellspacing="0">
|
||||
<colgroup>
|
||||
<col id="col_directplay" />
|
||||
<col id="col_add" />
|
||||
<col id="col_track" />
|
||||
<col id="col_song" />
|
||||
<col id="col_artist" />
|
||||
<col id="col_album" />
|
||||
<col id="col_genre" />
|
||||
<col id="col_track" />
|
||||
<col id="col_time" />
|
||||
<col id="col_rating" />
|
||||
<col id="col_userflag" />
|
||||
<col id="col_action" />
|
||||
</colgroup>
|
||||
<tbody id="sortableplaylist">
|
||||
<form method="post" id="reorder_playlist_<?php echo $playlist->id; ?>">
|
||||
<table id="reorder_playlist_table" class="tabledata" cellpadding="0" cellspacing="0">
|
||||
<tr class="th-top">
|
||||
<?php if (Config::get('directplay')) { ?>
|
||||
<th class="cel_directplay"><?php echo T_('Play'); ?></th>
|
||||
|
@ -49,7 +35,6 @@ $web_path = Config::get('web_path');
|
|||
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
||||
<th class="cel_album"><?php echo T_('Album'); ?></th>
|
||||
<th class="cel_genre"><?php echo T_('Genre'); ?></th>
|
||||
<th class="cel_track"><?php echo T_('Track'); ?></th>
|
||||
<th class="cel_time"><?php echo T_('Time'); ?></th>
|
||||
<?php if (Config::get('ratings')) {
|
||||
Rating::build_cache('song', array_map(create_function('$i', 'return $i[\'object_id\'];'), $object_ids));
|
||||
|
@ -63,8 +48,9 @@ $web_path = Config::get('web_path');
|
|||
<?php } ?>
|
||||
<th class="cel_action"><?php echo T_('Action'); ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($object_ids as $object) {
|
||||
|
||||
<tbody id="sortableplaylist">
|
||||
<?php foreach ($object_ids as $object) {
|
||||
$song = new Song($object['object_id']);
|
||||
$song->format();
|
||||
$playlist_track = $object['track'];
|
||||
|
@ -73,6 +59,8 @@ $web_path = Config::get('web_path');
|
|||
<?php require Config::get('prefix') . '/templates/show_playlist_song_row.inc.php'; ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
|
||||
<tr class="th-bottom">
|
||||
<?php if (Config::get('directplay')) { ?>
|
||||
<th class="cel_directplay"><?php echo T_('Play'); ?></th>
|
||||
|
@ -83,7 +71,6 @@ $web_path = Config::get('web_path');
|
|||
<th class="cel_artist"><?php echo T_('Artist'); ?></th>
|
||||
<th class="cel_album"><?php echo T_('Album'); ?></th>
|
||||
<th class="cel_genre"><?php echo T_('Genre'); ?></th>
|
||||
<th class="cel_track"><?php echo T_('Track'); ?></th>
|
||||
<th class="cel_time"><?php echo T_('Time'); ?></th>
|
||||
<?php if (Config::get('ratings')) { ?>
|
||||
<th class="cel_rating"><?php echo T_('Rating'); ?></th>
|
||||
|
@ -93,6 +80,6 @@ $web_path = Config::get('web_path');
|
|||
<?php } ?>
|
||||
<th class="cel_action"><?php echo T_('Action'); ?></th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</table>
|
||||
</form>
|
||||
<?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue