Переглянути джерело

prevent users from adding duplicate songs

AkiraLaine 9 роки тому
батько
коміт
3dbfc4dd33
1 змінених файлів з 7 додано та 3 видалено
  1. 7 3
      app/client/client.js

+ 7 - 3
app/client/client.js

@@ -241,9 +241,13 @@ Template.room.events({
         var artist = $("#artist").val();
         var img = $("#img").val();
         var songData = {type: type, id: id, title: title, artist: artist, img: img};
-        Meteor.call("addSongToQueue", genre, songData, function(err, res) {
-            console.log(err, res);
-        });
+        if(Playlists.find({type: songData.type, "songs.title": songData.title}, {songs: {$elemMatch: {title: songData.title}}}).count() === 0) {
+            $(".landing").prepend("<div class='alert alert-danger alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Song not added.</strong> This song is already is in the playlist.</div>");
+        } else{
+            Meteor.call("addSongToQueue", genre, songData, function(err, res) {
+                console.log(err, res);
+            });
+        }
         $("#close-modal-a").click();
     },
     "click #toggle-video": function(e){