fipamo/public/assets/scripts/dash/app/actions/PageActions.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

import StringUtils from '../utils/StringUtils.js';
export default class PostActions {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
collectInfo(files) {
return new Promise((resolve, reject) => {
let pageInfo = [];
let pageRef = document.querySelector('[role="file-manager"]');
//process html content for storage
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
//build data object
pageInfo = {
id: pageRef.getAttribute('data-index'),
uuid: pageRef.getAttribute('data-uuid'),
layout: document.getElementById('page-templates').value,
current_title: pageRef.getAttribute('data-slug'),
content: html,
title: document.getElementById('post-title-text').value,
created: document.getElementById('post-date').getAttribute('data-raw'),
slug: new StringUtils().cleanString(
document.getElementById('post-title-text').value
),
tags: document.getElementById('post-tags').value,
menu: document
.getElementById('option-menu-pin')
.getAttribute('data-active'),
featured: document
.getElementById('option-feature')
.getAttribute('data-active'),
published: document
.getElementById('option-published')
.getAttribute('data-active'),
form_token: document.getElementById('form_token').value,
imageList: files.images,
fileList: files.files
};
resolve(pageInfo);
});
}
//--------------------------
// event handlers
//--------------------------
}