瀏覽代碼

Fixed staff permission and admin controls.

KrisVos130 8 年之前
父節點
當前提交
83ae7f6bb3
共有 4 個文件被更改,包括 60 次插入22 次删除
  1. 36 16
      app/client/scripts/events.js
  2. 12 2
      app/client/scripts/helpers.js
  3. 10 2
      app/client/templates/room.html
  4. 2 2
      app/server/a.js

+ 36 - 16
app/client/scripts/events.js

@@ -1383,16 +1383,26 @@ Template.room.events({
         }
     },
     "click #lock": function () {
-        Meteor.call("lockRoom", Session.get("type"));
-        var $parent = $("#lock").parent();
-        $("#lock").remove();
-        $parent.append('<a id="unlock"><i class="material-icons">lock_open</i></a>')
+        Meteor.call("lockRoom", Session.get("type"), function(err) {
+            if(err){
+                var $toastContent = $('<span><strong>Room not locked.</strong> ' + err.reason + '</span>');
+                Materialize.toast($toastContent, 4000);
+            } else {
+                var $toastContent = $('<span><strong>Room locked.</strong></span>');
+                Materialize.toast($toastContent, 4000);
+            }
+        });
     },
     "click #unlock": function () {
-        Meteor.call("unlockRoom", Session.get("type"));
-        var $parent = $("#unlock").parent();
-        $("#unlock").remove();
-        $parent.append('<a id="lock"><i class="material-icons">lock_outline</i></a>')
+        Meteor.call("unlockRoom", Session.get("type"), function(err) {
+            if(err){
+                var $toastContent = $('<span><strong>Room not unlocked.</strong> ' + err.reason + '</span>');
+                Materialize.toast($toastContent, 4000);
+            } else {
+                var $toastContent = $('<span><strong>Room unlocked.</strong></span>');
+                Materialize.toast($toastContent, 4000);
+            }
+        });
     },
     "click #submit": function () {
         if(Meteor.userId()){
@@ -1558,16 +1568,26 @@ Template.room.events({
         }
     },
     "click #play": function () {
-        Meteor.call("resumeRoom", Session.get("type"));
-        var $parent = $("#play").parent();
-        $("#play").remove();
-        $parent.append('<a id="pause"><i class="material-icons">pause</i></a>')
+        Meteor.call("resumeRoom", Session.get("type"), function (err, res) {
+            if (err) {
+                var $toastContent = $('<span><strong>Room not resumed.</strong> ' + err.reason + '</span>');
+                Materialize.toast($toastContent, 4000);
+            } else {
+                var $toastContent = $('<span><strong>Room resumed.</strong></span>');
+                Materialize.toast($toastContent, 4000);
+            }
+        });
     },
     "click #pause": function () {
-        Meteor.call("pauseRoom", Session.get("type"));
-        var $parent = $("#pause").parent();
-        $("#pause").remove();
-        $parent.append('<a id="play"><i class="material-icons">play_arrow</i></a>')
+        Meteor.call("pauseRoom", Session.get("type"), function (err, res) {
+            if (err) {
+                var $toastContent = $('<span><strong>Room not paused.</strong> ' + err.reason + '</span>');
+                Materialize.toast($toastContent, 4000);
+            } else {
+                var $toastContent = $('<span><strong>Room paused.</strong></span>');
+                Materialize.toast($toastContent, 4000);
+            }
+        });
     },
     "click #skip": function () {
         Meteor.call("skipSong", Session.get("type"));

+ 12 - 2
app/client/scripts/helpers.js

@@ -436,10 +436,20 @@ Template.room.helpers({
         return Session.get("loaded");
     },
     paused: function () {
-        return Session.get("state") === "paused";
+        var room = Rooms.findOne({type: Session.get("type")});
+        if (room !== undefined) {
+            return room.state === "paused";
+        } else {
+            return false;
+        }
     },
     private: function () {
-        return 1;
+        var room = Rooms.findOne({type: Session.get("type")});
+        if (room !== undefined) {
+            return room.private === true;
+        } else {
+            return false;
+        }
         //return Rooms.findOne({type: Session.get("type")}).private === true;
     },
     currentSong: function(){

+ 10 - 2
app/client/templates/room.html

@@ -115,10 +115,18 @@
     </div>
     <!--Admin room controls-->
     <ul id='admin-dropdown' style="background-color: rgb(3, 169, 244) !important; display: none">
-        <li><a id="pause"><i class="material-icons">pause</i></a></li>
+        {{#if paused}}
+            <li><a id="play"><i class="material-icons">play_arrow</i></a></li>
+        {{else}}
+            <li><a id="pause"><i class="material-icons">pause</i></a></li>
+        {{/if}}
         <li><a id="skip"><i class="material-icons">skip_next</i></a></li>
         <li><a id="shuffle"><i class="material-icons">shuffle</i></a></li>
-        <li><a id="lock"><i class="material-icons">lock_outline</i></a></li>
+        {{#if private}}
+            <li><a id="unlock"><i class="material-icons">lock_outline</i></a></li>
+        {{else}}
+            <li><a id="lock"><i class="material-icons">lock_open</i></a></li>
+        {{/if}}
     </ul>
     <!--Add song modal-->
     <div id="add_song_modal" class="modal">

+ 2 - 2
app/server/a.js

@@ -41,11 +41,11 @@ Meteor.updatedMethods = function(methods) {
                 }
                 _.each(methods[methodName].requirements, function(requirement) {
                     if (requirement === "moderator") {
-                        if (!Meteor.userId() || !Meteor.user() || !(Meteor.user().profile.type === "admin" || Meteor.user().profile.type === "moderator")) {
+                        if (!Meteor.userId() || !Meteor.user() || !(Meteor.user().profile.rank === "admin" || Meteor.user().profile.type === "moderator")) {
                             throw new Meteor.Error(401, "Invalid permissions.");
                         }
                     } else if (requirement === "admin") {
-                        if (!Meteor.userId() || !Meteor.user() || Meteor.user().profile.type !== "admin") {
+                        if (!Meteor.userId() || !Meteor.user() || Meteor.user().profile.rank !== "admin") {
                             throw new Meteor.Error(401, "Invalid permissions.");
                         }
                     } else if (requirement === "login") {