Browse Source

Fixed reporting modal.

KrisVos130 9 years ago
parent
commit
889212516a
3 changed files with 33 additions and 35 deletions
  1. 9 31
      app/client/scripts/events.js
  2. 13 0
      app/client/scripts/helpers.js
  3. 11 4
      app/client/templates/room.html

+ 9 - 31
app/client/scripts/events.js

@@ -1464,14 +1464,14 @@ Template.room.events({
     "click #report-prev": function (e) {
         if (Session.get("previousSong") !== undefined) {
             Session.set("reportPrevious", true);
-            $("#report-prev").prop("disabled", true);
-            $("#report-curr").prop("disabled", false);
+            $("#report-prev").addClass("disabled");
+            $("#report-curr").removeClass("disabled");
         }
     },
     "click #report-curr": function (e) {
         Session.set("reportPrevious", false);
-        $("#report-prev").prop("disabled", false);
-        $("#report-curr").prop("disabled", true);
+        $("#report-prev").removeClass("disabled");
+        $("#report-curr").addClass("disabled");
     },
     "click #report-modal": function () {
         Session.set("currentSongR", Session.get("currentSong"));
@@ -1607,15 +1607,14 @@ Template.room.events({
             Session.set(camelCase, e.target.checked);
         }*/
     },
-    "click #report-modal-button": function(){
-        $("#report-pre-song-button").removeClass("disabled")
-        Session.set("reportingSong", Session.get("currentSong"));
-        $("#report-which").html(Session.get("currentSong").title + ' <span class="thin">by</span> ' + Session.get("currentSong").artist);
-    },
     "click #report-song-button": function () {
         var room = Session.get("type");
         var reportData = {};
-        reportData.song = Session.get("reportingSong").mid;
+        if (Session.get("reportPrevious") === false) {
+            reportData.song = Session.get("previousSongR").mid;
+        } else {
+            reportData.song = Session.get("currentSongR").mid;
+        }
         reportData.type = [];
         reportData.reason = [];
 
@@ -1629,7 +1628,6 @@ Template.room.events({
 
         console.log(reportData);
         Meteor.call("submitReport", room, reportData, function () {
-            $("#report-pre-song-button").removeClass("disabled")
             $("report_modal").closeModal();
         });
     },
@@ -1646,26 +1644,6 @@ Template.room.events({
         Meteor.setTimeout(function(){
             $(".dropdown-button").click();
         }, 10);
-    },
-    "click #report-pre-song-button": function(){
-        $("#report-pre-song-button").addClass("disabled")
-        var previousSong = {}
-        var songs = Songs.find({"genres": Session.get("type")}).fetch();
-        for(var i = 0; i < songs.length; i++){
-            if(songs[i].mid === Session.get("currentSong").mid){
-                if(i === 0){
-                    previousSong.title = songs[i].title;
-                    previousSong.artist = songs[i].artist;
-                } else {
-                    previousSong.title = songs[i-1].title;
-                    previousSong.artist = songs[i-1].artist;
-                    previousSong.mid = songs[i-1].mid;
-                    Session.set("reportingSong", previousSong);
-                }
-            }
-        }
-        console.log(previousSong.title + ' <span class="thin">by</span> ' + previousSong.artist);
-        $("#report-which").html(previousSong.title + ' <span class="thin">by</span> ' + previousSong.artist);
     }
 });
 // Settings Template

+ 13 - 0
app/client/scripts/helpers.js

@@ -281,6 +281,12 @@ Template.manageStation.helpers({
 });
 
 Template.room.helpers({
+    currentSongR: function() {
+        return Session.get("currentSongR");
+    },
+    previousSongR: function() {
+        return Session.get("previousSongR");
+    },
     editingSong: function() {
         return Session.get("editingSong");
     },
@@ -401,6 +407,13 @@ Template.room.helpers({
     currentSong: function(){
         return Session.get("currentSong");
     },
+    reportingSong: function() {
+        if (!Session.get("reportPrevious")) {
+            return Session.get("currentSongR");
+        } else {
+            return Session.get("previousSongR");
+        }
+    },
     reportSong: function(){
         Meteor.setInterval(function(){
             if($("#report-song").is(":checked")){

+ 11 - 4
app/client/templates/room.html

@@ -281,7 +281,7 @@
     <div id="report_modal" class="modal">
         <div class="modal-content container">
             <h4>Reporting:</h4>
-            <h5 id="report-which">{{currentSong.title}} <span class="thin">by</span> {{currentSong.artist}}</h5>
+            <h5 id="report-which">{{reportingSong.title}} <span class="thin">by</span> {{reportingSong.artist}}</h5>
             <div class="report-layer-1">
                 <div>
                     <input type="checkbox" id="report-song">
@@ -477,8 +477,11 @@
                     {{/if}}
                 </div>
             </div>
-            <a id="report-song-button" class="waves-effect waves-light btn">Report Song</a>
-            <a id="report-pre-song-button" class="waves-effect waves-light btn">Report Previous Song</a>
+            <a id="report-song-button" class="waves-effect waves-light btn btn-block red">Submit Song Report</a>
+            {{#if previousSongR}}
+                <a id="report-prev" class="waves-effect waves-light btn btn-block">Report Previous Song</a>
+            {{/if}}
+                <a id="report-curr" class="waves-effect waves-light btn btn-block">Report Current Song</a>
         </div>
         <div class="divider"></div>
         <div class="modal-footer">
@@ -496,7 +499,11 @@
             dismissible: true,
             opacity: .5,
             in_duration: 500,
-            out_duration: 200
+            out_duration: 200,
+            ready: function() {
+                Session.set("currentSongR", Session.get("currentSong"));
+                Session.set("previousSongR", Session.get("previousSong"));
+            }
         });
         $(".dropdown-button").dropdown({
             belowOrigin: true