moved custom tools to brain, got rid of react extensions, converted custom tools to es6

sql-version-freeze
Ro 6 years ago
parent 625bab02e5
commit 99db0dde71

4
.gitignore vendored

@ -1,8 +1,10 @@
content/
node_modules/
.sass-cache/
.cache/
content/folio-images
content/client-images
content/blog-images
content/user-images
.ftpconfig
.vscode/
config.development.json

@ -0,0 +1,168 @@
import StringUtils from '../../tools/utilities/StringUtils';
import RightsManager, {
TASK_CREATE,
TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST
} from '../../tools/utilities/RightsManager';
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var Models = require('../../models');
const scrape = require('scrape-metadata')
/*
Get Bookmark Listzz
*/
router.get('/archive', function (req, res, next) {
BMArchive.find()
.then((bookmarks) => {
console.log(bookmarks[1])
res.json(bookmarks)
})
.catch((err) => {
console.log(err)
})
});
/*
Get Bookmark List
*/
router.get('/', function (req, res, next) {
Bookmark.find().sort({
created: -1
})
.then((bookmarks) => {
res.json(bookmarks)
})
.catch((err) => {
console.log(err)
})
});
/*
Get Bookmark by ID
*/
router.get('/:id', function (req, res, next) {
});
/*
Create New BookMark
*/
router.post('/add', function (req, res, next) {
if (!req.session.user)
return res.json({
message: "You need to be logged in, champ."
});
var link = req.body.url;
Models.User.findById(req.session.user.id).then((user) => {
if (rightsManager.check(user.role, OBJECT_BOOKMARK, TASK_CREATE)) {
scrape(link, (err, meta) => {
var urlPieces = link.split("/");
Models.Bookmark.sync().then(f => {
Models.Bookmark.create({
source: urlPieces[0] + urlPieces[1] + '//' + urlPieces[2],
url: link,
image: meta.ogImage,
title: meta.title,
author: user.id,
listed: true
}).then(saved => {
res.json({
message: "link added"
});
}).catch(err => {
res.json({
message: "post error",
error: err
});
})
})
})
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
/*
Update Bookmark by ID
*/
router.post('/update/:id', function (req, res, next) {
if (!req.session.user)
return res.json({
message: "You need to be logged in, champ."
});
console.log("ID: "+req.params.id);
let title = req.body.title;
let tags = req.body.tags;
let image = req.body.image;
Models.User.findById(req.session.user.id).then((user) => {
if (rightsManager.check(user.role, OBJECT_BOOKMARK, TASK_UPDATE)) {
Models.Bookmark.findOne({
where: {
id: req.params.id
}
}).then(saved => {
console.log('SAVED: '+req.body.title);
saved.update({
title: title,
image: image
}).then(updated => {
res.json({
message: "bookmark updated"
});
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err)
})
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
/*
Delete Bookmark by ID
*/
router.delete('/:id', function (req, res, next) {
});
module.exports = router;

@ -0,0 +1,235 @@
import DateUtils from '../../tools/utilities/DateUtils';
import RightsManager, {
TASK_CREATE,
TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST
} from '../../tools/utilities/RightsManager';
var express = require('express');
var router = express.Router();
var multer = require('multer');
var fs = require('fs-extra');
var Models = require('../../models');
var User = require('../../models/User.js');
const dateUtil = new DateUtils()
var uploadPath = "./content/folio-images/" + dateUtil.getDate('year', new Date()) + "/" + dateUtil.getDate('month', new Date());
fs.ensureDir(uploadPath, function (err) {
//console.log(err) // => null
// dir has now been created, including the directory it is to be placed in
})
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, uploadPath)
},
filename: function (req, file, cb) {
var splice = file.originalname.split(':');
cb(null, splice[0]);
}
});
var upload = multer({
storage: storage
}).array('folioImages');
/*
Create New Folio Project
*/
router.post('/add', function (req, res, next) {
if (!req.user)
return res.json({
message: "You need to be logged in, champ."
})
User.findById(req.user._id).then((user) => {
upload(req, res, function (err) {
if (err) {
//console.log('Error in Saving Entry: ' + err);
res.json({
message: err
});
throw err;
} else {
if (RightsManager.check(user.role, [RightsManager.OBJECT_PROJECT_FOLIO], RightsManager.TASK_CREATE)) {
var project = new Project(req.body);
if (req.files != "") {
project.images = req.files;
} else {
console.log("NOTHING TO SAVE");
}
project.save().then((project) => {
res.json({
message: "new client project added"
});
}).catch((err) => {
console.log(err);
})
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
}
});
}).catch((err) => {
console.log(err);
})
});
/*
Get Folio Project List
*/
router.get('/', function (req, res, next) {
Project.find({}).then((projects) => {
var folioArray = [];
for (var i = 0; i < projects.length; i++) {
var imgURL = null;
if (projects[i].images.length != 0)
imgURL = String(projects[i].images[0].path).substring(8, String(projects[i].images[0].path).length);
var folioItem = {
id: projects[i]._id,
title: projects[i].title,
url: projects[i].url,
tools: projects[i].tools,
description: projects[i].description,
type: projects[i].type,
img_url: imgURL,
img_full_url: "http://formless.local/" + imgURL
}
folioArray[i] = folioItem;
}
res.json(folioArray);
})
});
/*
Get Folio Project by ID
*/
router.get('/:id', function (req, res, next) {
Project.findById(req.params.id).then((project) => {
res.json(project);
}).catch((err) => {
console.log(err);
});
});
/*
Update Folio Project by ID
*/
router.post('/update/:id', function (req, res, next) {
if (!req.session.user)
return res.json({
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) => {
if (RightsManager.check(user.role, [RightsManager.OBJECT_PROJECT_FOLIO], RightsManager.TASK_UPDATE)) {
upload(req, res, function (err) {
if (err) {
//console.log('Error in Saving Entry: ' + err);
res.json({
message: err
});
throw err;
} else {
Models.FolioProject.findOne({where:{id: req.params.id}}).then((project) => {
if (req.files != "") {
project.images = req.files;
} else {
console.log("NOTHING TO SAVE");
}
console.log(req.body);
project.update(req.body).then(updated => {
res.json({
message: "project updated"
});
}).catch(err => {
console.log(err)
});
/**
project.save().then((saved) => {
res.json({
message: "project updated"
});
}).catch((err) => {
console.log(err);
})
**/
}).catch((err) => {
console.log(err);
})
}
});
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
/*
Delete Folio Project by ID
*/
router.delete('/:id', function (req, res, next) {
if (!req.user)
return res.json({
message: "users only, yo. you're not that"
});
User.findById(req.user._id).then((user) => {
if (RightsManager.check(user.role, [RightsManager.OBJECT_PROJECT_FOLIO], RightsManager.TASK_DELETE)) {
Project.findByIdAndRemove(req.params.id).then((project) => {
res.json({
message: 'project has been removed'
});
}).catch((err) => {
console.log(err);
})
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
router.post('/sort', function (req, res, next) {
var sortList = req.body;
var self = this;
User.findById(req.user._id).then((user) => {
if (RightsManager.check(user.role, [RightsManager.OBJECT_PROJECT_FOLIO], RightsManager.TASK_UPDATE)) {
var clean = true;
for (var i = 0; i < sortList.length; i++) {
Project.findByIdAndUpdate(sortList[i].sortID, {
sortIndex: sortList[i].sortIndex
}).then((project) => {
//console.log("SORTED")
//res.json({message: "sorted"})
}).catch((err) => {
//res.json({message: "sorted", error:err})
})
//res.json({message:'projects updated'})
}
} else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
module.exports = router;

@ -0,0 +1,41 @@
var express = require('express');
var router = express.Router();
var api_key = 'key-4ef13da32fb39b9d9f0370c9efba7f06';
var domain = 'communique.playvicio.us';
var mailgun = require('mailgun-js')({
apiKey: api_key,
domain: domain
});
router.post('/', function (req, res, next) {
// create reusable transporter object using the default SMTP transport
// setup e-mail data with unicode symbols
var mailOptions = {
from: req.body.email, // sender address
to: 'ro@playvicio.us', // list of receivers
subject: 'Availability Inquiry', // Subject line
text: "Message from: " + req.body.client + " <" + req.body.email + "> - " + req.body.description + " - " + req.body.type
};
mailgun.messages().send(mailOptions, function (error, body) {
if (error) {
res.json({
error: error
});
}
console.log(body);
res.json({
message: "message sent"
});
});
});
module.exports = router;

@ -0,0 +1,345 @@
var express = require('express');
import DateUtils from '../../tools/utilities/DateUtils';
import StringUtils from '../../tools/utilities/StringUtils';
import RightsManager,
{
TASK_CREATE,
TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST
}
from '../../tools/utilities/RightsManager';
var router = express.Router();
var multer = require('multer');
var fs = require('fs-extra');
var Models = require('../../models');
var uuidv4 = require('uuid/v4');
var md = require('markdown-it')('commonmark');
var sanitize = require('sanitize-html');
const dateUtils = new DateUtils();
const stringUtils = new StringUtils();
const rightsManager = new RightsManager();
var uploadPath = "./content/blog-images/" + dateUtils.getDate('year', new Date()) + "/" + dateUtils.getDate('month', new Date());
fs.ensureDir(uploadPath, function(err)
{
//console.log(err) // => null
// dir has now been created, including the directory it is to be placed in
})
var storage = multer.diskStorage(
{
destination: function(req, file, cb)
{
cb(null, uploadPath)
},
filename: function(req, file, cb)
{
var splice = file.originalname.split(':');
cb(null, splice[0]);
}
});
var feature_upload = multer(
{
storage: storage
}).array('feature_image');
var post_upload = multer(
{
storage: storage
}).array('post_image');
/***
ADD POST
*/
router.post('/add', function(req, res, next)
{
if (!req.session.user) return res.json(
{
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE))
{
feature_upload(req, res, function(err)
{
if (err)
{
res.json(
{
message: err
});
throw err;
}
else
{
var postImages = [];
if (req.files != "")
{
for (let i = 0; i < req.files.length; i++)
{
postImages.push(req.files[i].path);
}
}
else
{
console.log("NOTHING TO SAVE");
}
Models.Post.sync().then(f =>
{
var html = req.body.post_plaintext;
html = html.replace(/<\/?span[^>]*>/g, ""); //removes highightjs styling
console.log("REGULAR: " + html);
let buffed = sanitize(html,
{
allowedTags: ['del', 'a', 'iframe', 'img'],
allowedAttributes:
{
a: ['href', 'name', 'target'],
img: ['src'],
iframe: ['height', 'width', 'src', 'frameborder', 'allow', 'allowfullscreen']
}
})
buffed = stringUtils.decodeHTML(buffed)
Models.Post.create(
{
uuid: uuidv4(),
title: req.body.title,
slug: req.body.slug,
plaintext: buffed,
tags: req.body.tags,
page: req.body.status_page,
featured: req.body.status_feature,
published: req.body.status_published,
author_id: req.session.user.id,
origin_date: new Date(req.body.origin_date),
html: md.render(buffed,
{
html: true,
xhtmlOut: true,
}),
feature_image: JSON.stringify(postImages)
}).then(saved =>
{
res.json(
{
message: "postAdded",
postID: saved.slug
});
}).catch(err =>
{
console.log(err)
})
})
}
});
}
else
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
/***
UPDATE POST
*/
router.post('/update/:id', function(req, res, next)
{
//console.log(req.body);
if (!req.session.user) return res.json(
{
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE))
{
feature_upload(req, res, function(err)
{
if (err)
{
res.json(
{
message: err
});
throw err;
}
else
{
var postImages = [];
if (req.files != "")
{
for (let i = 0; i < req.files.length; i++)
{
postImages.push(req.files[i].path);
}
}
else
{
console.log("NOTHING TO SAVE");
}
Models.Post.findOne(
{
where:
{
id: req.params.id
}
}).then(post =>
{
if (postImages.length == 0) postImages = JSON.parse(post.feature_image);
var html = req.body.post_plaintext;
html = html.replace(/<\/?span[^>]*>/g, ""); //removes highightjs styling
let cleaned = sanitize(html,
{
allowedTags: ['del', 'a', 'iframe', 'img'],
allowedAttributes:
{
a: ['href', 'name', 'target'],
img: ['src'],
iframe: ['height', 'width', 'src', 'frameborder', 'allow', 'allowfullscreen']
}
})
cleaned = stringUtils.decodeHTML(cleaned)
post.update(
{
title: req.body.title,
slug: req.body.slug,
plaintext: cleaned,
origin_date: new Date(req.body.origin_date),
tags: req.body.tags,
page: req.body.status_page,
featured: req.body.status_feature,
published: req.body.status_published,
html: md.render(cleaned,
{
html: true,
xhtmlOut: true
}),
feature_image: JSON.stringify(postImages)
}).then(updated =>
{
res.json(
{
message: "postUpdated"
});
}).catch(err =>
{
console.log(err)
res.json(
{
message: "postError",
error: err
});
})
}).catch(err =>
{
//console.log(err)
res.json(
{
message: "postError",
error: err
});
})
}
});
}
else
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
/***
POST IMAGE
*/
router.post('/add-post-image', function(req, res, next)
{
//console.log(req.body);
if (!req.session.user) return res.json(
{
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE))
{
post_upload(req, res, function(err)
{
if (err)
{
//console.log('Error in Saving Entry: ' + err);
res.json(
{
message: err
});
throw err;
}
else
{
var postImage = req.files[0].path;
return res.json(
{
message: "post image added",
url: postImage.substr(7, postImage.length)
});
}
});
}
else
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
router.post('/delete/:id', function(req, res, next)
{
if (!req.session.user) return res.json(
{
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_DELETE))
{
Models.Post.findOne(
{
where:
{
id: req.params.id
}
}).then(post =>
{
post.destroy().then(deleted =>
{
res.json(
{
message: "postDeleted"
});
})
}).catch(err =>
{
console.log(err);
})
}
else
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
module.exports = router;

@ -0,0 +1,180 @@
import RightsManager, {
TASK_CREATE,
TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST
} from '../../tools/utilities/RightsManager';
var express = require('express');
var router = express.Router();
var multer = require('multer');
var fs = require('fs-extra');
var Models = require('../../models');
var User = require('../../models/User.js');
var uploadPath = "./content/client-images/";
fs.ensureDir(uploadPath, function(err) {
//console.log(err) // => null
// dir has now been created, including the directory it is to be placed in
})
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, uploadPath)
},
filename: function(req, file, cb) {
var splice = file.originalname.split(':');
cb(null, splice[0]);
}
});
var upload = multer({storage: storage}).array('projectImages');
var rightsManager = new RightsManager();
/*
Create New Client Project
*/
router.post('/add', function(req, res, next) {
if (!req.user)
return res.json({message: "You need to be logged in, champ."})
User.findById(req.user._id).then((user) => {
upload(req, res, function(err) {
if (err) {
//console.log('Error in Saving Entry: ' + err);
res.json({message: err});
throw err;
} else {
if (rightsManager.check(user.role, OBJECT_PROJECT_FOLIO, TASK_CREATE)) {
var project = new Project(req.body);
project.owner = user._id;
project.user = [];
project.comments = [];
project.tasks = [];
project.created = new Date().getTime();
project.edited = new Date().getTime();
if (req.files != "") {
project.images = req.files;
} else {
console.log("NOTHING TO SAVE");
}
project.save().then((project) => {
res.json({message: "new client project added"});
}).catch((err) => {
console.log(err);
})
} else {
res.json({message: "Nah. You can't do that. Talk to the admin, sport."});
}
}
});
}).catch((err) => {
console.log(err);
})
});
/*
Get Client Project List
*/
router.get('/', function(req, res, next) {
if (!req.user)
return res.json({message: "You need to be logged in, champ."})
User.findById(req.user._id).then((user) => {
if ( rightsManager.check(user.role, OBJECT_POST, TASK_READ )) {
Project.find({}).then((projects) => {
res.json(projects);
}).then((users) => {
//res.json({message: "got user list"});
}).catch((err) => {
console.log(err);
});
} else {
res.json({message: "Nah. You can't do that. Talk to the admin, sport."});
}
}).catch((err) => {
console.log(err);
})
});
/*
Get Client Project by ID
*/
router.get('/:id', function(req, res, next) {
if (!req.user)
return res.json({message: "You need to be logged in, champ."});
User.findById(req.user._id).then((user) => {
if (RightsManager.check(user.role, [RightsManager.OBJECT_PROJECT_CLIENT], RightsManager.TASK_READ)) {
Project.findById(req.params.id).then((project) => {
res.json(project);
}).catch((err) => {
console.log(err);
});
}
})
});
/*
Update Client Project by ID
*/
router.post('/update/:id', function(req, res, next) {
if (!req.user)
return res.json({message: "You need to be logged in, champ."});
User.findById(req.user._id).then((user) => {
if ( rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE) ) {
upload(req, res, function(err) {
if (err) {
//console.log('Error in Saving Entry: ' + err);
res.json({message: err});
throw err;
} else {
Project.findByIdAndUpdate(req.params.id, req.body).then((project) => {
if (req.files != "") {
project.images = req.files;
} else {
console.log("NOTHING TO SAVE");
}
project.edited = new Date().getTime();
project.save().then((saved) => {
res.json({message: "project updated"});
}).catch((err) => {
console.log(err);
})
}).catch((err) => {
console.log(err);
})
}
});
} else {
res.json({message: "Nah. You can't do that. Talk to the admin, sport."});
}
});
});
/*
Delete Client Project by ID
*/
router.delete('/:id', function(req, res, next) {
if (!req.user)
return res.json({message: "users only, yo. you're not that"});
User.findById(req.user._id).then((user) => {
if ( rightsManager.check(user.role, OBJECT_POST, TASK_DELETE) ) {
Project.findByIdAndRemove(req.params.id).then((project) => {
res.json({message: 'project has been removed'});
}).catch((err) => {
console.log(err);
})
} else {
res.json({message: "Nah. You can't do that. Talk to the admin, sport."});
}
});
});
module.exports = router;

@ -1,11 +1,14 @@
import DateUtils from '../../tools/utilities/DateUtils';
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var DateUtils = require('../../utils/DateUtils');
var hljs = require('highlight.js/lib/highlight');
var hljs_md = require('highlight.js/lib/languages/markdown');
hljs.registerLanguage('markdown', hljs_md);
const dateUtils = new DateUtils();
//--------------------------
// Index
//--------------------------
@ -14,7 +17,6 @@ router.get('/', function (req, res) {
if (req.session.user)
loggedIn = true;
console.log('SYNCING');
Models.Post.sync().then(f => {
Models.Post.findAll({
order: [
@ -107,7 +109,8 @@ router.get('/posts/add/new', function (req, res) {
res.render('dash/post-edit', {
title: 'Make New Post',
mode: 'admin',
date: DateUtils.getDate('year', new Date()) + "-" + DateUtils.getDate('month', new Date()) + "-" + DateUtils.getDate('day', new Date()),
date: dateUtils.getDate('year', new Date()) + "-" + dateUtils.getDate('month', new Date()) + "-" + dateUtils.getDate('day', new Date()),
status:['false', 'false', 'false'],
edit: false
});
} else {
@ -132,7 +135,7 @@ router.get('/posts/edit/:id', function (req, res) {
let sexydate
if (post.origin_date == "" || post.origin_date == null)
sexydate = DateUtils.getDate('year', post.created_at) + "-" + DateUtils.getDate('month', post.created_at) + "-" + DateUtils.getDate('day', post.created_at)
sexydate = dateUtils.getDate('year', post.created_at) + "-" + dateUtils.getDate('month', post.created_at) + "-" + dateUtils.getDate('day', post.created_at)
else
sexydate = post.origin_date
res.render('dash/post-edit', {

@ -1,5 +1,5 @@
import * as DataEvent from '../events/DataEvent';
import DateUtils from './DateUtils';
import DateUtils from '../utilities/DateUtils';
import {
position,
offset

@ -0,0 +1,154 @@
export const roles = {
hnic:
{
"client_admin":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_user":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"folio_project":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"bookmark":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"post":
{
"create": true,
"read": true,
"update": true,
"delete": true
}
},
client:
{
"client_admin":
{
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_user":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project":
{
"create": true,
"read": true,
"update": true,
"delete": false
},
"folio_project":
{
"create": false,
"read": false,
"update": false,
"delete": false
}
},
user:
{
"client_admin":
{
"create": false,
"read": false,
"update": false,
"delete": false
},
"client_user":
{
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_project":
{
"create": false,
"read": true,
"update": true,
"delete": false
},
"folio_project":
{
"create": false,
"read": false,
"update": false,
"delete": false
},
"bookmark":
{
"create": true,
"read": true,
"update": true,
"delete": true
},
"post":
{
"create": false,
"read": false,
"update": false,
"delete": false
}
}
};
export const TASK_CREATE = 'create'
export const TASK_UPDATE = 'update'
export const TASK_READ = 'read'
export const TASK_DELETE = 'delete'
export const OBJECT_CLIENT_ADMIN = 'client_admin'
export const OBJECT_CLIENT_USER = 'client_user'
export const OBJECT_PROJECT_CLIENT = 'client_project'
export const OBJECT_PROJECT_FOLIO = 'folio_project'
export const OBJECT_BOOKMARK = 'bookmark'
export const OBJECT_POST = 'post'
export default class RightsManager
{
//--------------------------
// constructor
//--------------------------
constructor()
{
var self = this;
}
//--------------------------
// methods
//--------------------------
check(role, object, task)
{
console.log(role + " *** " + object + " *** " + task);
return roles[role][object][task];
}
//--------------------------
// event handlers
//--------------------------
}

@ -1,100 +0,0 @@
module.exports = {
decodeHTML: function (string, quote_style) {
var optTemp = 0,
i = 0,
noquotes = false;
if (typeof quote_style === 'undefined') {
quote_style = 2;
}
string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
var OPTS = {
'ENT_NOQUOTES': 0,
'ENT_HTML_QUOTE_SINGLE': 1,
'ENT_HTML_QUOTE_DOUBLE': 2,
'ENT_COMPAT': 2,
'ENT_QUOTES': 3,
'ENT_IGNORE': 4
};
if (quote_style === 0) {
noquotes = true;
}
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
if (OPTS[quote_style[i]] === 0) {
noquotes = true;
} else if (OPTS[quote_style[i]]) {
optTemp = optTemp | OPTS[quote_style[i]];
}
}
quote_style = optTemp;
}
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
// string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
}
if (!noquotes) {
string = string.replace(/&quot;/g, '"');
}
// Put this in last place to avoid escape being double-decoded
string = string.replace(/&amp;/g, '&');
return string;
},
cleanString: function (str) {
return (str + '').replace(/\\(.?)/g, function (s, n1) {
switch (n1) {
case '\\':
return '\\';
case '0':
return '\u0000';
case '':
return '';
default:
return n1;
}
});
},
cleanString: function (string) {
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '').toLowerCase().replace(/[\/_| -]+/g, '-');
return clean;
},
getDate: function (type, rawdate) {
var day = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate()));
var month = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1));
var year = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear()));
var hour = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours()));
var minute = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes()));
var seconds = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds()));
var millisecond = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds()));
var offset = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset()));
if (day.length == 1)
day = String("0" + day);
if (month.length == 1)
month = String("0" + month);
offset = String(offset / 60);
if (offset.length == 1)
offset = String("0" + offset);
switch (type) {
case "day":
return day;
break;
case "month":
return month;
break;
case "year":
return year;
break;
case "stamp":
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + (offset));
break
default:
return String(year + "-" + month + "-" + day + " : " + hour + "-" + minute + "-" + seconds);
break;
}
}
};

@ -1,112 +0,0 @@
var roles = {
hnic: {
"client_admin": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_user": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"folio_project": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"bookmark": {
"create": true,
"read": true,
"update": true,
"delete": true
}
},
client: {
"client_admin": {
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_user": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project": {
"create": true,
"read": true,
"update": true,
"delete": false
},
"folio_project": {
"create": false,
"read": false,
"update": false,
"delete": false
}
},
user: {
"client_admin": {
"create": false,
"read": false,
"update": false,
"delete": false
},
"client_user": {
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_project": {
"create": false,
"read": true,
"update": true,
"delete": false
},
"folio_project": {
"create": false,
"read": false,
"update": false,
"delete": false
},
"bookmark": {
"create": true,
"read": true,
"update": true,
"delete": true
}
}
};
module.exports = {
TASK_CREATE: 'create',
TASK_UPDATE: 'update',
TASK_READ: 'read',
TASK_DELETE: 'delete',
OBJECT_CLIENT_ADMIN: 'client_admin',
OBJECT_CLIENT_USER: 'client_user',
OBJECT_PROJECT_CLIENT: 'client_project',
OBJECT_PROJECT_FOLIO: 'folio_project',
OBJECT_BOOKMARK: 'bookmark',
check: function(role, object, task) {
for (var i = 0; i < object.length; i++) {
if(!roles[role][object[i]][task])
return false
}
return true;
},
hey: function() {}
};

5
package-lock.json generated

@ -2708,6 +2708,11 @@
"source-map": "~0.6.1"
}
},
"esm": {
"version": "3.0.84",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.0.84.tgz",
"integrity": "sha512-SzSGoZc17S7P+12R9cg21Bdb7eybX25RnIeRZ80xZs+VZ3kdQKzqTp2k4hZJjR7p9l0186TTXSgrxzlMDBktlw=="
},
"esprima": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz",

@ -6,9 +6,9 @@
"repository": "https://code.playvicio.us/Are0h/Fipamo",
"theme": "default",
"scripts": {
"start": "forever start init.js",
"start": "forever start -r esm init.js",
"stop": "forever stop init.js",
"dev": "nodemon init.js",
"dev": "nodemon -r esm init.js",
"watch-front-scripts": "parcel watch themes/$npm_package_theme/src/com/Start.jsx --out-dir themes/$npm_package_theme/assets/js --out-file start.min.js --public-url /$npm_package_theme/assets/js",
"watch-front-styles": "stylus -w -m -o themes/$npm_package_theme/assets/css themes/$npm_package_theme/src/styles/base.styl",
"build-front-kit": "uglifyjs node_modules/scramble-text/dist/ScrambleText.min.js node_modules/animejs/anime.min.js node_modules/reframe.js/dist/reframe.min.js -c -o themes/$npm_package_theme/assets/js/toolkit.min.js",
@ -28,6 +28,7 @@
"cookie-parser": "~1.3.3",
"debug": "^4.1.0",
"entypo": "^2.1.0",
"esm": "^3.0.84",
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs-extra": "latest",

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -7,7 +7,7 @@ block main-content
-var post_tags = ''
-var post_id = ''
-var post_date = date
-var post_status = ['false', 'false', 'false', '']
-var post_status = ['false', 'false', 'false',]
if(edit)
-post_title = post.title

@ -1,5 +1,12 @@
import DataUtils, { REQUEST_TYPE_GET, REQUEST_TYPE_PUT, REQUEST_TYPE_POST, REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON, CONTENT_TYPE_FORM } from './tools/utilities/DataUtils.jsx';
import * as DataEvent from './tools/events/DataEvent.jsx';
import DataUtils, {
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
} from '../../../../brain/tools/utilities/DataUtils';
import * as DataEvent from '../../../../brain/tools/events/DataEvent.jsx';
import DisplayManager from './controllers/DisplayManager.jsx';
export default class Base {

@ -1,6 +1,14 @@
import DataUtils, { REQUEST_TYPE_GET, REQUEST_TYPE_PUT, REQUEST_TYPE_POST, REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON, CONTENT_TYPE_FORM } from '../tools/utilities/DataUtils';
import * as DataEvent from '../tools/events/DataEvent';
import StringUtils from '../tools/utilities/StringUtils';
import DataUtils, {
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
} from '../../../../../brain//tools/utilities/DataUtils';
import * as DataEvent from '../../../../../brain//tools/events/DataEvent';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
class PostActions {
//--------------------------
// constructor
@ -16,7 +24,7 @@ class PostActions {
submitPost(edit, uploadFiles) {
let self = this;
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
//collect form data
//if(!this.validateForm())
var postData = new FormData();
@ -69,10 +77,10 @@ class PostActions {
});
}
deletePost(){
deletePost() {
let self = this;
let postID = document.getElementById('edit-update').getAttribute('data-id');
return new Promise(function(resolve, reject){
return new Promise(function (resolve, reject) {
self.dataUtils.request("/api/post/delete/" + postID, DataEvent.POST_DELETED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM)
.then((response) => {
resolve({
@ -86,8 +94,11 @@ class PostActions {
})
//this.dataUtils.re
}
//--------------------------
// event handlers
//--------------------------
//--------------------------
// event handlers
//--------------------------
}
export {
PostActions as
default
}
export { PostActions as default }

@ -6,9 +6,10 @@ import DataUtils, {
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
} from '../tools/utilities/DataUtils.jsx';
} from '../../../../../brain/tools/utilities/DataUtils';
import PostEditor from './PostEditor';
import Animate from '../tools/effects/Animate.jsx';
import Animate from '../../../../../brain/tools/effects/Animate.jsx';
class DisplayManager {
//--------------------------
// constructor
@ -19,13 +20,13 @@ class DisplayManager {
this.urlPieces = document.URL.split("/");
//grab url so system knows what to display
this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]);
}
//--------------------------
// methods
//--------------------------
start() {
let self = this;
// new stuff
new Animate().object({
targets: document.getElementById('loader'),
duration: 300,
@ -50,7 +51,6 @@ class DisplayManager {
chooseDisplay(section, page) {
this.currentDisplay = '';
//console.log(section+" "+page)
switch (section) {
case 'posts':
this.currentDisplay = new PostEditor();

@ -0,0 +1,274 @@
//TOOLS
import DataUtils,
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
}
from '../../../../../brain/tools/utilities/DataUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import Animate from '../../../../../brain/tools/effects/Animate';
import PostActions from '../actions/PostActions';
import * as EditorEvent from '../../../../../brain/tools/events/EditorEvent';
import TinyDatePicker from 'tiny-date-picker';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import TextEditor from '../../../../../brain/tools/ui/TextEditor';
class PostEditor
{
//--------------------------
// constructor
//--------------------------
constructor()
{
//reframe('iframe');
let self = this;
this.uploadFiles;
this.anim = new Animate();
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
if ( document.getElementById( 'edit-post-text' ) )
{
this.editor = new TextEditor( document.getElementById( 'edit-post-text' ), document.getElementById( 'header' ).offsetHeight + document.getElementById( 'post-header' ).offsetHeight + document.getElementById( 'post-feature' ).offsetHeight );
this.editor.addListener( EditorEvent.EDITOR_DELETE, f => this.handleEditorOptions( EditorEvent.EDITOR_DELETE ), false )
this.editor.addListener( EditorEvent.EDITOR_UPLOAD_POST_IMAGE, f => this.handleEditorOptions( EditorEvent.EDITOR_UPLOAD_POST_IMAGE ), false )
this.editor.addListener( EditorEvent.EDITOR_UPDATE, f => this.handleEditorOptions( EditorEvent.EDITOR_UPDATE ), false )
this.editor.addListener( EditorEvent.EDITOR_SAVE, f => this.handleEditorOptions( EditorEvent.EDITOR_SAVE ), false )
document.getElementById( 'post-image' ).addEventListener( 'change', e => this.handlePostImageAdd( e ), false );
TinyDatePicker( document.getElementById( 'post-date' ),
{
mode: 'dp-below',
format( date )
{
//return date;
return self.dateUtils.getDate( 'origin', date );
}
} );
}
this.start();
}
//--------------------------
// methods
//--------------------------
start()
{
let self = this;
new Animate().object(
{
targets: document.getElementById( 'loader' ),
duration: 300,
opacity: 0,
easing: 'easeInOutQuad',
complete: function()
{
document.getElementById( 'loader' ).style.display = 'none';
document.getElementById( 'loader' ).style.visibility = 'hidden';
new Animate().object(
{
targets: document.getElementById( 'header' ),
duration: 10,
opacity: 1,
easing: 'easeInOutQuad',
complete: function()
{
if ( document.getElementById( 'the-intro' ) ) document.getElementById( 'the-intro' ).style.opacity = 1;
if ( document.getElementById( 'blog-entry' ) ) document.getElementById( 'blog-entry' ).style.opacity = 1;
}
} );
}
} );
if ( document.getElementById( 'featured-image-drop' ) )
{
document.getElementById( 'featured-image-drop' ).addEventListener( 'dragover', this.handleDragOver, false );
document.getElementById( 'featured-image-drop' ).addEventListener( 'drop', this.handleDrop, false );
document.getElementById( 'featured-click' ).addEventListener( 'change', this.handleClicked, false );
if ( document.getElementById( 'new-upload-link' ) )
{
document.getElementById( 'new-upload-link' ).addEventListener( 'click', e =>
{
document.getElementById( 'featured-click' ).click();
} )
}
var optionButtons = document.querySelectorAll( '.post-option-btn' );
for ( var i = 0, length = optionButtons.length; i < length; i++ )
{
optionButtons[ i ].addEventListener( 'click', e => this.handlePostOptions( e ), false );
}
}
}
//--------------------------
// event handlers
//--------------------------
handlePostOptions( e )
{
let currentOption;
switch ( e.target.id )
{
case "option-page-icon":
case "option-page":
currentOption = document.getElementById( 'option-page' );
break;
case "option-feature-icon":
case "option-feature":
currentOption = document.getElementById( 'option-feature' );
break;
case "option-published-icon":
case "option-published":
currentOption = document.getElementById( 'option-published' );
break;
}
let active = currentOption.getAttribute( 'data-active' );
( active == 'false' ) ? currentOption.setAttribute( 'data-active', 'true' ): currentOption.setAttribute( 'data-active', 'false' )
}
handleEditorOptions( e )
{
switch ( e )
{
case EditorEvent.EDITOR_SAVE:
case EditorEvent.EDITOR_UPDATE:
let edit = false;
if ( e == EditorEvent.EDITOR_UPDATE ) edit = true;
new PostActions().submitPost( edit, PostEditor.uploadFiles ).then( ( response ) =>
{
let note = JSON.parse( response[ 'response' ][ 'request' ].response );
this.editor.notify( note.message, note.postID );
if ( note.message == DataEvent.POST_ADDED ) window.location = "/@/dashboard/posts/edit/" + note.postID;
} ).catch( ( err ) =>
{
console.log( err )
} );
break;
case EditorEvent.EDITOR_DELETE:
if ( confirm( 'Aye! You know you\'re deleting this post, right?' ) )
{
new PostActions().deletePost().then( ( response ) =>
{
let note = JSON.parse( response[ 'response' ][ 'request' ].response );
window.location = "/@/dashboard/posts/";
//console.log(note);
} ).catch( ( err ) =>
{
console.log( err )
} );
}
else
{
// Do nothing!
}
break;
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
document.getElementById( 'post-image' ).click();
break;
}
}
handleDragOver( e )
{
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
handleClicked( e )
{
e.stopPropagation();
e.preventDefault();
//console.log("IMAGES " + e.target.files);
PostEditor.uploadFiles = e.target.files;
for ( var i = 0, f; f = PostEditor.uploadFiles[ i ]; i++ )
{
// Only process image files.
if ( !f.type.match( 'image.*' ) )
{
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = ( function( theFile )
{
return function( f )
{
// Render thumbnail.
var image = document.createElement( 'img' );
image.src = f.target.result;
image.title = escape( theFile.name );
var span = document.createElement( 'div' );
span.innerHTML = [ '<img src="',
f.target.result, '" title="',
escape( theFile.name ), '"/>'
].join( '' );
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById( 'featured-image-drop' ).innerHTML = '';
document.getElementById( 'featured-image-drop' ).appendChild( image );
};
} )( f );
// Read in the image file as a data URL.
reader.readAsDataURL( f );
}
}
handleDrop( e )
{
e.stopPropagation();
e.preventDefault();
PostEditor.uploadFiles = e.dataTransfer.files;
//console.log(MemberArea.uploadFiles.length);
for ( var i = 0, f; f = PostEditor.uploadFiles[ i ]; i++ )
{
// Only process image files.
if ( !f.type.match( 'image.*' ) )
{
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = ( function( theFile )
{
return function( f )
{
// Render thumbnail.
var span = document.createElement( 'span' );
span.innerHTML = [ '<img src="',
f.target.result, '" title="',
escape( theFile.name ), '"/>'
].join( '' );
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById( 'featured-image-drop' ).innerHTML = '';
document.getElementById( 'featured-image-drop' ).appendChild( span );
};
} )( f );
// Read in the image file as a data URL.
reader.readAsDataURL( f );
}
}
handlePostImageAdd( e )
{
e.stopPropagation();
e.preventDefault();
let self = this;
var postData = new FormData();
var files = e.target.files;
for ( var i = 0; i < files.length; i++ )
{
var file = files[ i ];
// Check the file type.
if ( !file.type.match( 'image.*' ) )
{
continue;
}
postData.append( 'post_image', file, file.name );
}
this.dataUtils.request( "/api/blog/add-post-image", DataEvent.POST_IMAGE_ADDED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, postData ).then( ( response ) =>
{
self.editor.notify( EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse( response.request[ 'response' ] ).url );
} ).catch( ( err ) =>
{
console.log( err )
} )
}
}
PostEditor.uploadFiles = [];
export
{
PostEditor as
default
}

@ -1,263 +0,0 @@
//TOOLS
import DataUtils, {
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
} from '../tools/utilities/DataUtils';
import * as DataEvent from '../tools/events/DataEvent';
import Animate from '../tools/effects/Animate';
import * as Ease from '../tools/effects/Animate';
import PostActions from '../actions/PostActions';
import * as EditorEvent from '../tools/events/EditorEvent';
import TextEditor from '../tools/utilities/TextEditor';
import TinyDatePicker from 'tiny-date-picker';
import DateUtils from '../tools/utilities/DateUtils';
class PostEditor {
//--------------------------
// constructor
//--------------------------
constructor() {
reframe('iframe');
let self = this;
this.uploadFiles;
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
if (document.getElementById('edit-post-text')) {
this.editor = new TextEditor(document.getElementById('edit-post-text'),
document.getElementById('header').offsetHeight +
document.getElementById('post-header').offsetHeight +
document.getElementById('post-feature').offsetHeight
);
this.editor.addListener(EditorEvent.EDITOR_DELETE, f => this.handleEditorOptions(EditorEvent.EDITOR_DELETE), false)
this.editor.addListener(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, f => this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE), false)
this.editor.addListener(EditorEvent.EDITOR_UPDATE, f => this.handleEditorOptions(EditorEvent.EDITOR_UPDATE), false)
this.editor.addListener(EditorEvent.EDITOR_SAVE, f => this.handleEditorOptions(EditorEvent.EDITOR_SAVE), false)
document.getElementById('post-image').addEventListener('change', e => this.handlePostImageAdd(e), false);
TinyDatePicker(document.getElementById('post-date'), {
mode: 'dp-below',
format(date) {
//return date;
return self.dateUtils.getDate('origin', date);
}
});
}
this.start();
}
//--------------------------
// methods
//--------------------------
start() {
let self = this;
new Animate().object({
targets: document.getElementById('loader'),
duration: 300,
opacity: 0,
easing: 'easeInOutQuad',
complete: function () {
document.getElementById('loader').style.display = 'none';
document.getElementById('loader').style.visibility = 'hidden';
new Animate().object({
targets: document.getElementById('header'),
duration: 10,
opacity: 1,
easing: 'easeInOutQuad',
complete: function () {
if (document.getElementById('the-intro'))
document.getElementById('the-intro').style.opacity = 1;
if (document.getElementById('blog-entry'))
document.getElementById('blog-entry').style.opacity = 1;
}
});
}
});
if (document.getElementById('featured-image-drop')) {
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleDragOver, false);
document.getElementById('featured-image-drop').addEventListener('drop', this.handleDrop, false);
document.getElementById('featured-click').addEventListener('change', this.handleClicked, false);
if (document.getElementById('new-upload-link')) {
document.getElementById('new-upload-link').addEventListener('click', e => {
document.getElementById('featured-click').click();
})
}
var optionButtons = document.querySelectorAll('.post-option-btn');
for (var i = 0, length = optionButtons.length; i < length; i++) {
optionButtons[i].addEventListener('click', e => this.handlePostOptions(e), false);
}
}
}
//--------------------------
// event handlers
//--------------------------
handlePostOptions(e) {
let currentOption;
switch (e.target.id) {
case "option-page-icon":
case "option-page":
currentOption = document.getElementById('option-page');
break;
case "option-feature-icon":
case "option-feature":
currentOption = document.getElementById('option-feature');
break;
case "option-published-icon":
case "option-published":
currentOption = document.getElementById('option-published');
break;
}
let active = currentOption.getAttribute('data-active');
(active == 'false') ? currentOption.setAttribute('data-active', 'true') : currentOption.setAttribute('data-active', 'false')
}
handleEditorOptions(e) {
switch (e) {
case EditorEvent.EDITOR_SAVE:
case EditorEvent.EDITOR_UPDATE:
let edit = false;
if (e == EditorEvent.EDITOR_UPDATE)
edit = true;
new PostActions().submitPost(edit, PostEditor.uploadFiles).then((response) => {
let note = JSON.parse(response['response']['request'].response);
this.editor.notify(note.message, note.postID);
if (note.message == DataEvent.POST_ADDED)
window.location = "/@/dashboard/posts/edit/" + note.postID;
}).catch((err) => {
console.log(err)
});
break;
case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?')) {
new PostActions().deletePost().then((response) => {
let note = JSON.parse(response['response']['request'].response);
window.location = "/@/dashboard/posts/";
//console.log(note);
}).catch((err) => {
console.log(err)
});
} else {
// Do nothing!
}
break;
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
document.getElementById('post-image').click();
break;
}
}
handleDragOver(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
handleClicked(e) {
e.stopPropagation();
e.preventDefault();
//console.log("IMAGES " + e.target.files);
PostEditor.uploadFiles = e.target.files;
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (f) {
// Render thumbnail.
var image = document.createElement('img');
image.src = f.target.result;
image.title = escape(theFile.name);
var span = document.createElement('div');
span.innerHTML = [
'<img src="',
f.target.result,
'" title="',
escape(theFile.name),
'"/>'
].join('');
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(image);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
handleDrop(e) {
e.stopPropagation();
e.preventDefault();
PostEditor.uploadFiles = e.dataTransfer.files;
//console.log(MemberArea.uploadFiles.length);
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (f) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = [
'<img src="',
f.target.result,
'" title="',
escape(theFile.name),
'"/>'
].join('');
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(span);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
handlePostImageAdd(e) {
e.stopPropagation();
e.preventDefault();
let self = this;
var postData = new FormData();
var files = e.target.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
// Check the file type.
if (!file.type.match('image.*')) {
continue;
}
postData.append('post_image', file, file.name);
}
this.dataUtils.request("/api/blog/add-post-image", DataEvent.POST_IMAGE_ADDED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, postData)
.then((response) => {
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
}).catch((err) => {
console.log(err)
})
}
}
PostEditor.uploadFiles = [];
export {
PostEditor as
default
}
Loading…
Cancel
Save