Cx.Document
Properties
Properties | Type | Def | Definition |
---|---|---|---|
id |
String | null |
Id of the document in the Server |
docType |
String | 'Doc' |
Server side document type |
xType |
String | null |
Document type |
undoLimit |
Integer | 10 |
Maximun number of history points kept |
name |
String | null |
Name stored in the Server |
notes |
String | null |
Notes stored in the Server |
owned |
Boolean | true |
The current user owns this document |
archived |
Boolean | false |
The document is archived in the Server |
tags |
Tag Array | [] |
Core tags |
metadata |
Metadata | None | Extra app data |
Events
Events | Definition |
---|---|
'saved' |
Fired after the document is saved in the Server |
'lock' |
Fired when a transaction starts |
'unlock' |
Document is able to process next transaction |
'commitstarted' |
Commit started, hook to assure things like showThrough color |
'commit' |
Transaction finished succesfully |
'revert' |
Transaction failed, state reverted to previous history point |
'undo' |
Fired after an undo operation |
'redo' |
Fired after a redo operation |
'pageschanged' |
Pages array changed |
'activepagechanged' |
Active Page changed |
'layerschanged' |
Layers array changed |
'activelayerchanged' |
Active layer changed |
Creation
var doc = Cx.Document();
Pages
doc.pages(i,a);doc.activePage();doc.activePageIndex();doc.releasePages(pages);
Layers
doc.layers(i,a);doc.activeLayer();doc.activeLayerIndex();doc.releaseLayers(layers);
Figures
doc.figures(i,a);doc.allFigures();
The document offers helper functions to directly modify the figures in the active layer. The doc.group(figures)
function will remove the figures from the document, and add them grouped.
doc.backOne(figures);doc.toBack(figures);doc.forwardOne(figures);doc.toFront(figures);doc.autoCreateMultiPartText$(figures);doc.breakMultiPartText(text); doc.group(figures);doc.ungroup(figures);doc.extractPowerClipContents(figure);doc.addPowerClipContents(figure,content); doc.reshape$(figures,action);
Transactions
doc.lock();doc.unlock();doc.commit$();doc.revert$();doc.update$();
Utilities
doc.background();doc.clone();doc.toXmlString();
Loading and Saving
Cx.Document.load$(id) .then(function(doc){ ...Cx.Pages.load$(id) .then(function(pages){ ...Cx.Layers.load$(id) .then(function(layers){ ...Cx.Document.fromXmlString(string);Cx.Document.fromXml(node);
doc.saveCopy$();doc.save$();doc.isSaved();
History
Each document keeps track of its history up to undoLimit
states. History is used both as a way to let users undo and redo their work, and to allow transactions to be properly reverted.
if( doc.canUndo() ) doc.undo(); if( doc.canRedo() ) doc.redo();
When implementing undo and redo actions for your app, use the canvas.undo()
machinery that uses tools history instead of plain document history. Read more about Canvas and tools history in the Canvas reference.
Templating
Adds a clipart centered in the template and with proper scaling (half the template size)
doc.addClipart$(clipart) .then(...
Replaces a clipart taking care of keeping the user transform, placing and size.
doc.replaceClipart$(old, clipart) .then(...