diff options
author | ab <abdullah_ahmed@brown.edu> | 2019-07-01 15:40:55 -0400 |
---|---|---|
committer | ab <abdullah_ahmed@brown.edu> | 2019-07-01 15:40:55 -0400 |
commit | 0fc7edd5f9bd1234f8de6e5b1c7b8f23668d784c (patch) | |
tree | 2ddff97c032657fb86de37c3be2cf2d201980088 /src/new_fields/Doc.ts | |
parent | 4f8b7cecea3ceed6861c38bde9ce03c9c46e2d09 (diff) | |
parent | 6bd79baf2d9301304194d87667bb5c66c17e5298 (diff) |
Merge branch 'monikasearch2' of https://github.com/browngraphicslab/Dash-Web into text_box_ab
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index b0184dd4e..734a90731 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -277,7 +277,29 @@ export namespace Doc { if (!GetT(doc, "isPrototype", "boolean", true)) { return Doc.MakeCopy(doc); } - return new Doc; + return Doc.MakeDelegate(doc); // bcz? + } + + export function expandTemplateLayout(templateLayoutDoc: Doc, dataDoc?: Doc) { + let resolvedDataDoc = (templateLayoutDoc !== dataDoc) ? dataDoc : undefined; + if (!dataDoc || !(templateLayoutDoc && !(Cast(templateLayoutDoc.layout, Doc) instanceof Doc) && resolvedDataDoc && resolvedDataDoc !== templateLayoutDoc)) { + return templateLayoutDoc; + } + // if we have a data doc that doesn't match the layout, then we're rendering a template. + // ... which means we change the layout to be an expanded view of the template layout. + // This allows the view override the template's properties and be referenceable as its own document. + + let expandedTemplateLayout = templateLayoutDoc["_expanded_" + dataDoc[Id]]; + if (expandedTemplateLayout instanceof Doc) { + return expandedTemplateLayout; + } + if (expandedTemplateLayout === undefined) { + setTimeout(() => { + templateLayoutDoc["_expanded_" + dataDoc[Id]] = Doc.MakeDelegate(templateLayoutDoc); + (templateLayoutDoc["_expanded_" + dataDoc[Id]] as Doc).title = templateLayoutDoc.title + " applied to " + dataDoc.title; + }, 0); + } + return templateLayoutDoc; } export function MakeCopy(doc: Doc, copyProto: boolean = false): Doc { |