From 3101134e8e579a6f9202d552c46d2a8bd70fda79 Mon Sep 17 00:00:00 2001
From: Monika Hedman <monika_hedman@brown.edu>
Date: Sat, 16 Mar 2019 18:48:21 -0400
Subject: cant get image stuff????

---
 src/client/views/collections/CollectionViewBase.tsx | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index eda62a4ca..dd05837d8 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -47,12 +47,19 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
     protected drop(e: Event, de: DragManager.DropEvent) {
         const docView: DocumentView = de.data["documentView"];
         const doc: Document = de.data["document"];
+
         if (docView && (!docView.props.ContainingCollectionView || docView.props.ContainingCollectionView !== this.props.CollectionView)) {
             if (docView.props.RemoveDocument) {
+
                 docView.props.RemoveDocument(docView.props.Document);
             }
+            console.log("2");
+            //console.log(docView.props.Document.GetData(KeyStore.Data, ""))
+            //let text = doc.GetText(KeyStore.DocumentText, "");
+            console.log("text")
             this.props.addDocument(docView.props.Document);
         } else if (doc) {
+            // console.log("3");
             this.props.removeDocument(doc);
             this.props.addDocument(doc);
         }
@@ -67,6 +74,7 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
 
         let html = e.dataTransfer.getData("text/html");
         let text = e.dataTransfer.getData("text/plain");
+
         if (html && html.indexOf("<img") != 0) {
             console.log("not good");
             let htmlDoc = Documents.HtmlDocument(html, { ...options, width: 300, height: 300 });
-- 
cgit v1.2.3-70-g09d2


From 88b175395307e31ce713ff66c3e2ae9c62e1a369 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Sat, 16 Mar 2019 21:48:13 -0400
Subject: Everything but the actual template works

---
 src/client/documents/Documents.ts                  | 15 ++++++++++++++-
 .../views/collections/CollectionFreeFormView.tsx   | 22 +---------------------
 .../views/collections/CollectionViewBase.tsx       |  8 ++++++--
 src/client/views/nodes/DocumentView.tsx            | 15 +++++++++++++++
 4 files changed, 36 insertions(+), 24 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 983253347..7b6409a62 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -209,10 +209,23 @@ export namespace Documents {
             + FormattedTextBox.LayoutString("CaptionKey") +
             `</div> 
         </div>` };
-    export function FixedCaption(fieldName: string = "Caption") {
+    function FixedCaption(fieldName: string = "Caption") {
         return `<div style="position:absolute; height:30px; bottom:0; width:100%">
             <div style="position:absolute; width:100%; height:100%; text-align:center;bottom:0;">`
             + FormattedTextBox.LayoutString(fieldName + "Key") +
             `</div> 
         </div>` };
+
+    function Caption() {
+        return (`
+<div>
+    <div style="margin:auto; height:85%; width:85%;">
+        {layout}
+    </div>
+    <div style="height:15%">
+        <FormattedTextBox doc={Document} DocumentViewForField={DocumentView} bindings={bindings} fieldKey={"CaptionKey"} isSelected={isSelected} select={select} selectOnLoad={SelectOnLoad} isTopMost={isTopMost}/>
+    </div>
+</div>       
+        `)
+    }
 }
\ No newline at end of file
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index 79ea77c77..0a4b57ffb 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -209,27 +209,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
     @action
     onDrop = (e: React.DragEvent): void => {
         var pt = this.getTransform().transformPoint(e.pageX, e.pageY);
-
-        let text = e.dataTransfer.getData("text/plain");
-        let start = text.startsWith("<div")
-        if (start) {
-            console.log(e.target);
-            console.log(this.props.Document.GetData(KeyStore.Layout, TextField, new String))
-            var children = this.props.Document.GetList<Document>(KeyStore.Data, []);
-            console.log(children);
-            if (children) {
-                children.forEach(f => {
-                    console.log(f.GetData(KeyStore.Layout, TextField, new String));
-                });
-            }
-            // let xx = this.props.Document.GetT(KeyStore.Thumbnail, ImageField)
-            // if (xx) {
-            //     console.log(xx.toString())
-            // }
-            this.props.Document.SetData(KeyStore.Layout, text, TextField);
-            e.stopPropagation();
-        }
-        else { super.onDrop(e, { x: pt[0], y: pt[1] }); }
+        super.onDrop(e, { x: pt[0], y: pt[1] });
     }
 
     onDragOver = (): void => {
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index dd05837d8..b0f42125a 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -68,13 +68,17 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
 
     @action
     protected onDrop(e: React.DragEvent, options: DocumentOptions): void {
-        e.stopPropagation()
-        e.preventDefault()
         let that = this;
 
         let html = e.dataTransfer.getData("text/html");
         let text = e.dataTransfer.getData("text/plain");
 
+        if (text && text.startsWith("<div")) {
+            return;
+        }
+        e.stopPropagation()
+        e.preventDefault()
+
         if (html && html.indexOf("<img") != 0) {
             console.log("not good");
             let htmlDoc = Documents.HtmlDocument(html, { ...options, width: 300, height: 300 });
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 4b50e40a3..2be5407fd 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -239,6 +239,20 @@ export class DocumentView extends React.Component<DocumentViewProps> {
         e.stopPropagation();
     }
 
+    onDrop = (e: React.DragEvent) => {
+        if (e.isDefaultPrevented()) {
+            return;
+        }
+        let text = e.dataTransfer.getData("text/plain");
+        if (text && text.startsWith("<div")) {
+            let oldLayout = this.props.Document.GetText(KeyStore.Layout, "");
+            let layout = text.replace("{layout}", oldLayout);
+            this.props.Document.SetText(KeyStore.Layout, layout);
+            e.stopPropagation();
+            e.preventDefault();
+        }
+    }
+
     @action
     onContextMenu = (e: React.MouseEvent): void => {
         e.stopPropagation();
@@ -315,6 +329,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
                     transformOrigin: "left top",
                     transform: `scale(${scaling} , ${scaling})`
                 }}
+                onDrop={this.onDrop}
                 onContextMenu={this.onContextMenu}
                 onPointerDown={this.onPointerDown} >
                 <DocumentContentsView {...this.getProps} />
-- 
cgit v1.2.3-70-g09d2


From a5a5e17adb4f5881c905baa13669c0ca4e884467 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Sat, 16 Mar 2019 21:52:33 -0400
Subject: Cleanup

---
 src/client/views/collections/CollectionFreeFormView.tsx | 7 ++-----
 src/client/views/collections/CollectionViewBase.tsx     | 6 ------
 2 files changed, 2 insertions(+), 11 deletions(-)

(limited to 'src/client/views/collections/CollectionViewBase.tsx')

diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index 0a4b57ffb..9dc1ae847 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -1,11 +1,10 @@
-import { action, computed, observable, trace } from "mobx";
+import { action, computed, observable } from "mobx";
 import { observer } from "mobx-react";
 import { Document } from "../../../fields/Document";
 import { FieldWaiting } from "../../../fields/Field";
 import { KeyStore } from "../../../fields/KeyStore";
 import { ListField } from "../../../fields/ListField";
 import { TextField } from "../../../fields/TextField";
-import { Documents } from "../../documents/Documents";
 import { DragManager } from "../../util/DragManager";
 import { Transform } from "../../util/Transform";
 import { undoBatch } from "../../util/UndoManager";
@@ -31,7 +30,6 @@ import { MarqueeView } from "./MarqueeView";
 import { PreviewCursor } from "./PreviewCursor";
 import React = require("react");
 const JsxParser = require('react-jsx-parser').default;//TODO Why does this need to be imported like this?
-import { ImageField } from '../../../fields/ImageField';
 
 @observer
 export class CollectionFreeFormView extends CollectionViewBase {
@@ -199,7 +197,6 @@ export class CollectionFreeFormView extends CollectionViewBase {
     @action
     private SetPan(panX: number, panY: number) {
         var x1 = this.getLocalTransform().inverse().Scale;
-        var x2 = this.getTransform().inverse().Scale;
         const newPanX = Math.min((1 - 1 / x1) * this.nativeWidth, Math.max(0, panX));
         const newPanY = Math.min((1 - 1 / x1) * this.nativeHeight, Math.max(0, panY));
         this.props.Document.SetNumber(KeyStore.PanX, this.isAnnotationOverlay ? newPanX : panX);
@@ -309,7 +306,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
 
     //when focus is lost, this will remove the preview cursor
     @action
-    onBlur = (e: React.FocusEvent<HTMLDivElement>): void => {
+    onBlur = (): void => {
         this.PreviewCursorVisible = false;
     }
 
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index b0f42125a..d9598aa72 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -50,16 +50,10 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
 
         if (docView && (!docView.props.ContainingCollectionView || docView.props.ContainingCollectionView !== this.props.CollectionView)) {
             if (docView.props.RemoveDocument) {
-
                 docView.props.RemoveDocument(docView.props.Document);
             }
-            console.log("2");
-            //console.log(docView.props.Document.GetData(KeyStore.Data, ""))
-            //let text = doc.GetText(KeyStore.DocumentText, "");
-            console.log("text")
             this.props.addDocument(docView.props.Document);
         } else if (doc) {
-            // console.log("3");
             this.props.removeDocument(doc);
             this.props.addDocument(doc);
         }
-- 
cgit v1.2.3-70-g09d2

