|
|
@ -2,14 +2,14 @@
|
|
|
|
import FipamoAdminAPI, {
|
|
|
|
import FipamoAdminAPI, {
|
|
|
|
TASK_PAGE_CREATE,
|
|
|
|
TASK_PAGE_CREATE,
|
|
|
|
TASK_PAGE_EDIT,
|
|
|
|
TASK_PAGE_EDIT,
|
|
|
|
TASK_PAGE_DELETE
|
|
|
|
TASK_PAGE_DELETE,
|
|
|
|
} from '../../libraries/FipamoAdminAPI';
|
|
|
|
} from "../../libraries/FipamoAdminAPI";
|
|
|
|
import * as DataEvent from '../events/DataEvent';
|
|
|
|
import * as DataEvent from "../events/DataEvent";
|
|
|
|
import PageActions from '../actions/PageActions';
|
|
|
|
import PageActions from "../actions/PageActions";
|
|
|
|
import * as EditorEvent from '../events/EditorEvent';
|
|
|
|
import * as EditorEvent from "../events/EditorEvent";
|
|
|
|
//import TinyDatePicker from 'tiny-date-picker';
|
|
|
|
//import TinyDatePicker from 'tiny-date-picker';
|
|
|
|
import TextEditor from '../ui/TextEditor';
|
|
|
|
import TextEditor from "../ui/TextEditor";
|
|
|
|
import Notfications from '../ui/Notifications';
|
|
|
|
import Notfications from "../ui/Notifications";
|
|
|
|
const admin = new FipamoAdminAPI();
|
|
|
|
const admin = new FipamoAdminAPI();
|
|
|
|
const notify = new Notfications();
|
|
|
|
const notify = new Notfications();
|
|
|
|
export default class PostEditor {
|
|
|
|
export default class PostEditor {
|
|
|
@ -18,24 +18,28 @@ export default class PostEditor {
|
|
|
|
//--------------------------
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
|
|
|
constructor() {
|
|
|
|
let self = this;
|
|
|
|
let self = this;
|
|
|
|
this.urlPieces = document.URL.split('/');
|
|
|
|
this.urlPieces = document.URL.split("/");
|
|
|
|
this.post = [];
|
|
|
|
this.post = [];
|
|
|
|
this.postID = null;
|
|
|
|
this.postID = null;
|
|
|
|
this.postUUID = null;
|
|
|
|
this.postUUID = null;
|
|
|
|
this.postLayout = null;
|
|
|
|
this.postLayout = null;
|
|
|
|
if (document.getElementById('post-edit-index').getAttribute('data-index')) {
|
|
|
|
if (document.getElementById("post-edit-index").getAttribute("data-index")) {
|
|
|
|
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
|
|
|
|
this.postID = document
|
|
|
|
this.postUUID = document.getElementById('post-edit-index').getAttribute('data-uuid');
|
|
|
|
.getElementById("post-edit-index")
|
|
|
|
|
|
|
|
.getAttribute("data-index");
|
|
|
|
|
|
|
|
this.postUUID = document
|
|
|
|
|
|
|
|
.getElementById("post-edit-index")
|
|
|
|
|
|
|
|
.getAttribute("data-uuid");
|
|
|
|
this.postLayout = document
|
|
|
|
this.postLayout = document
|
|
|
|
.getElementById('post-edit-index')
|
|
|
|
.getElementById("post-edit-index")
|
|
|
|
.getAttribute('data-layout');
|
|
|
|
.getAttribute("data-layout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (document.getElementById('edit-post-text')) {
|
|
|
|
if (document.getElementById("edit-post-text")) {
|
|
|
|
this.editor = new TextEditor(
|
|
|
|
this.editor = new TextEditor(
|
|
|
|
document.getElementById('edit-post-text'),
|
|
|
|
document.getElementById("edit-post-text"),
|
|
|
|
document.getElementById('header').offsetHeight +
|
|
|
|
document.getElementById("header").offsetHeight +
|
|
|
|
document.getElementById('post-header').offsetHeight +
|
|
|
|
document.getElementById("post-header").offsetHeight +
|
|
|
|
document.getElementById('post-feature').offsetHeight
|
|
|
|
document.getElementById("post-feature").offsetHeight
|
|
|
|
);
|
|
|
|
);
|
|
|
|
this.editor.addListener(
|
|
|
|
this.editor.addListener(
|
|
|
|
EditorEvent.EDITOR_DELETE,
|
|
|
|
EditorEvent.EDITOR_DELETE,
|
|
|
@ -57,9 +61,9 @@ export default class PostEditor {
|
|
|
|
() => this.handleEditorOptions(EditorEvent.EDITOR_SAVE),
|
|
|
|
() => this.handleEditorOptions(EditorEvent.EDITOR_SAVE),
|
|
|
|
false
|
|
|
|
false
|
|
|
|
);
|
|
|
|
);
|
|
|
|
document.getElementById('post-image-upload').addEventListener(
|
|
|
|
document.getElementById("post-image-upload").addEventListener(
|
|
|
|
'change',
|
|
|
|
"change",
|
|
|
|
e => {
|
|
|
|
(e) => {
|
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false
|
|
|
|
false
|
|
|
@ -80,24 +84,30 @@ export default class PostEditor {
|
|
|
|
// methods
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
|
|
|
start() {
|
|
|
|
if (document.getElementById('featured-image-drop')) {
|
|
|
|
if (document.getElementById("featured-image-drop")) {
|
|
|
|
document
|
|
|
|
document
|
|
|
|
.getElementById('featured-image-drop')
|
|
|
|
.getElementById("featured-image-drop")
|
|
|
|
.addEventListener('dragover', this.handleImageActions, false);
|
|
|
|
.addEventListener("dragover", this.handleImageActions, false);
|
|
|
|
document
|
|
|
|
document
|
|
|
|
.getElementById('featured-image-drop')
|
|
|
|
.getElementById("featured-image-drop")
|
|
|
|
.addEventListener('drop', this.handleImageActions, false);
|
|
|
|
.addEventListener("drop", this.handleImageActions, false);
|
|
|
|
document
|
|
|
|
document
|
|
|
|
.getElementById('featured-image-upload')
|
|
|
|
.getElementById("featured-image-upload")
|
|
|
|
.addEventListener('change', e => this.handleImageActions(e), false);
|
|
|
|
.addEventListener("change", (e) => this.handleImageActions(e), false);
|
|
|
|
if (document.getElementById('new-feature-upload')) {
|
|
|
|
if (document.getElementById("new-feature-upload")) {
|
|
|
|
document.getElementById('new-feature-upload').addEventListener('click', () => {
|
|
|
|
document
|
|
|
|
document.getElementById('featured-image-upload').click();
|
|
|
|
.getElementById("new-feature-upload")
|
|
|
|
|
|
|
|
.addEventListener("click", () => {
|
|
|
|
|
|
|
|
document.getElementById("featured-image-upload").click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var optionButtons = document.querySelectorAll('.post-option-btn');
|
|
|
|
var optionButtons = document.querySelectorAll(".post-option-btn");
|
|
|
|
for (var i = 0, length = optionButtons.length; i < length; i++) {
|
|
|
|
for (var i = 0, length = optionButtons.length; i < length; i++) {
|
|
|
|
optionButtons[i].addEventListener('click', e => this.handlePostOptions(e), false);
|
|
|
|
optionButtons[i].addEventListener(
|
|
|
|
|
|
|
|
"click",
|
|
|
|
|
|
|
|
(e) => this.handlePostOptions(e),
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -107,37 +117,41 @@ export default class PostEditor {
|
|
|
|
handlePostOptions(e) {
|
|
|
|
handlePostOptions(e) {
|
|
|
|
let currentOption;
|
|
|
|
let currentOption;
|
|
|
|
switch (e.target.id) {
|
|
|
|
switch (e.target.id) {
|
|
|
|
case 'option-page-icon':
|
|
|
|
case "option-page-icon":
|
|
|
|
case 'option-menu-pin':
|
|
|
|
case "option-menu-pin":
|
|
|
|
currentOption = document.getElementById('option-menu-pin');
|
|
|
|
currentOption = document.getElementById("option-menu-pin");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'option-feature-icon':
|
|
|
|
case "option-feature-icon":
|
|
|
|
case 'option-feature':
|
|
|
|
case "option-feature":
|
|
|
|
currentOption = document.getElementById('option-feature');
|
|
|
|
currentOption = document.getElementById("option-feature");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'option-published-icon':
|
|
|
|
case "option-published-icon":
|
|
|
|
case 'option-published':
|
|
|
|
case "option-published":
|
|
|
|
currentOption = document.getElementById('option-published');
|
|
|
|
currentOption = document.getElementById("option-published");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let active = currentOption.getAttribute('data-active');
|
|
|
|
let active = currentOption.getAttribute("data-active");
|
|
|
|
active == 'false'
|
|
|
|
active == "false"
|
|
|
|
? currentOption.setAttribute('data-active', 'true')
|
|
|
|
? currentOption.setAttribute("data-active", "true")
|
|
|
|
: currentOption.setAttribute('data-active', 'false');
|
|
|
|
: currentOption.setAttribute("data-active", "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleEditorOptions(e) {
|
|
|
|
handleEditorOptions(e) {
|
|
|
|
switch (e) {
|
|
|
|
switch (e) {
|
|
|
|
case EditorEvent.EDITOR_SAVE:
|
|
|
|
case EditorEvent.EDITOR_SAVE:
|
|
|
|
case EditorEvent.EDITOR_UPDATE:
|
|
|
|
case EditorEvent.EDITOR_UPDATE:
|
|
|
|
var task = '';
|
|
|
|
var task = "";
|
|
|
|
e === EditorEvent.EDITOR_SAVE ? (task = TASK_PAGE_CREATE) : (task = TASK_PAGE_EDIT);
|
|
|
|
e === EditorEvent.EDITOR_SAVE
|
|
|
|
|
|
|
|
? (task = TASK_PAGE_CREATE)
|
|
|
|
|
|
|
|
: (task = TASK_PAGE_EDIT);
|
|
|
|
new PageActions()
|
|
|
|
new PageActions()
|
|
|
|
.collectInfo(document.getElementById('featured-image-upload').files[0])
|
|
|
|
.collectInfo(
|
|
|
|
.then(page => {
|
|
|
|
document.getElementById("featured-image-upload").files[0]
|
|
|
|
notify.alert('Writing down changes', null);
|
|
|
|
)
|
|
|
|
|
|
|
|
.then((page) => {
|
|
|
|
|
|
|
|
notify.alert("Writing down changes", null);
|
|
|
|
admin
|
|
|
|
admin
|
|
|
|
.pageActions(task, page)
|
|
|
|
.pageActions(task, page)
|
|
|
|
.then(r => {
|
|
|
|
.then((r) => {
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
r.type === DataEvent.PAGE_ERROR ||
|
|
|
|
r.type === DataEvent.PAGE_ERROR ||
|
|
|
|
r.type === DataEvent.API_REQUEST_LAME
|
|
|
|
r.type === DataEvent.API_REQUEST_LAME
|
|
|
@ -148,18 +162,18 @@ export default class PostEditor {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
window.location = '/@/dashboard/page/edit/' + r.id;
|
|
|
|
window.location = "/@/dashboard/page/edit/" + r.id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
.catch((err) => {
|
|
|
|
notify.alert(err, false);
|
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_DELETE:
|
|
|
|
case EditorEvent.EDITOR_DELETE:
|
|
|
|
if (this.postLayout === 'index') {
|
|
|
|
if (this.postLayout === "index") {
|
|
|
|
notify.alert('Index cannot be deleted', false);
|
|
|
|
notify.alert("Index cannot be deleted", false);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (confirm("AYE! You know you're deleting this post, right?")) {
|
|
|
|
if (confirm("AYE! You know you're deleting this post, right?")) {
|
|
|
@ -167,9 +181,9 @@ export default class PostEditor {
|
|
|
|
admin
|
|
|
|
admin
|
|
|
|
.pageActions(TASK_PAGE_DELETE, id)
|
|
|
|
.pageActions(TASK_PAGE_DELETE, id)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
window.location = '/@/dashboard/page/list/';
|
|
|
|
window.location = "/dashboard/pages";
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
.catch((err) => {
|
|
|
|
notify.alert(err, false);
|
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -177,7 +191,7 @@ export default class PostEditor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
|
|
document.getElementById('post-image-upload').click();
|
|
|
|
document.getElementById("post-image-upload").click();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,17 +199,17 @@ export default class PostEditor {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
switch (e.type) {
|
|
|
|
switch (e.type) {
|
|
|
|
case 'dragover':
|
|
|
|
case "dragover":
|
|
|
|
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
|
|
|
|
e.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy.
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'change':
|
|
|
|
case "change":
|
|
|
|
case 'drop':
|
|
|
|
case "drop":
|
|
|
|
e.type == 'drop'
|
|
|
|
e.type == "drop"
|
|
|
|
? (PostEditor.uploadFiles = e.dataTransfer.files)
|
|
|
|
? (PostEditor.uploadFiles = e.dataTransfer.files)
|
|
|
|
: (PostEditor.uploadFiles = e.target.files);
|
|
|
|
: (PostEditor.uploadFiles = e.target.files);
|
|
|
|
for (var i = 0, f; (f = PostEditor.uploadFiles[i]); i++) {
|
|
|
|
for (var i = 0, f; (f = PostEditor.uploadFiles[i]); i++) {
|
|
|
|
// Only process image files.
|
|
|
|
// Only process image files.
|
|
|
|
if (!f.type.match('image.*')) {
|
|
|
|
if (!f.type.match("image.*")) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var reader = new FileReader();
|
|
|
|
var reader = new FileReader();
|
|
|
@ -203,19 +217,19 @@ export default class PostEditor {
|
|
|
|
reader.onload = (function (theFile) {
|
|
|
|
reader.onload = (function (theFile) {
|
|
|
|
return function (f) {
|
|
|
|
return function (f) {
|
|
|
|
// Render thumbnail.
|
|
|
|
// Render thumbnail.
|
|
|
|
var image = document.createElement('img');
|
|
|
|
var image = document.createElement("img");
|
|
|
|
image.src = f.target.result;
|
|
|
|
image.src = f.target.result;
|
|
|
|
image.title = escape(theFile.name);
|
|
|
|
image.title = escape(theFile.name);
|
|
|
|
var span = document.createElement('div');
|
|
|
|
var span = document.createElement("div");
|
|
|
|
span.innerHTML = [
|
|
|
|
span.innerHTML = [
|
|
|
|
'<img src="',
|
|
|
|
'<img src="',
|
|
|
|
f.target.result,
|
|
|
|
f.target.result,
|
|
|
|
'" title="',
|
|
|
|
'" title="',
|
|
|
|
escape(theFile.name),
|
|
|
|
escape(theFile.name),
|
|
|
|
'"/>'
|
|
|
|
'"/>',
|
|
|
|
].join('');
|
|
|
|
].join("");
|
|
|
|
document.getElementById('featured-image-drop').innerHTML = '';
|
|
|
|
document.getElementById("featured-image-drop").innerHTML = "";
|
|
|
|
document.getElementById('featured-image-drop').appendChild(image);
|
|
|
|
document.getElementById("featured-image-drop").appendChild(image);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})(f);
|
|
|
|
})(f);
|
|
|
|
// Read in the image file as a data URL.
|
|
|
|
// Read in the image file as a data URL.
|
|
|
@ -225,16 +239,16 @@ export default class PostEditor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleImageUpload(type, files) {
|
|
|
|
handleImageUpload(type, files) {
|
|
|
|
let self = this;
|
|
|
|
let self = this;
|
|
|
|
notify.alert('Uploading Image', null);
|
|
|
|
notify.alert("Uploading Image", null);
|
|
|
|
admin
|
|
|
|
admin
|
|
|
|
.imageUpload(type, files)
|
|
|
|
.imageUpload(type, files)
|
|
|
|
.then(r => {
|
|
|
|
.then((r) => {
|
|
|
|
if (r.type == DataEvent.POST_IMAGE_ADDED)
|
|
|
|
if (r.type == DataEvent.POST_IMAGE_ADDED)
|
|
|
|
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
|
|
|
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
|
|
|
notify.alert('Image Added to Entry', true);
|
|
|
|
notify.alert("Image Added to Entry", true);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
.catch(() => {
|
|
|
|
notify.alert('Uh oh. Image not added', false);
|
|
|
|
notify.alert("Uh oh. Image not added", false);
|
|
|
|
//console.log('ERROR', err);
|
|
|
|
//console.log('ERROR', err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|