Răsfoiți Sursa

added option to make room private on creation

Akira Laine 9 ani în urmă
părinte
comite
3616192871
4 a modificat fișierele cu 71 adăugiri și 9 ștergeri
  1. 42 0
      app/client/app.css
  2. 3 3
      app/client/client.js
  3. 3 1
      app/client/templates/stations.html
  4. 23 5
      app/server/server.js

+ 42 - 0
app/client/app.css

@@ -1414,3 +1414,45 @@ nav form input[type="image"]{
 .song-panel-room{
     float: right;
 }
+/*Credit to: http://thecodeplayer.com/walkthrough/custom-animated-checkbox-inputs-using-css-iconfonts*/
+#two-label {
+    position: relative;
+    padding-left: 30px;
+    font-size: 14px;
+    cursor: pointer;
+    margin-bottom: 15px;
+    color: white;
+    padding-top: 3px;
+}
+#two-label:before, #two-label:after {
+    font-family: FontAwesome;
+    font-size: 21px;
+    /*absolutely positioned*/
+    position: absolute; top: 0; left: 0;
+}
+#two-label:before {
+    content: '\f096'; /*unchecked*/
+}
+#two-label:after {
+    content: '\f046'; /*checked*/
+    /*checked icon will be hidden by default by using 0 max-width and overflow hidden*/
+    max-width: 0;
+    overflow: hidden;
+    opacity: 0.5;
+    /*CSS3 transitions for animated effect*/
+    transition: all 0.35s;
+}
+
+/*hiding the original checkboxes*/
+input[type="checkbox"] {
+    display: none;
+}
+/*when the user checks the checkbox the checked icon will animate in*/
+input[type="checkbox"]:checked + #two-label:after {
+    max-width: 25px; /*an arbitratry number more than the icon's width*/
+    opacity: 1; /*for fade in effect*/
+}
+
+/*adding some colors for fun*/
+#two+label:before, #two+label:after {color: hsl(180, 45%, 40%);}
+

+ 3 - 3
app/client/client.js

@@ -96,8 +96,8 @@ Template.settings.events({
 });
 
 Template.profile.helpers({
-    "username": function() {
-        return Session.get("username");
+    username: function() {
+        return Session.get("username")
     },
     "first_joined": function() {
         return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
@@ -1276,7 +1276,7 @@ Template.stations.events({
         }
     },
     "click #croom_create": function() {
-        Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), function (err, res) {
+        Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), $("#two").prop("checked"), function (err, res) {
             if (err) {
                 alert("Error " + err.error + ": " + err.reason);
             } else {

+ 3 - 1
app/client/templates/stations.html

@@ -51,7 +51,7 @@
           </div>
       {{/each}}
 
-      <button class="btn btn-danger col-md-6 col-md-offset-3" id="rrating" data-toggle="modal" data-target="#confirmModal">Reset Rating</button>
+      <button class="btn btn-danger col-md-6 col-md-offset-3" id="rrating" data-toggle="modal" data-target="#confirmModal" style="margin-bottom: 10px">Reset Rating</button>
 
       <div class="col-md-4 col-md-offset-4">
           <div id="croom_container">
@@ -63,6 +63,8 @@
               <div class="input-group">
                   <input type="text" class="croom" id="croom_tag" name="croom" required />
               </div>
+              <input type="checkbox" name="two" id="two"/>
+              <label id="two-label" for="two">Make Room Private?</label>
               <button class="btn btn-warning btn-block" id="croom_create">Create</button>
           </div>
       </div>

+ 23 - 5
app/server/server.js

@@ -13,7 +13,7 @@ Meteor.startup(function() {
     var stations = [{tag: "edm", display: "EDM"}, {tag: "pop", display: "Pop"}]; //Rooms to be set on server startup
     for(var i in stations){
         if(Rooms.find({type: stations[i]}).count() === 0){
-            createRoom(stations[i].display, stations[i].tag);
+            createRoom(stations[i].display, stations[i].tag, false);
         }
     }
     emojione.ascii = true;
@@ -86,9 +86,9 @@ function getStation(type, cb) {
     });
 }
 
-function createRoom(display, tag) {
+function createRoom(display, tag, private) {
     var type = tag;
-    if (Rooms.find({type: type}).count() === 0) {
+    if (Rooms.find({type: type}).count() === 0 && private === false) {
         Rooms.insert({display: display, type: type, users: 0}, function(err) {
             if (err) {
                 throw err;
@@ -106,6 +106,24 @@ function createRoom(display, tag) {
                 }
             }
         });
+    } else if (Rooms.find({type: type}).count() === 0 && private === true) {
+        Rooms.insert({display: display, type: type, users: 0, private: true}, function(err) {
+            if (err) {
+                throw err;
+            } else {
+                if (Playlists.find({type: type}).count() === 1) {
+                    stations.push(new Station(type));
+                } else {
+                    Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
+                        if (err2) {
+                            throw err2;
+                        } else {
+                            stations.push(new Station(type));
+                        }
+                    });
+                }
+            }
+        });
     } else {
         return "Room already exists";
     }
@@ -892,9 +910,9 @@ Meteor.methods({
             throw new Meteor.Error(403, "Invalid permissions.");
         }
     },
-    createRoom: function(display, tag) {
+    createRoom: function(display, tag, private) {
         if (isAdmin() && !isBanned()) {
-            createRoom(display, tag);
+            createRoom(display, tag, private);
         } else {
             throw new Meteor.Error(403, "Invalid permissions.");
         }