aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-07-31 00:05:39 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-07-31 00:05:39 -0400
commita268800c9d743e94c9395dc1d34809bb55c3ceab (patch)
treeaa2369c621bf0bd25267be9a46d34bf4cef33678
parent7ebbcc8e09933150d4b5b5daf19cb781c99a8f8f (diff)
added alt-drag-drop for applying template to items in a collection
-rw-r--r--src/client/views/collections/CollectionSubView.tsx15
-rw-r--r--src/client/views/nodes/ImageBox.tsx12
-rw-r--r--src/new_fields/Doc.ts13
3 files changed, 24 insertions, 16 deletions
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 7386eaba6..077f3f941 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -1,13 +1,15 @@
import { action, computed } from "mobx";
import * as rp from 'request-promise';
import CursorField from "../../../new_fields/CursorField";
-import { Doc, DocListCast, Opt } from "../../../new_fields/Doc";
+import { Doc, DocListCast } from "../../../new_fields/Doc";
import { Id } from "../../../new_fields/FieldSymbols";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
+import { ScriptField } from "../../../new_fields/ScriptField";
import { BoolCast, Cast } from "../../../new_fields/Types";
import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
import { RouteStore } from "../../../server/RouteStore";
+import { Utils } from "../../../Utils";
import { DocServer } from "../../DocServer";
import { Docs, DocumentOptions, DocumentType } from "../../documents/Documents";
import { DragManager } from "../../util/DragManager";
@@ -19,10 +21,6 @@ import { CollectionPDFView } from "./CollectionPDFView";
import { CollectionVideoView } from "./CollectionVideoView";
import { CollectionView } from "./CollectionView";
import React = require("react");
-import { MainView } from "../MainView";
-import { Utils } from "../../../Utils";
-import { ScriptField } from "../../../new_fields/ScriptField";
-import { CompileScript } from "../../util/Scripting";
export interface CollectionViewProps extends FieldViewProps {
addDocument: (document: Doc, allowDuplicates?: boolean) => boolean;
@@ -115,6 +113,13 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
@action
protected drop(e: Event, de: DragManager.DropEvent): boolean {
if (de.data instanceof DragManager.DocumentDragData) {
+ if (de.mods === "AltKey" && de.data.draggedDocuments.length) {
+ this.childDocs.map(doc =>
+ Doc.ApplyTemplateTo(de.data.draggedDocuments[0], doc, undefined)
+ );
+ e.stopPropagation();
+ return true;
+ }
let added = false;
if (de.data.dropAction || de.data.userDropAction) {
added = de.data.droppedDocuments.reduce((added: boolean, d) => this.props.addDocument(d) || added, false);
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index dbe545048..b60ef41fd 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -93,17 +93,7 @@ export class ImageBox extends DocComponent<FieldViewProps, ImageDocument>(ImageD
if (de.data instanceof DragManager.DocumentDragData) {
de.data.droppedDocuments.forEach(action((drop: Doc) => {
if (de.mods === "CtrlKey") {
- let temp = Doc.MakeDelegate(drop);
- this.props.Document.nativeWidth = Doc.GetProto(this.props.Document).nativeWidth = undefined;
- this.props.Document.nativeHeight = Doc.GetProto(this.props.Document).nativeHeight = undefined;
- this.props.Document.width = drop.width;
- this.props.Document.height = drop.height;
- Doc.GetProto(this.props.Document).type = DocumentType.TEMPLATE;
- if (this.props.DataDoc && this.props.DataDoc.layout === this.props.Document) {
- this.props.DataDoc.layout = temp;
- } else {
- this.props.Document.layout = temp;
- }
+ Doc.ApplyTemplateTo(drop, this.props.Document, this.props.DataDoc);
e.stopPropagation();
} else if (de.mods === "AltKey" && /*this.dataDoc !== this.props.Document &&*/ drop.data instanceof ImageField) {
Doc.GetProto(this.dataDoc)[this.props.fieldKey] = new ImageField(drop.data.url);
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 59314783b..dab0f9070 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -462,6 +462,19 @@ export namespace Doc {
otherdoc.type = DocumentType.TEMPLATE;
return otherdoc;
}
+ export function ApplyTemplateTo(templateDoc: Doc, target: Doc, targetData?: Doc) {
+ let temp = Doc.MakeDelegate(templateDoc);
+ target.nativeWidth = Doc.GetProto(target).nativeWidth = undefined;
+ target.nativeHeight = Doc.GetProto(target).nativeHeight = undefined;
+ target.width = templateDoc.width;
+ target.height = templateDoc.height;
+ Doc.GetProto(target).type = DocumentType.TEMPLATE;
+ if (targetData && targetData.layout === target) {
+ targetData.layout = temp;
+ } else {
+ target.layout = temp;
+ }
+ }
export function MakeTemplate(fieldTemplate: Doc, metaKey: string, templateDataDoc: Doc) {
// move data doc fields to layout doc as needed (nativeWidth/nativeHeight, data, ??)