diff options
author | bob <bcz@cs.brown.edu> | 2019-04-24 12:20:38 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-04-24 12:20:38 -0400 |
commit | 20becbb5ca40350ed85e01f73f29621ba7783bb9 (patch) | |
tree | e06383f2f35c88430174a74404e91ac8f1fd79f3 /src/fields/Document.ts | |
parent | d2a95b1aa144e8dd4e87338525922dae1f3d9e67 (diff) |
playing with linking
Diffstat (limited to 'src/fields/Document.ts')
-rw-r--r-- | src/fields/Document.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 7cf784f0e..7a7dbc3fe 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -371,6 +371,37 @@ export class Document extends Field { return alias; } + @action + CreateLink(dstTarg: Document) { + let batch = UndoManager.StartBatch("document view drop"); + let linkDoc: Document = new Document(); + linkDoc.SetText(KeyStore.Title, "New Link"); + linkDoc.SetText(KeyStore.LinkDescription, ""); + linkDoc.SetText(KeyStore.LinkTags, "Default"); + + let srcTarg = this; + linkDoc.Set(KeyStore.LinkedToDocs, dstTarg); + linkDoc.Set(KeyStore.LinkedFromDocs, srcTarg); + const prom1 = new Promise(resolve => dstTarg.GetOrCreateAsync( + KeyStore.LinkedFromDocs, + ListField, + field => { + (field as ListField<Document>).Data.push(linkDoc); + resolve(); + } + )); + const prom2 = new Promise(resolve => srcTarg.GetOrCreateAsync( + KeyStore.LinkedToDocs, + ListField, + field => { + (field as ListField<Document>).Data.push(linkDoc); + resolve(); + } + )); + Promise.all([prom1, prom2]).finally(() => batch.end()); + return linkDoc; + } + MakeDelegate(id?: string): Document { let delegate = new Document(id); |