Formatter
Mon Jan 27 2014 14:49:11 GMT+0100 (Central Europe Standard Time)
enabled
# OneNote in Lively Yeah, finally I can also access my one note notes. module("lively.net.OneNote") is added to world requirements. So let's explore the API from http://dev.onenote.com/docs a bit. Lets start at the root and see what notebooks I have in my Notebooks:
And now we get the sections:
notebookId = this.get("NotebookList").selection.id
r = lively.net.OneNote.get("notebooks/"+ notebookId
    + "/sections?select=name,id", 'application/json', true);
if (!r.content) throw new Error("No result")
sections = JSON.parse(r.content);
this.get("SectionList").setList(sections.collect(function(ea){
    return {string: ea.name, value: ea}
}))
r.content
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
[ { "id": "0-D333AEE656452F8B!169954", "name": "TestList" }, { "id": "0-D333AEE656452F8B!2067", "name": "ToBeLoaded" }, { "id": "0-D333AEE656452F8B!2065", "name": "ToBeRead" }, { "id": "0-D333AEE656452F8B!2066", "name": "ToBeSeen" } ]
[ { "id": "0-D333AEE656452F8B!101398", "name": "Games" }, { "id": "0-D333AEE656452F8B!2051", "name": "GTD" }, { "id": "0-D333AEE656452F8B!1805", "name": "Journal" }, { "id": "0-D333AEE656452F8B!2062", "name": "Lists" }, { "id": "0-D333AEE656452F8B!1867", "name": "Lively" }, { "id": "0-D333AEE656452F8B!196988", "name": "Lively4" }, { "id": "0-D333AEE656452F8B!189602", "name": "My Notebook" }, { "id": "0-D333AEE656452F8B!894", "name": "Notes" }, { "id": "0-D333AEE656452F8B!2206", "name": "Notizbuch von Jens" }, { "id": "0-D333AEE656452F8B!1494", "name": "SWA" }, { "id": "0-D333AEE656452F8B!1501", "name": "Thesis" } ]
r = lively.net.OneNote.get("notebooks?select=name,id", 'application/json', true);
if (!r.content) throw new Error("No result")
notebooks = JSON.parse(r.content);
this.get("NotebookList").setList(notebooks.collect(function(ea){
    return {string: ea.name, value: ea}
}))
r.content
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
[ { "id": "0-8c315222da8c476596b92b4b159ec4f1!4-D333AEE656452F8B!169954", "title": "" }, { "id": "0-d277a55b04d2418cb8238a97b25d6656!9-D333AEE656452F8B!169954", "title": "TestPage" } ]
sectionId = this.get("SectionList").selection.id
r = lively.net.OneNote.get("/sections/" +  sectionId + "/pages"
    + "?select=title,id", 'application/json', true);
if (r.content) pages = JSON.parse(r.content);
this.get("PagesList").setList(pages.collect(function(ea){
    return {string: ea.title, value: ea}
}))
r.content
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
... and the pages
So, we have a page now. Can we look inside?
<html xmlns="http://www.w3.org/1999/xhtml" lang="de-DE"> <head> <title>TestPage</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="created" content="2015-06-03T13:25:00.0000000" /> </head> <body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt"> <div id="div:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{113}" style="position:absolute;left:58px;top:114px;width:624px"> <h1 id="h1:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{117}" lang="en-US" style="font-size:16pt;color:#1e4e79;margin-top:0pt;margin-bottom:0pt">A header</h1> <ul id="ul:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{118}"> <li id="li:{5b449127-f843-44bb-97e5-e05926b3cf9f}{6}"><span lang="en-US">item1</span></li> <li id="li:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{134}"><p id="p:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{145}" lang="en-US" style="margin-top:0pt;margin-bottom:0pt">Item2</p> <ul id="ul:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{146}"> <li id="li:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{157}" style="list-style-type:circle"><span lang="en-US">Sublist 1</span></li> <li id="li:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{174}" style="list-style-type:circle"><span lang="en-US">Sublist 2</span></li> </ul> </li> </ul> <br /> <p id="p:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{203}" lang="en-US" style="margin-top:0pt;margin-bottom:0pt">And this is a paragraph.</p> <p id="p:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{232}" lang="en-US" style="margin-top:0pt;margin-bottom:0pt">And this?</p> <p id="p:{85276b74-153d-4f23-b2d8-36666ea7c8e2}{252}" lang="en-US" style="margin-top:0pt;margin-bottom:0pt">Nothing.</p> <br /> </div> <div id="div:{5b449127-f843-44bb-97e5-e05926b3cf9f}{105}" style="position:absolute;left:325px;top:114px;width:624px"> <br /> </div> </body> </html>
pageId = this.get("PagesList").selection.id
r = lively.net.OneNote.get("/pages/" +  pageId + "/content?includeIDs=true", 
    'text/html', true);
$morph("OneNotePagePreview").setHTML(r.content)
pageXML = $.parseXML(r.content)
r.content
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
Journal
Lists
Lively
Lively4
My Notebook
Notes
Notizbuch von Jens
TestList
ToBeLoaded
ToBeRead
ToBeSeen
[object Object]
TestPage
# Updating Page content Since we queried the content with ids, we can use those ids to generate PATCH request. But we should be aware that "generated id values might change after a page update, so you should get the current values before building a PATCH request that uses them." [https://msdn.microsoft.com/EN-US/library/office/dn600337.aspx]
<html xmlns="http://www.w3.org/1999/xhtml" lang="de-DE"> <head> <title>Einkaufen</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="created" content="2014-11-26T16:19:00.0000000" /> </head> <body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt"> <div id="div:{59111831-ffe5-2949-a0bc-334467ceb3f3}{30}" style="position:absolute;left:48px;top:115px;width:720px"> <br /> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{36}" lang="en-US" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">T&#252;rvorhang + Schiene </p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{38}" lang="en-US" data-tag="to-do:completed" style="margin-top:0pt;margin-bottom:0pt">Sarotan kaufen </p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{40}" lang="en-US" data-tag="to-do:completed" style="margin-top:0pt;margin-bottom:0pt">Cr&#234;pe Papier </p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{42}" lang="en-US" data-tag="to-do:completed" style="margin-top:0pt;margin-bottom:0pt">Und Waschmittel kaufen </p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{44}" lang="en-US" data-tag="to-do:completed" style="margin-top:0pt;margin-bottom:0pt">Toilettenreiniger kaufen </p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{46}" lang="en-US" data-tag="to-do:completed" style="margin-top:0pt;margin-bottom:0pt">Schuhe zum Schuster bringen</p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{48}" lang="en-US" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Blumentopf mit 30 cm Durchmesser kaufen</p> <p id="p:{59111831-ffe5-2949-a0bc-334467ceb3f3}{51}" lang="en-US" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Glasreiniger kaufen </p> </div> </body> </html>
paragraphs = pageXML.getElementsByTagName("p")
paragraphs[0].textContent
this.get("ParagraphList").setList($A(paragraphs).collect(function(ea){
    return {string: ea.textContent, value: ea}
}))
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
Türvorhang + Schiene
Sarotan kaufen
Crêpe Papier
Und Waschmittel kaufen
Toilettenreiniger kaufen
Schuhe zum Schuster bringen
Blumentopf mit 30 cm Durchmesser kaufen
[object Object]
paragraph = this.get("ParagraphList").selection
paragraphId = paragraph.id
newText = this.get("ParagraphEdit").textString
replacePatch = [
  {
    'target': paragraphId,
    'action':'replace',
    'content':'<p>'+ newText+'</p>'
  }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Do it
maximize
Sarotan kaufen @done
# Conclusion And than closes the loop. We can get content from OneNote, update or add to it as we please. An open issue is how we can deal with conflicts on the paragraph level, due to changing ids. But it seems to merge changes on different paragraphs without a problem.
First we get all paragraphs and display them in list:
Then we select one of them and edit its content. After this the changes are send back as a PATCH.
TestPage

A header

  • item1
  • Item2

    • Sublist 1
    • Sublist 2

And this is a paragraph.

And this?

Nothing.