1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Moved page editing to angular controller and started work on update drafts

This commit is contained in:
Dan Brown
2016-03-09 22:32:07 +00:00
parent 1d6137f7e2
commit 59ce228c2e
14 changed files with 202 additions and 32 deletions

View File

@ -213,4 +213,49 @@ module.exports = function (ngApp, events) {
}]);
ngApp.controller('PageEditController', ['$scope', '$http', '$attrs', '$interval', function ($scope, $http, $attrs, $interval) {
$scope.editorOptions = require('./pages/page-form');
$scope.editorHtml = '';
$scope.draftText = '';
var pageId = Number($attrs.pageId);
var isEdit = pageId !== 0;
if (isEdit) {
startAutoSave();
}
$scope.editorChange = function() {
$scope.draftText = '';
}
function startAutoSave() {
var currentTitle = $('#name').val();
var currentHtml = $scope.editorHtml;
console.log('Starting auto save');
$interval(() => {
var newTitle = $('#name').val();
var newHtml = $scope.editorHtml;
if (newTitle !== currentTitle || newHtml !== currentHtml) {
currentHtml = newHtml;
currentTitle = newTitle;
saveDraftUpdate(newTitle, newHtml);
}
}, 1000*5);
}
function saveDraftUpdate(title, html) {
$http.put('/ajax/page/' + pageId + '/save-draft', {
name: title,
html: html
}).then((responseData) => {
$scope.draftText = 'Draft saved'
})
}
}]);
};

View File

@ -162,5 +162,31 @@ module.exports = function (ngApp, events) {
};
}]);
ngApp.directive('tinymce', [function() {
return {
restrict: 'A',
scope: {
tinymce: '=',
ngModel: '=',
ngChange: '='
},
link: function (scope, element, attrs) {
function tinyMceSetup(editor) {
editor.on('keyup', (e) => {
var content = editor.getContent();
scope.$apply(() => {
scope.ngModel = content;
});
scope.ngChange(content);
});
}
scope.tinymce.extraSetups.push(tinyMceSetup);
tinymce.init(scope.tinymce);
}
}
}])
};

View File

@ -119,11 +119,5 @@ function elemExists(selector) {
return document.querySelector(selector) !== null;
}
// TinyMCE editor
if (elemExists('#html-editor')) {
var tinyMceOptions = require('./pages/page-form');
tinymce.init(tinyMceOptions);
}
// Page specific items
require('./pages/page-show');
require('./pages/page-show');

View File

@ -1,4 +1,4 @@
module.exports = {
var mceOptions = module.exports = {
selector: '#html-editor',
content_css: [
'/css/styles.css'
@ -51,8 +51,15 @@ module.exports = {
args.content = '';
}
},
extraSetups: [],
setup: function (editor) {
console.log(mceOptions.extraSetups);
for (var i = 0; i < mceOptions.extraSetups.length; i++) {
mceOptions.extraSetups[i](editor);
}
(function () {
var wrap;