diff options
| author | laurawilsonri <laura_wilson@brown.edu> | 2019-04-08 19:10:03 -0400 |
|---|---|---|
| committer | laurawilsonri <laura_wilson@brown.edu> | 2019-04-08 19:10:03 -0400 |
| commit | 74411165f21b6c616fa98e0676c6f4568c2d4564 (patch) | |
| tree | 38079f721f8cdeba25e7bc0439aa5d6523927f1c /src/client/views/collections/CollectionSchemaView.tsx | |
| parent | 5d4414e8d2a17c75c808bce9343dba85fbb32440 (diff) | |
| parent | a72fcdd0ebc06a3c851007c6ed89ab13a9a0d835 (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into richTextEditor
Diffstat (limited to 'src/client/views/collections/CollectionSchemaView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionSchemaView.tsx | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx index 0ff6c3b40..b10aaba98 100644 --- a/src/client/views/collections/CollectionSchemaView.tsx +++ b/src/client/views/collections/CollectionSchemaView.tsx @@ -86,12 +86,10 @@ export class CollectionSchemaView extends CollectionViewBase { ) let reference = React.createRef<HTMLDivElement>(); let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc)); - let applyToDoc = (doc: Document, value: string) => { - let script = CompileScript(value, { this: doc }, true); - if (!script.compiled) { - return false; - } - let field = script(); + let applyToDoc = (doc: Document, run: (args?: { [name: string]: any }) => any) => { + const res = run({ this: doc }); + if (!res.success) return false; + const field = res.result; if (field instanceof Field) { doc.Set(props.fieldKey, field); return true; @@ -118,12 +116,22 @@ export class CollectionSchemaView extends CollectionViewBase { return field || ""; }} SetValue={(value: string) => { - return applyToDoc(props.doc, value); + let script = CompileScript(value, { addReturn: true, params: { this: "Document" } }); + if (!script.compiled) { + return false; + } + return applyToDoc(props.doc, script.run); }} OnFillDown={(value: string) => { + let script = CompileScript(value, { addReturn: true, params: { this: "Document" } }); + if (!script.compiled) { + return; + } + const run = script.run; + //TODO This should be able to be refactored to compile the script once this.props.Document.GetTAsync<ListField<Document>>(this.props.fieldKey, ListField).then((val) => { if (val) { - val.Data.forEach(doc => applyToDoc(doc, value)); + val.Data.forEach(doc => applyToDoc(doc, run)); } }) }}> |
