2022-02-23 15:48:11 -08:00
|
|
|
import StringUtils from '../utils/StringUtils';
|
2019-11-21 22:36:18 -08:00
|
|
|
export default class PostActions {
|
2022-05-16 17:41:15 -07:00
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
collectInfo(files) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let pageInfo = new FormData();
|
2022-09-18 13:07:52 -07:00
|
|
|
pageInfo.enctype = 'multipart/form-data';
|
2022-05-16 17:41:15 -07:00
|
|
|
let txt = document.createElement('textarea');
|
|
|
|
txt.innerHTML = document.getElementById('highlight-content').innerHTML;
|
|
|
|
let html = txt.value;
|
|
|
|
html = html.replace(/<\/?span[^>]*>/g, ''); //removes prism styling
|
|
|
|
html = html.replace(/<\/?br[^>]*>/g, '\n'); //convert back to encoded line break for storage
|
|
|
|
pageInfo.append(
|
|
|
|
'id',
|
|
|
|
document.getElementById('post-edit-index').getAttribute('data-index')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'uuid',
|
|
|
|
document.getElementById('post-edit-index').getAttribute('data-uuid')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'layout',
|
|
|
|
document.getElementById('post-edit-index').getAttribute('data-layout')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'current_title',
|
|
|
|
document.getElementById('post-edit-index').getAttribute('data-slug')
|
|
|
|
);
|
|
|
|
pageInfo.append('content', html);
|
|
|
|
pageInfo.append('title', document.getElementById('post-title-text').value);
|
|
|
|
pageInfo.append(
|
|
|
|
'created',
|
|
|
|
document.getElementById('post-date').getAttribute('data-raw')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'slug',
|
|
|
|
new StringUtils().cleanString(
|
|
|
|
document.getElementById('post-title-text').value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
pageInfo.append('tags', document.getElementById('post-tags').value);
|
|
|
|
pageInfo.append(
|
|
|
|
'menu',
|
|
|
|
document.getElementById('option-menu-pin').getAttribute('data-active')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'featured',
|
|
|
|
document.getElementById('option-feature').getAttribute('data-active')
|
|
|
|
);
|
|
|
|
pageInfo.append(
|
|
|
|
'published',
|
|
|
|
document.getElementById('option-published').getAttribute('data-active')
|
|
|
|
);
|
|
|
|
pageInfo.append('layout', document.getElementById('page-templates').value);
|
|
|
|
pageInfo.append('form_token', document.getElementById('form_token').value);
|
|
|
|
if (files.length > 0 && files != null) {
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var file = files[i];
|
|
|
|
if (
|
|
|
|
file.type.match('image.*') ||
|
|
|
|
file.type.match('video.mp4') ||
|
|
|
|
file.type.match('audio.mpeg') ||
|
|
|
|
file.type.match('application.pdf') ||
|
|
|
|
file.type.match('text.plain') ||
|
|
|
|
file.type.match('text.rtf')
|
|
|
|
) {
|
|
|
|
pageInfo.append('page_files[]', file, file.name);
|
|
|
|
} else {
|
2022-05-18 16:41:25 -07:00
|
|
|
reject('Not an image file: ' + file.type);
|
2022-05-16 17:41:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//check to see if image exists
|
|
|
|
if (document.getElementById('featured-image')) {
|
|
|
|
var imageURL = document.getElementById('featured-image').src;
|
|
|
|
imageURL != null || imageURL != undefined
|
|
|
|
? pageInfo.append('feature_image', imageURL)
|
|
|
|
: pageInfo.append('feature_image', null);
|
|
|
|
} else {
|
|
|
|
//pageInfo.append("feature_image", null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//console.log("FILES", files);
|
|
|
|
resolve(pageInfo);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// event handlers
|
|
|
|
//--------------------------
|
2019-11-21 22:36:18 -08:00
|
|
|
}
|