Storing / Printing Data
From the Official Quill Documentation:
Code:
Rich text editors lack a specification to express its own contents.
Until recently, most rich text editors did not even know what was in their own edit areas.
These editors just pass the user HTML, along with the burden of parsing and interpretting
this. At any given time, this interpretation will differ from those of major browser
vendors, leading to different editing experiences for users.
Quill is the first rich text editor to actually understand its own contents.
Key to this is Deltas, the specification describing rich text. Deltas are designed to
be easy to understand and use. We will walk through some of the thinking behind Deltas,
to shed light on why things are the way they are.
All that said, I don't use Deltas. I researched it but still don't understand how to implement.
We shall use the good old
HTML....
Feel free to create
your own tutorial that teaches us how to use Deltas properly.
Data:
The following is an example of HTML text stored in a MySQL table (saved from the editor). Note the use of Quill CSS embedded within the content.
HTML:
<p class="ql-indent-1">KTSA <strong>showed </strong>their views...</p><ol><li data-list="bullet" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>These issues were cited:</li><li data-list="bullet" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>rapid gunfire noise</li><li data-list="bullet" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>lead contamination</li><li data-list="bullet" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>no ro most times</li><li data-list="bullet" class="ql-indent-1"><span class="ql-ui" contenteditable="false"></span>poaching of KTSA members</li></ol><p><br></p>
When we display this content (read only), we shall always use the CompQuillEditor custom component, since it uses the associated CSS file.
If you use an ABMLabel with .TextAsRAWHTML to display this data - the format will be mostly WRONG since ABMLabel does not use the CSS file (hence RAW HTML).
Printing or Saving as PDF File
Printing and saving has been, in the past, a
horrible and
time consuming coding project - fraught with errors and frustration...
Now my good friends, it
COULD NOT be more
Simple! One clean function...
The PrintEditor method - supplied by @alwaysbusy
B4X:
public Sub PrintEditor(id As String)
Dim Script As String = $"
var divContents = $("#${id}").html();
var a = window.open('', '','');
a.document.write('<html>');
a.document.write('<head>');
a.document.write('<style>');
a.document.write("@media only screen {html {visibility: hidden}}@charset 'UTF-8';.row:after{clear:both}.transparent{background-color:transparent!important}body{margin:0}main{display:block}html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;box-sizing:border-box}*,:after,:before{box-sizing:inherit}.row .ql-editor .ql-color-yellow{color:#ff0}.ql-editor .ql-color-green{color:#008a00}.ql-editor .ql-color-blue{color:#06c}.ql-editor .ql-color-purple{color:#93f}.ql-editor .ql-font-serif{font-family:Georgia,Times New Roman,serif}.ql-editor .ql;
a.document.write('</style>');
a.document.write('</head>');
a.document.write('<body onafterprint="self.close()">');
a.document.write('<div style="width:100%;height:100%;page-break-inside:avoid">');
a.document.write(divContents);
a.document.write('</div>');
a.document.write('</body></html>');
a.document.close();
a.print();
"$
page.ws.Eval(Script, Null)
page.ws.Flush
End Sub
NOTE: the <style> ... </style> section in the code above is
NOT complete! The complete method will be supplied in a project package later....
The style section is essentially the Quill.CSS file. It is required for the browser (Chrome in my case) to render a proper document with a.print().
To use this we call: PrintEditor("agend_out-parent").
The parameter is the parent <div> that contains the content to be printed....
In a new tab, the following is produced:
With the Destination combo, we can direct pages to a selected printer -
OR - save the content as a
PDF file!
Once printed (or saved) the tab auto closes and returns to your calling app (tab).
What Next?
All that has been presented above is from a certain page of my huge app.
Now, I intend to create an email page that uses CompQuillEditor to format email content to be sent.
This new project will expose
all the nuts and bolts I have discovered to use this custom component correctly.
The complete project source shall be shared here.
It is going to take some time to put this together, but I think the wait shall be worth it.
Thanks