Permalink
Browse files

Added News and Pages

  • Loading branch information...
1 parent 6a28f7f commit 28c64e2ed9479c83c7f3fc28e7dcf1d8b49acb60 @iwillwen committed Jul 27, 2012
View
20 app.js
@@ -9,6 +9,8 @@ var config = require('./config');
var index = require('./controllers/index');
var survey = require('./controllers/survey');
var status = require('./controllers/status');
+var news = require('./controllers/news');
+var page = require('./controllers/page');
var admin = require('./controllers/admin');
var app = express.createServer();
@@ -65,12 +67,30 @@ var adminRequired = function (req, res, next) {
}
};
+// topics
app.post('/add_topic', authRequired, survey.addTopic);
app.post('/vote_topic', authRequired, survey.vote);
app.get('/admin/topics', authRequired, adminRequired, admin.topics);
app.post('/admin/update_topic', authRequired, adminRequired, admin.updateTopic);
app.get('/admin/view_topic', authRequired, adminRequired, admin.viewTopic);
+// news
+app.get('/news', news.overview);
+app.get('/news/:id', news.single);
+app.get('/admin/news', authRequired, adminRequired, admin.news);
+app.post('/admin/add_news', authRequired, adminRequired, admin.addNews);
+app.del('/admin/del_news', authRequired, adminRequired, admin.removeNews);
+app.get('/admin/view_news', authRequired, adminRequired, admin.viewNews);
+app.post('/admin/edit_news', authRequired, adminRequired, admin.editNews);
+
+// pages
+app.get('/page/:sign', page.view);
+app.get('/admin/pages', authRequired, adminRequired, admin.pages);
+app.post('/admin/add_page', authRequired, adminRequired, admin.addPage);
+app.get('/admin/view_page', authRequired, adminRequired, admin.viewPage);
+app.post('/admin/edit_page', authRequired, adminRequired, admin.editPage);
+app.del('/admin/del_page', authRequired, adminRequired, admin.removePage);
+
// 用于网络监控
app.get('/status', status.status);
app.get('/', index.index);
@@ -0,0 +1,122 @@
+$(function () {
+ var hiddenID = $("#id");
+ var newsNode = $("#title");
+ var fieldset = $("#news");
+ var contentBox = $("#content");
+
+ $(".container").on("click", 'td a.edit', function (event) {
+ var that = $(event.currentTarget);
+ var tr = that.closest("tr");
+ var id = tr.data("id");
+ if (!id) {
+ return false;
+ }
+ $.ajax("/admin/view_news", {
+ type: 'GET',
+ dataType: 'json',
+ data: {
+ "id": id
+ },
+ success: function (res) {
+ var news = res.news;
+ hiddenID.val(news._id);
+ contentBox.val(news.content);
+ newsNode.val(news.title);
+ $("#submit").text("更新").attr("edit", "1").attr("_id", id);
+ newsNode.focus();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ });
+
+ $(".container").on("click", 'td a.remove', function (event) {
+ var that = $(event.currentTarget);
+ var tr = that.closest("tr");
+ var id = tr.data("id");
+ if (!id) {
+ return false;
+ }
+ $.ajax("/admin/del_news", {
+ type: 'DELETE',
+ dataType: 'json',
+ data: {
+ "id": id,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ });
+
+ $(".container").on("click", '#submit', function (event) {
+ var title = newsNode.val();
+ var content = contentBox.val();
+ var that = $(event.currentTarget);
+ if (that.attr("edit") !== "1") {
+ $.ajax("/admin/add_news", {
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ "title": title,
+ "content": content,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ } else {
+ var id = that.attr("_id");
+ $.ajax("/admin/edit_news", {
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ "id": id,
+ "title": title,
+ "content": content,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ }
+ });
+
+ newsNode.bind("input", function () {
+ fieldset.removeClass("error");
+ });
+ $('.dropdown-toggle').dropdown();
+});
@@ -0,0 +1,126 @@
+$(function () {
+ var hiddenID = $("#id");
+ var newsNode = $("#title");
+ var fieldset = $("#news");
+ var contentBox = $("#content");
+ var signBox = $("#sign");
+
+ $(".container").on("click", 'td a.edit', function (event) {
+ var that = $(event.currentTarget);
+ var tr = that.closest("tr");
+ var id = tr.data("id");
+ if (!id) {
+ return false;
+ }
+ $.ajax("/admin/view_page", {
+ type: 'GET',
+ dataType: 'json',
+ data: {
+ "id": id
+ },
+ success: function (res) {
+ var news = res.news;
+ hiddenID.val(news._id);
+ contentBox.val(news.content);
+ newsNode.val(news.title);
+ $("#submit").text("更新").attr("edit", "1").attr("_id", id);
+ newsNode.focus();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ });
+
+ $(".container").on("click", 'td a.remove', function (event) {
+ var that = $(event.currentTarget);
+ var tr = that.closest("tr");
+ var id = tr.data("id");
+ if (!id) {
+ return false;
+ }
+ $.ajax("/admin/del_page", {
+ type: 'DELETE',
+ dataType: 'json',
+ data: {
+ "id": id,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ });
+
+ $(".container").on("click", '#submit', function (event) {
+ var title = newsNode.val();
+ var content = contentBox.val();
+ var sign = signBox.val();
+ var that = $(event.currentTarget);
+ if (that.attr("edit") !== "1") {
+ $.ajax("/admin/add_page", {
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ "title": title,
+ "content": content,
+ "sign": sign,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ } else {
+ var id = that.attr("_id");
+ $.ajax("/admin/edit_page", {
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ "id": id,
+ "title": title,
+ "content": content,
+ "sign": sign,
+ "_csrf": csrf
+ },
+ success: function (res) {
+ location.reload();
+ },
+ error: function (xhr, status) {
+ if (xhr.status === 401) {
+ alert("请先登录");
+ location.href = "/oauth?blogtype=weibo";
+ } else {
+ alert("服务器错误,请稍候再试");
+ }
+ }
+ });
+ }
+ });
+
+ newsNode.bind("input", function () {
+ fieldset.removeClass("error");
+ });
+ $('.dropdown-toggle').dropdown();
+});
View
@@ -49,4 +49,11 @@ span.logo_hanzi {
background: url('https://github.com/favicon.ico') whiteSmoke no-repeat;
background-position: 1px .5px;
background-size: 22px;
+}
+.content {
+ margin-top: 10px;
+}
+.readmore {
+ margin-top: -20px;
+ margin-right: 10px;
}
View
@@ -0,0 +1,16 @@
+var config = {};
+config.db = 'localhost/conf';//'82ml7vofpf1m8:898jowidte3@127.0.0.1:20088/4EU96oUTS0cD';
+config.weibo = {
+ appkey: '3065857112',
+ secret: '0e303661ff8fc05e0747d60c0c1e3cf6'
+};
+config.github = {
+ appkey: '97db48307671a31aa0d2',//'ddd8ea44faa7c6e87c13',
+ secret: '0c67119d0c8aecc9238c23670ea30b4497c5ef85'//'aa11b699e70229144d0e575ff8b05196b52b7070'
+};
+config.tqq = {
+ appkey: '801196847',
+ secret: '8805aceeab82e8df0583751f98b8f4bf'
+};
+config.admins = ["http://weibo.com/shyvo", "https://github.com/iwillwen"];
+module.exports = config;
Oops, something went wrong.

0 comments on commit 28c64e2

Please sign in to comment.