Explorar o código

Added creating of articles.

KrisVos130 %!s(int64=9) %!d(string=hai) anos
pai
achega
d215aacb56

+ 19 - 0
app/client/scripts/events.js

@@ -915,6 +915,25 @@ Template.register.events({
     }
     }
 });
 });
 
 
+Template.news.events({
+    "click #createArticleButton": function() {
+        var title = $("#title").val();
+        var content = $("#content").val();
+        var anonymous = $("#anonymous").is(":checked");
+        Meteor.call("createArticle", {title: title, content: content, anonymous: anonymous}, function(err, res) {
+            if (err) {
+                var $toastContent = $('<span><strong>Article not created.</strong> ' + err.reason + '</span>');
+                Materialize.toast($toastContent, 8000);
+            } else {
+                $('#createArticle').closeModal()
+                $("#title").val("").change();
+                $("#content").val("").change();
+                $("#anonymous").prop("checked", false).change();
+            }
+        });
+    }
+});
+
 Template.room.events({
 Template.room.events({
     "click #youtube-playlist-button": function () {
     "click #youtube-playlist-button": function () {
         if (!Session.get("importingPlaylist")) {
         if (!Session.get("importingPlaylist")) {

+ 0 - 14
app/client/scripts/routes.js

@@ -128,20 +128,6 @@ Router.route("/admin/alerts", {
     }
     }
 });
 });
 
 
-Router.route("/admin/news", {
-    waitOn: function() {
-        return [Meteor.subscribe("isModerator", Meteor.userId()), Meteor.subscribe("isAdmin", Meteor.userId())];
-    },
-    action: function() {
-        var user = Meteor.users.findOne({});
-        if (user !== undefined && user.profile !== undefined && (user.profile.rank === "admin")) {
-            this.render("mnews");
-        } else {
-            this.redirect("/");
-        }
-    }
-});
-
 Router.route("/u/:user", function() {
 Router.route("/u/:user", function() {
     this.render("profile");
     this.render("profile");
 });
 });

+ 0 - 42
app/client/templates/mnews.html

@@ -1,42 +0,0 @@
-<template name="mnews">
-    <div class="landing">
-        {{> header}}
-        <div class="row">
-            <div class="about col-md-8 col-md-offset-2">
-                <h1 class="center-align">Add A New Article:</h1>
-                <div class="row">
-                    <form class="col s12">
-                        <div class="row">
-                            <div class="input-field col s6">
-                                <input id="input_text" type="text" length="10">
-                                <label for="input_text">Article Title:</label>
-                            </div>
-                        </div>
-                        <div class="row">
-                            <div class="input-field col s12">
-                                <textarea id="textarea1" class="materialize-textarea" length="120"></textarea>
-                                <label for="textarea1">Article Content:</label>
-                            </div>
-                        </div>
-                        <div class="switch">
-                          <p>Post As "Musare Admin"</p>
-                            <label>
-                                No
-                                <input type="checkbox">
-                                <span class="lever"></span>
-                                Yes
-                            </label>
-                        </div>
-                        <div class="row">
-                            <div class="input-field col s12">
-                                <a class="btn-floating btn-large waves-effect waves-light right red"><i class="material-icons">add</i></a>
-                            </div>
-                        </div>
-                    </form>
-                </div>
-                <hr />
-                <h1 class="center-align">Article List:</h1>
-            </div>
-        </div>
-    </div>
-</template>

+ 40 - 0
app/client/templates/news.html

@@ -18,5 +18,45 @@
                 </div>
                 </div>
             {{/each}}
             {{/each}}
     </main>
     </main>
+    <div class="fixed-action-btn" style="bottom: 45px; right: 24px;">
+        <a class="btn-floating btn-large red modal-trigger" href="#createArticle"><i class="large material-icons">add</i></a>
+    </div>
+    <div id="createArticle" class="modal">
+        <div class="modal-content musare white-text">
+            <h4 class="center-align">Create Article</h4>
+            <div class="row">
+                <div class="input-field col l8 m8 s12 offset-l2 offset-m2">
+                    <label for="title" class="white-text">Title</label>
+                    <input class="validate" name="title" id="title" type="text"/>
+                </div>
+                <div class="input-field col l8 m8 s12 offset-l2 offset-m2">
+                    <textarea class="materialize-textarea validate" name="content" id="content" type="text"></textarea>
+                    <label for="content" class="white-text">Content</label>
+                </div>
+                <div class="col l8 m8 s12 offset-l2 offset-m2">
+                    <div class="switch">
+                        <label class="white-text">
+                            Post as myself
+                            <input id="anonymous" type="checkbox">
+                            <span class="lever"></span>
+                            Post anonymous
+                        </label>
+                    </div>
+                </div>
+            </div>
+            <div class="row">
+                <button type="button" id="createArticleButton" class="btn btn-large col l6 m6 s10 offset-l3 offset-m3 offset-s1 waves-effect waves-light">Create Article</button>
+            </div>
+        </div>
+        <div class="modal-footer musare white-text">
+            <a href="#!" class="modal-action modal-close waves-effect waves-light btn-flat white">X</a>
+        </div>
+    </div>
+    <script>
+        $(document).ready(function(){
+            // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
+            $('.modal-trigger').leanModal();
+        });
+    </script>
     {{> footer}}
     {{> footer}}
 </template>
 </template>

+ 3 - 2
app/server/server.js

@@ -943,18 +943,19 @@ Meteor.methods({
     createArticle: function(data) {
     createArticle: function(data) {
         if (!isBanned() && isModerator()) {
         if (!isBanned() && isModerator()) {
             var userId = Meteor.userId();
             var userId = Meteor.userId();
-            var requiredProperties = ["title", "content", "author"];
+            var requiredProperties = ["title", "content", "anonymous"];
             if (data !== undefined && Object.keys(data).length === requiredProperties.length) {
             if (data !== undefined && Object.keys(data).length === requiredProperties.length) {
                 for (var property in requiredProperties) {
                 for (var property in requiredProperties) {
                     if (data[requiredProperties[property]] === undefined) {
                     if (data[requiredProperties[property]] === undefined) {
                         throw new Meteor.Error(403, "Invalid data.");
                         throw new Meteor.Error(403, "Invalid data.");
                     }
                     }
                 }
                 }
-                if (data.author === true) {
+                if (data.anonymous === false) {
                     data.author = Meteor.user().profile.username
                     data.author = Meteor.user().profile.username
                 } else {
                 } else {
                     data.author = "A Musare Admin";
                     data.author = "A Musare Admin";
                 }
                 }
+                delete data.anonymous;
                 data.time =  new Date();
                 data.time =  new Date();
                 News.insert(data, function(err, res) {
                 News.insert(data, function(err, res) {
                     if (err) {
                     if (err) {