diff --git a/app/javascript/components/builder.vue b/app/javascript/components/builder.vue index beb1f2b6..3f293838 100644 --- a/app/javascript/components/builder.vue +++ b/app/javascript/components/builder.vue @@ -35,7 +35,9 @@ :areas-index="fieldAreasIndex[document.uuid]" :document="document" :is-draw="!!drawField" + :is-drag="!!dragFieldType" @draw="onDraw" + @drop-field="onDropfield" />
FIelds
@@ -84,6 +89,7 @@ export default { data () { return { drawField: null, + dragFieldType: null, flow: { name: '', schema: [], @@ -134,6 +140,9 @@ export default { this.drawField = null }, + onDropfield (area) { + this.$refs.fields.addField(this.dragFieldType, area) + }, updateFromUpload ({ schema, documents }) { this.flow.schema.push(...schema) this.flow.documents.push(...documents) diff --git a/app/javascript/components/document.vue b/app/javascript/components/document.vue index e26a2af1..89611c17 100644 --- a/app/javascript/components/document.vue +++ b/app/javascript/components/document.vue @@ -5,8 +5,10 @@ :number="index" :areas="areasIndex[index]" :is-draw="isDraw" + :is-drag="isDrag" :class="{ 'cursor-crosshair': isDraw }" :image="image" + @drop-field="$emit('drop-field', {...$event, attachment_uuid: document.uuid })" @draw="$emit('draw', {...$event, attachment_uuid: document.uuid })" /> @@ -32,9 +34,14 @@ export default { type: Boolean, required: false, default: false + }, + isDrag: { + type: Boolean, + required: false, + default: false } }, - emits: ['draw'], + emits: ['draw', 'drop-field'], computed: { sortedPreviewImages () { return [...this.document.preview_images].sort((a, b) => parseInt(a.filename) - parseInt(b.filename)) diff --git a/app/javascript/components/field.vue b/app/javascript/components/field.vue index 694f9fa8..4f58e235 100644 --- a/app/javascript/components/field.vue +++ b/app/javascript/components/field.vue @@ -1,6 +1,11 @@ @@ -33,7 +59,7 @@ export default { required: true } }, - emits: ['set-draw'], + emits: ['set-draw', 'set-drag', 'drag-end'], computed: { fieldTypes () { return [ @@ -49,7 +75,10 @@ export default { } }, methods: { - addField (type) { + onDragstart (fieldType) { + this.$emit('set-drag', fieldType) + }, + addField (type, area = null) { const field = { name: type === 'signature' ? 'Signature' : '', uuid: v4(), @@ -61,6 +90,10 @@ export default { field.options = [''] } + if (area) { + field.areas = [area] + } + this.fields.push(field) } } diff --git a/app/javascript/components/page.vue b/app/javascript/components/page.vue index eb1f9105..36937e6f 100644 --- a/app/javascript/components/page.vue +++ b/app/javascript/components/page.vue @@ -28,12 +28,14 @@ />
@@ -62,12 +64,17 @@ export default { required: false, default: false }, + isDrag: { + type: Boolean, + required: false, + default: false + }, number: { type: Number, required: true } }, - emits: ['draw'], + emits: ['draw', 'drop-field'], data () { return { scale: 1, @@ -95,6 +102,15 @@ export default { onResize () { this.scale = this.$refs.image.clientWidth / this.image.metadata.width }, + onDrop (e) { + this.$emit('drop-field', { + x: e.layerX / this.scale, + y: e.layerY / this.scale, + w: 200, + h: 40, + page: this.number + }) + }, onPointerdown (e) { if (this.isDraw) { this.newArea = {