aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DocumentView.tsx
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-03-27 23:30:03 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-03-27 23:30:03 -0400
commitf80aee53be8582956a1f39519938700c3e90cb53 (patch)
tree8de6544a3970565fd8625fd4bf30292b6d88fe5f /src/client/views/nodes/DocumentView.tsx
parent692381503f2af93dba2a4f30495a17b7b4deed36 (diff)
fixed up embedded document view layout references in text boxes to 1) create the template if it doesn't exist and 2) to allow parameters to be passed to templates
Diffstat (limited to 'src/client/views/nodes/DocumentView.tsx')
-rw-r--r--src/client/views/nodes/DocumentView.tsx61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 9a7568518..544c0a961 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -513,9 +513,29 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
undoBatch(() => Doc.setNativeView(doc))();
}
- static makeCustomViewClicked = (doc: Doc, dataDoc: Opt<Doc>, creator: (documents: Array<Doc>, options: DocumentOptions, id?: string) => Doc, name: string = "custom", docLayoutTemplate?: Doc) => {
+ static makeCustomViewClicked = (doc: Doc, dataDoc: Opt<Doc>, creator: (documents: Array<Doc>, options: DocumentOptions, id?: string) => Doc, templateSignature: string = "custom", docLayoutTemplate?: Doc) => {
+ const userDoc = Doc.UserDoc();
+ const imgView = Cast(userDoc.iconView, Doc, null);
+ const iconImgView = Cast(userDoc.iconImageView, Doc, null);
+ const iconColView = Cast(userDoc.iconColView, Doc, null);
+ const iconViews = [imgView, iconImgView, iconColView];
+ const templateButtons = DocListCast(Cast(userDoc.templateButtons, Doc, null)?.data);
+ const noteTypes = DocListCast(Cast(userDoc.noteTypes, Doc, null)?.data);
+ const allTemplates = iconViews.concat(templateButtons).concat(noteTypes);
+ const templateName = templateSignature.replace(/\(.*\)/, "");
+ !docLayoutTemplate && allTemplates.map(btnDoc => (btnDoc.dragFactory as Doc) || btnDoc).filter(doc => doc.isTemplateDoc).forEach(tempDoc => {
+ if (StrCast(tempDoc.title) === doc.type + "_" + templateName) {
+ docLayoutTemplate = tempDoc;
+ }
+ });
+ !docLayoutTemplate && allTemplates.map(btnDoc => (btnDoc.dragFactory as Doc) || btnDoc).filter(doc => doc.isTemplateDoc).forEach(tempDoc => {
+ if (StrCast(tempDoc.title) === templateName) {
+ docLayoutTemplate = tempDoc;
+ }
+ });
+
const batch = UndoManager.StartBatch("CustomViewClicked");
- const customName = "layout_" + name;
+ const customName = "layout_" + templateSignature;
if (doc[customName] === undefined) {
const _width = NumCast(doc._width);
const _height = NumCast(doc._height);
@@ -626,39 +646,12 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
@undoBatch
@action
- setCustomView =
- (custom: boolean, layout: string): void => {
- // if (this.props.ContainingCollectionView?.props.DataDoc || this.props.ContainingCollectionView?.props.Document.isTemplateDoc) {
- // Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.ContainingCollectionView.props.Document);
- // } else
- if (custom) {
- DocumentView.makeNativeViewClicked(this.props.Document);
- const userDoc = Doc.UserDoc();
-
- const imgView = Cast(userDoc.iconView, Doc, null);
- const iconImgView = Cast(userDoc.iconImageView, Doc, null);
- const iconColView = Cast(userDoc.iconColView, Doc, null);
- const iconViews = [imgView, iconImgView, iconColView];
- const templateButtons = DocListCast(Cast(userDoc.templateButtons, Doc, null)?.data);
- const noteTypes = DocListCast(Cast(userDoc.noteTypes, Doc, null)?.data);
- const allTemplates = iconViews.concat(templateButtons).concat(noteTypes);
- let foundLayout: Opt<Doc>;
- allTemplates.map(btnDoc => (btnDoc.dragFactory as Doc) || btnDoc).filter(doc => doc.isTemplateDoc).forEach(tempDoc => {
- if (StrCast(tempDoc.title) === this.props.Document.type + "_" + layout) {
- foundLayout = tempDoc;
- }
- });
- !foundLayout && allTemplates.map(btnDoc => (btnDoc.dragFactory as Doc) || btnDoc).filter(doc => doc.isTemplateDoc).forEach(tempDoc => {
- if (StrCast(tempDoc.title) === layout) {
- foundLayout = tempDoc;
- }
- });
- DocumentView.
- makeCustomViewClicked(this.props.Document, this.props.DataDoc, Docs.Create.StackingDocument, layout, foundLayout);
- } else {
- DocumentView.makeNativeViewClicked(this.props.Document);
- }
+ setCustomView = (custom: boolean, layout: string): void => {
+ DocumentView.makeNativeViewClicked(this.props.Document);
+ if (custom) {
+ DocumentView.makeCustomViewClicked(this.props.Document, this.props.DataDoc, Docs.Create.StackingDocument, layout, undefined);
}
+ }
@undoBatch
@action