Commit 6c606c3b by ramdayalmunda

loading and saving completed

parent 1aec68cb
......@@ -830,6 +830,26 @@ var ADocEditor = function (customConfig) {
}
var returnObj = {
getDocumentData(){
let activeDataIndex = dataList.findIndex( item => item.id == caretData.activeData.id )
let returnObj = {
config: JSON.parse( JSON.stringify(config) ),
content: JSON.parse( JSON.stringify(dataList) ),
caretData: JSON.parse( JSON.stringify(caretData) )
}
delete returnObj.caretData.activeData
returnObj.caretData.activeDataIndex = activeDataIndex
return returnObj
},
setDocumentData(data){
// might need to change some configuration
dataList = JSON.parse( JSON.stringify( data.content ) )
config = JSON.parse( JSON.stringify( data.config ) )
caretData = JSON.parse( JSON.stringify( data.caretData ) )
caretData.activeData = dataList[data.caretData.activeDataIndex]
reRenderCanvas()
},
addFonts,
getConfiguration() { return JSON.parse(JSON.stringify(config)) },
getPages() {
......
......@@ -25,7 +25,8 @@
<p style="font-family: 'Calibri';">Click on the <span>canvas</span> and start typing
<input />
<button onclick="log()">Log</button>
<button onclick="setData()">Set Data</button>
<button onclick="getDocumentData()">Save Data</button>
<button onclick="setData()">Load Saved Data</button>
<button onclick="generatePDF()">Generate PDF</button>
</p>
<div id="user-container-for-editor"></div>
......
......@@ -13,15 +13,27 @@ var tempDocData = [
var editor = new ADocEditor({
container: document.getElementById("user-container-for-editor")
})
var extractedData = null
editor.focusOnPage()
var extractedData = null
function getDocumentData(){
let data = editor.getDocumentData()
console.log(data)
localStorage.setItem('oldData', JSON.stringify( data ))
extractedData = data
return data
}
function log() {
editor.log()
}
function setData() {
editor.loadContent(extractedData)
if (!extractedData) extractedData = JSON.parse( localStorage.getItem('oldData') )
if(extractedData){
editor.setDocumentData(extractedData)
}
}
function generatePDF() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment