|
@ -1,12 +1,15 @@ |
|
|
/** File which renders the edit form for the posts and processes |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* File which renders the edit form for the posts and processes |
|
|
* the post data generated by edit forms. |
|
|
* the post data generated by edit forms. |
|
|
* |
|
|
* |
|
|
* @type {Promise|*} |
|
|
* @type {Promise|*} |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
const Promise = require('promise'); |
|
|
|
|
|
|
|
|
//parses the post data
|
|
|
const qs = require('querystring'); |
|
|
const qs = require('querystring'); |
|
|
const sql = require('../utils/sql'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//updates db
|
|
|
|
|
|
const sql = require('../../utils/sql'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -21,7 +24,7 @@ const renderPostRow = function(post) |
|
|
"<td>" + post.name + "</td>" + |
|
|
"<td>" + post.name + "</td>" + |
|
|
"<td>" + post.picture_url + "</td>" + |
|
|
"<td>" + post.picture_url + "</td>" + |
|
|
"<td>" + post.published + "</td>" + |
|
|
"<td>" + post.published + "</td>" + |
|
|
"<td><form action=\"/admin/\" method =\"post\" >\n" + |
|
|
|
|
|
|
|
|
"<td><form action=\"/admin\" method =\"post\" >\n" + |
|
|
"<input type=\"submit\" name=\"submit\" value=\"Edit\"\n" + |
|
|
"<input type=\"submit\" name=\"submit\" value=\"Edit\"\n" + |
|
|
" class=\"btn btn-secondary\"/>\n" + |
|
|
" class=\"btn btn-secondary\"/>\n" + |
|
|
"<input type='hidden' name='edit_post' value='" + post.post_id + "'/>"+ |
|
|
"<input type='hidden' name='edit_post' value='" + post.post_id + "'/>"+ |
|
@ -35,7 +38,7 @@ const renderPostRow = function(post) |
|
|
*/ |
|
|
*/ |
|
|
const postsTable = function() |
|
|
const postsTable = function() |
|
|
{ |
|
|
{ |
|
|
var html = "<div class='blogPost p-2'>" + |
|
|
|
|
|
|
|
|
const html = "<div class='blogPost p-2'>" + |
|
|
"<h1 class=\"text-center\">Posts</h1>" + |
|
|
"<h1 class=\"text-center\">Posts</h1>" + |
|
|
"<div class=\"\"><table class=\"table table-striped\">" + |
|
|
"<div class=\"\"><table class=\"table table-striped\">" + |
|
|
"<thead class=\"thead-dark\"><tr>" + |
|
|
"<thead class=\"thead-dark\"><tr>" + |
|
@ -68,6 +71,7 @@ const postsTable = function() |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Displays the edit form for edit posts |
|
|
* Displays the edit form for edit posts |
|
|
|
|
|
* |
|
|
* @param post_id |
|
|
* @param post_id |
|
|
*/ |
|
|
*/ |
|
|
const displayRenderForm = function(post_id) |
|
|
const displayRenderForm = function(post_id) |
|
@ -76,9 +80,9 @@ const displayRenderForm = function(post_id) |
|
|
{ |
|
|
{ |
|
|
sql.getPostById(post_id).then(function(post) |
|
|
sql.getPostById(post_id).then(function(post) |
|
|
{ |
|
|
{ |
|
|
var html = "<div class='blogPost'>"+ |
|
|
|
|
|
|
|
|
const html = "<div class='blogPost'>"+ |
|
|
"<h1 class=\"text-center\">Edit Post</h1>"+ |
|
|
"<h1 class=\"text-center\">Edit Post</h1>"+ |
|
|
"<form action=\"/admin/\" method =\"post\" >"+ |
|
|
|
|
|
|
|
|
"<form action=\"/admin\" method =\"post\" >"+ |
|
|
" <div class=\"form-group\">\n" + |
|
|
" <div class=\"form-group\">\n" + |
|
|
" <input class=\"form-control\" type=\"text\" name=\"edit_cat_num\" value='" + post.category_id + "' required>\n" + |
|
|
" <input class=\"form-control\" type=\"text\" name=\"edit_cat_num\" value='" + post.category_id + "' required>\n" + |
|
|
" <label class=\"w3-label w3-validate\">Category Number</label>\n" + |
|
|
" <label class=\"w3-label w3-validate\">Category Number</label>\n" + |
|
@ -114,6 +118,7 @@ const displayRenderForm = function(post_id) |
|
|
/** |
|
|
/** |
|
|
* Detects if the post data came from the edit form in posts table or edit post |
|
|
* Detects if the post data came from the edit form in posts table or edit post |
|
|
* in the edit post form. Based on this, this function will call one of two functions |
|
|
* in the edit post form. Based on this, this function will call one of two functions |
|
|
|
|
|
* |
|
|
* @param postData |
|
|
* @param postData |
|
|
*/ |
|
|
*/ |
|
|
const processPost = function(postData) |
|
|
const processPost = function(postData) |
|
@ -156,6 +161,7 @@ module.exports= |
|
|
/** |
|
|
/** |
|
|
* Method which calls helper functions which processes post data for editing posts |
|
|
* Method which calls helper functions which processes post data for editing posts |
|
|
* and calls a function which displays all the posts in a table |
|
|
* and calls a function which displays all the posts in a table |
|
|
|
|
|
* |
|
|
* @param postData |
|
|
* @param postData |
|
|
*/ |
|
|
*/ |
|
|
main: function(postData) |
|
|
main: function(postData) |