diff options
| author | bob <bcz@cs.brown.edu> | 2019-06-25 16:42:02 -0400 |
|---|---|---|
| committer | bob <bcz@cs.brown.edu> | 2019-06-25 16:42:02 -0400 |
| commit | 8af69f89c93b7f4287c1fba237ea42aa741c4137 (patch) | |
| tree | 662f5b46f5351642ee2ccfd290ecfcd3bf86693f /src/client/views/collections/CollectionBaseView.tsx | |
| parent | f65af3927995f4b024d670c5bd888103166a19a1 (diff) | |
testing stuff for document field extensions.
Diffstat (limited to 'src/client/views/collections/CollectionBaseView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionBaseView.tsx | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/client/views/collections/CollectionBaseView.tsx b/src/client/views/collections/CollectionBaseView.tsx index 50d1a5071..bb5cad6f3 100644 --- a/src/client/views/collections/CollectionBaseView.tsx +++ b/src/client/views/collections/CollectionBaseView.tsx @@ -74,6 +74,13 @@ export class CollectionBaseView extends React.Component<CollectionViewProps> { this.props.whenActiveChanged(isActive); } + @computed get extDoc() { + return this.dataDoc && this.props.fieldExt && this.dataDoc[this.props.fieldKey + "_ext"] instanceof Doc ? this.dataDoc[this.props.fieldKey + "_ext"] as Doc : this.dataDoc; + } + @computed get extField() { + return this.dataDoc && this.props.fieldExt && this.dataDoc[this.props.fieldKey + "_ext"] instanceof Doc ? this.props.fieldExt : this.props.fieldKey; + } + @action.bound addDocument(doc: Doc, allowDuplicates: boolean = false): boolean { var curPage = NumCast(this.props.Document.curPage, -1); @@ -82,14 +89,13 @@ export class CollectionBaseView extends React.Component<CollectionViewProps> { Doc.GetProto(doc).annotationOn = this.props.Document; } allowDuplicates = true; - //TODO This won't create the field if it doesn't already exist - const value = Cast(this.dataDoc[this.props.fieldKey], listSpec(Doc)); + const value = Cast(this.extDoc[this.extField], listSpec(Doc)); if (value !== undefined) { if (allowDuplicates || !value.some(v => v instanceof Doc && v[Id] === doc[Id])) { value.push(doc); } } else { - Doc.SetOnPrototype(this.dataDoc, this.props.fieldKey, new List([doc])); + Doc.SetOnPrototype(this.extDoc, this.extField, new List([doc])); } return true; } |
