Browse Source

Fixed issue where editing a song would directly change the songlist, even when cancelling.

KrisVos130 8 years ago
parent
commit
57ed7dc40c

+ 14 - 5
frontend/components/Admin/QueueSongs.vue

@@ -113,9 +113,15 @@
 				else if (type == 'artists') this.editing.song.artists.splice(index, 1);
 			},
 			edit: function (song, index) {
-				this.editing = { index, song };
-				this.video.player.loadVideoById(song._id);
-				this.isEditActive = true;
+				if (this.video.player) {
+					this.video.player.loadVideoById(song._id);
+					let songCopy = {};
+					for (let n in song) {
+						songCopy[n] = song[n];
+					}
+					this.editing = { index, song: songCopy };
+					this.isEditActive = true;
+				}
 			},
 			save: function (song) {
 				let _this = this;
@@ -175,10 +181,13 @@
 						if (volume > 0) _this.video.player.unMute();
 					},
 					'onStateChange': event => {
-						if (event.data == 1) {
+						if (event.data === 1) {
 							let youtubeDuration = _this.video.player.getDuration();
 							youtubeDuration -= _this.editing.song.skipDuration;
-							if (_this.editing.song.duration > youtubeDuration) this.stopVideo();
+							if (_this.editing.song.duration > youtubeDuration) {
+								this.video.player.stopVideo();
+								Toast.methods.addToast("Video can't play. Specified duration is bigger than the YouTube song duration.", 4000);
+							}
 						}
 					}
 				}

+ 13 - 4
frontend/components/Admin/Songs.vue

@@ -112,9 +112,15 @@
 				else if (type == 'artists') this.editing.song.artists.splice(index, 1);
 			},
 			edit: function (song, index) {
-				this.editing = { index, song };
-				this.video.player.loadVideoById(song._id);
-				this.isEditActive = true;
+				if (this.video.player) {
+					this.video.player.loadVideoById(song._id);
+					let songCopy = {};
+					for (let n in song) {
+						songCopy[n] = song[n];
+					}
+					this.editing = { index, song: songCopy };
+					this.isEditActive = true;
+				}
 			},
 			save: function (song) {
 				let _this = this;
@@ -173,7 +179,10 @@
 						if (event.data == 1) {
 							let youtubeDuration = _this.video.player.getDuration();
 							youtubeDuration -= _this.editing.song.skipDuration;
-							if (_this.editing.song.duration > youtubeDuration) this.stopVideo();
+							if (_this.editing.song.duration > youtubeDuration) {
+								this.video.player.stopVideo();
+								Toast.methods.addToast("Video can't play. Specified duration is bigger than the YouTube song duration.", 4000);
+							}
 						}
 					}
 				}

+ 2 - 2
frontend/components/Modals/Playlists/Edit.vue

@@ -152,13 +152,13 @@
 			promoteSong: function (songId) {
 				let _this = this;
 				_this.socket.emit('playlists.moveSongToTop', _this.playlist._id, songId, res => {
-					Toast.methods.toast(4000, res.message);
+					Toast.methods.addToast(res.message, 4000);
 				});
 			},
 			demoteSong: function (songId) {
 				let _this = this;
 				_this.socket.emit('playlists.moveSongToBottom', _this.playlist._id, songId, res => {
-					Toast.methods.toast(4000, res.message);
+					Toast.methods.addToast(res.message, 4000);
 				});
 			}
 		},