Permalink
Browse files

fix the playlist sortable/rm/add tracks

  • Loading branch information...
1 parent 16bb867 commit 8920e614b56426c907412d3147426f8466f05ee2 @dmelo committed May 18, 2012
@@ -51,8 +51,11 @@ public function searchAction()
public function saveAction()
{
if ($this->_request->isPost()) {
+ $playlist = $this->_request->getPost('playlist');
+ for($i = 0; $i < count($playlist); $i++)
+ $playlist[$i]['url'] = $playlist[$i]['mp3'];
$this->_session->playlist = array(
- $this->_request->getPost('playlist'),
+ $playlist,
$this->_request->getPost('name')
);
if (isset($this->_session->user))
@@ -6,7 +6,7 @@ public function insert($data)
{
// filtering fields.
$data['title'] = str_replace(array('"', '\'', '/'), array('', '', ''), strip_tags($data['title']));
- $data['url'] = preg_replace("/[^a-zA-Z0-9 :\.\/%]+/", "", $data['url']);
+ $data['url'] = preg_replace("/[^a-zA-Z0-9 :\.\/%-_]+/", "", $data['url']);
if (array_key_exists('mp3', $data)) {
View
@@ -67,6 +67,7 @@ function rmTrack(url, playlistName) {
url: url
}, function(data) {
$.bootstrapMessageAuto(data[0], data[1]);
+ console.log(myPlaylist.original);
if('error' === data[1])
loadPlaylist(playlistName);
}, 'json');
@@ -329,6 +329,7 @@
this._initPlaylist([]);
this._refresh(function() {
$(self.cssSelector.jPlayer).jPlayer("clearMedia");
+ self.scan();
});
return true;
} else {
@@ -372,6 +373,7 @@
}
self.removing = false;
+ self.scan();
});
}
return true;
@@ -467,16 +469,29 @@
var isAdjusted = false;
var replace = [];
+ var maxName = 0; // maximum value that name attribute assumes.
$.each($(this.cssSelector.playlist + " ul li"), function(index, value) {
- replace[index] = self.original[$(value).attr('name')];
- if(!isAdjusted && self.current === parseInt($(value).attr('name'), 10)) {
- self.current = index;
- isAdjusted = true;
+ if($(value).attr('name') > maxName)
+ maxName = parseInt($(value).attr('name'));
+ });
+
+ var diffCount = maxName + 1 != $(this.cssSelector.playlist + " ul li").length; // Flag that marks if the number of "ul li" elements doesn't match the name attribute counting.
+
+ $.each($(this.cssSelector.playlist + " ul li"), function(index, value) {
+ if(!diffCount) {
+ replace[index] = self.original[$(value).attr('name')];
+ if(!isAdjusted && self.current === parseInt($(value).attr('name'), 10)) {
+ self.current = index;
+ isAdjusted = true;
+ }
}
$(value).attr('name', index);
});
- this.original = replace;
- this._originalPlaylist();
+
+ if(!diffCount) {
+ this.original = replace;
+ this._originalPlaylist();
+ }
},
setCurrent: function(current) {
this.current = current;

0 comments on commit 8920e61

Please sign in to comment.