2018-08-17 11:24:00 -07:00
|
|
|
import CKEditor from '@ckeditor/ckeditor5-build-balloon';
|
|
|
|
|
import './AppreciationEditor.html';
|
|
|
|
|
import swal from "sweetalert2";
|
2018-08-14 10:56:12 -07:00
|
|
|
|
2018-08-17 11:24:00 -07:00
|
|
|
let originalData = "";
|
|
|
|
|
|
|
|
|
|
Tracker.autorun(function() {
|
|
|
|
|
Meteor.subscribe("pages");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.AppreciationEditor.onRendered(function() {
|
|
|
|
|
let _this = this;
|
|
|
|
|
|
|
|
|
|
//#appreciationEditor'
|
|
|
|
|
CKEditor.create(document.querySelector('#editor'), {}).then(editor => {
|
|
|
|
|
_this.ckEditor = editor;
|
|
|
|
|
|
|
|
|
|
Tracker.autorun(function() {
|
|
|
|
|
let doc = Meteor.collections.Pages.findOne({name: 'Appreciation'});
|
|
|
|
|
|
|
|
|
|
originalData = (doc === undefined ? "" : doc.html);
|
|
|
|
|
editor.setData(originalData);
|
|
|
|
|
});
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.AppreciationEditor.onDestroyed(function() {
|
|
|
|
|
let data = this.ckEditor.getData();
|
|
|
|
|
|
|
|
|
|
if(data != originalData) {
|
|
|
|
|
swal({
|
|
|
|
|
title: "Save Changes",
|
|
|
|
|
text: "Would you like to save any changes you have made to this sheet?",
|
|
|
|
|
type: "question",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
confirmButtonColor: "#7cdd7f",
|
|
|
|
|
confirmButtonText: "Yes",
|
|
|
|
|
cancelButtonText: "No"
|
|
|
|
|
}).then(
|
|
|
|
|
function(isConfirm) {
|
|
|
|
|
if(isConfirm) {
|
|
|
|
|
Meteor.call('updatePage', 'Appreciation', data, function (error, result) {
|
|
|
|
|
if (error) sAlert.error(error);
|
|
|
|
|
else sAlert.success("Content Saved Successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
function(dismiss) {}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.AppreciationEditor.helpers({
|
|
|
|
|
// html: function() {
|
|
|
|
|
// let doc = Meteor.collections.Pages.findOne({name: 'Appreciation'});
|
|
|
|
|
//
|
|
|
|
|
// return doc == undefined ? "" : doc.html;
|
|
|
|
|
// }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.AppreciationEditor.events({
|
|
|
|
|
'click #save': function(event, template) {
|
|
|
|
|
let data = template.ckEditor.getData();
|
|
|
|
|
|
|
|
|
|
if(data != originalData) {
|
|
|
|
|
Meteor.call('updatePage', 'Appreciation', data, function (error, result) {
|
|
|
|
|
if (error) sAlert.error(error);
|
|
|
|
|
else sAlert.success("Content Saved Successfully");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sAlert.success("Data has not changed!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|