@ -1,57 +1,82 @@
< template >
< div >
< h5 class = "uploader-label" >
{ { formInfo . preText } }
{ { formDef . preText } }
< a href = "javascript:void(0)" : id = "'Tooltip-' + uniqueId" >
{ { formInfo . name } } < i class = "fa fa-question-circle" > < / i >
{ { formDef . name } } < i class = "fa fa-question-circle" > < / i >
< / a >
< strong v-if ="party === 1" > - For You < / strong >
< strong v-if ="party === 2" > - For Your Spouse < / strong >
< / h5 >
< tooltip :text ="formInfo .help" : target = "'#Tooltip-' + uniqueId" > < / tooltip >
< tooltip :text ="formDef .help" : target = "'#Tooltip-' + uniqueId" > < / tooltip >
< label :for ="inputId" class = "sr-only" >
{ { formInfo . preText } } { { formInfo . name } }
{ { formDef . preText } } { { formDef . name } }
< span v-if ="party === 1" > - For You < / span >
< span v-if ="party === 2" > - For Your Spouse < / span >
< / label >
< div @dragover ="dragging On" @dragenter ="dragging On" @dragleave ="dragging Off" @dragend ="dragging Off" @drop ="draggin gOff" >
< div @dragover ="dragOn" @dragenter ="dragOn" @dragleave ="dragOff" @dragend ="dragOff" @drop ="dragOff" >
< file -upload
ref = "upload"
v - model = "files"
: multiple = "true"
: maximum = "maxFiles"
: size = "maxMegabytes * 1024 * 1024"
: drop = "true"
: drop - directory = "false"
: post - action = "postAction"
: input - id = "inputId"
name = "file"
: class = "['drop-zone', dragging ? 'dragging' : '']"
: data = "inputIdentifier s"
: data = "inputKey s"
@ input - file = "inputFile"
@ input - filter = "inputFilter" >
< div v-if ="files.length === 0" class="placeholder" >
< i class = "fa fa-plus-circle" > < / i > < br >
< em > Drag and Drop the PDF document or JPG pages here , < br > or click here to Browse for files . < / em >
< / div >
< div v -else class = "cards" >
< div v-for ="(file, index) in files" v-bind:key="index" class="card" >
< item -tile
: file = "file"
: index = "index"
: file - count = "files.length"
@ remove = "remove(file)"
@ moveup = "moveUp(index)"
@ movedown = "moveDown(index)"
@ rotateleft = "rotateLeft(index)"
@ rotateright = "rotateRight(index)" / >
< template v-else >
< div class = "text-danger error-top" v-if ="fileErrors === 1" >
< strong > One file has failed to upload to the server . Please remove the file marked 'Upload Error' and try uploading it again . < / strong >
< / div >
< div class = "card upload-button" >
< div class = "upload-button-wrapper" >
< i class = "fa fa-plus-circle" > < / i >
< div class = "text-danger error-top" v-if ="fileErrors > 1" >
< strong > Some files have failed to upload to the server . Please remove the files marked 'Upload Error' and try uploading them again . < / strong >
< / div >
< div class = "text-danger error-top" v-if ="tooBig" >
< strong > The total of all uploaded files for this form cannot exceed { { maxMegabytes } } MB .
Please reduce the size of your files so the total is below this limit . < / strong >
< / div >
< div class = "cards" >
< div v-for ="(file, index) in files" v-bind:key="index" class="card" >
< item -tile
: file = "file"
: index = "index"
: file - count = "files.length"
@ remove = "remove(file)"
@ moveup = "moveUp(index)"
@ movedown = "moveDown(index)"
@ rotateleft = "rotateLeft(index)"
@ rotateright = "rotateRight(index)" / >
< / div >
< div class = "card upload-button" v-if ="!tooBig" >
< div class = "upload-button-wrapper" >
< i class = "fa fa-plus-circle" > < / i >
< / div >
< / div >
< / div >
< div class = "text-danger pull-right error-bottom" v-if ="tooBig" >
< em >
< strong >
( Total { { Math . round ( totalSize / 1024 / 1024 * 100 ) / 100 } }
MB of { { maxMegabytes } } MB )
< / strong >
< / em >
< / div >
< / div >
< / template >
< / f i l e - u p l o a d >
< / div >
< div class = "pull-right" v-if ="!tooBig" >
< em > ( Maximum { { maxMegabytes } } MB ) < / em >
< / div >
< modal ref = "warningModal" v-model ="showWarning" >
{ { warningText } }
< / modal >
@ -62,7 +87,7 @@
import VueUploadComponent from 'vue-upload-component'
import { Tooltip , Modal } from 'uiv' ;
import ItemTile from './ItemTile'
import Forms from "../../utils/forms" ;
import FormDefinition s from "../../utils/forms" ;
import rotateFix from '../../utils/rotation' ;
export default {
@ -72,6 +97,8 @@ export default {
} ,
data : function ( ) {
return {
maxFiles : 30 ,
maxMegabytes : 10 ,
files : [ ] ,
dragging : false ,
showWarning : false ,
@ -86,26 +113,47 @@ export default {
Modal
} ,
computed : {
uniqueId ( ) {
if ( this . party === 0 ) {
return this . docType ;
}
return this . docType + this . party ;
} ,
inputId ( ) {
return "Uploader-" + this . uniqueId ;
} ,
formInfo ( ) {
return Forms [ this . docType ] ;
inputKeys ( ) {
return {
doc_type : this . docType ,
party_code : this . party
} ;
} ,
formDef ( ) {
return FormDefinitions [ this . docType ] ;
} ,
postAction ( ) {
return this . $parent . proxyRootPath + "poc/storage"
} ,
inputIdentifiers ( ) {
return {
doc_type : this . docType ,
party_code : this . party
} ;
uniqueId ( ) {
if ( this . party === 0 ) {
return this . docType ;
}
return this . docType + this . party ;
} ,
totalSize ( ) {
let size = 0 ;
this . files . forEach ( ( file ) => {
if ( ! file . error ) {
size += file . size ;
}
} ) ;
return size ;
} ,
fileErrors ( ) {
let count = 0 ;
this . files . forEach ( ( file ) => {
if ( file . error ) {
count ++ ;
}
} ) ;
return count ;
} ,
tooBig ( ) {
return this . totalSize > this . maxMegabytes * 1024 * 1024 ;
}
} ,
methods : {
@ -122,8 +170,7 @@ export default {
/ / G e t t h e r e s p o n s e s t a t u s c o d e ( w e c a n u s e t h i s f o r e r r o r h a n d l i n g )
if ( newFile . xhr . status !== 200 ) {
/ / t o d o : h a n d l e r e r r o r s
this . warningText = 'Error: ' + newFile . xhr . statusText ;
this . showWarning = true ;
this . showError ( 'Error: ' + newFile . xhr . statusText ) ;
console . log ( 'status' , newFile . xhr . status )
}
}
@ -134,29 +181,44 @@ export default {
if ( newFile && ! oldFile ) {
/ / F i l t e r n o n - i m a g e f i l e
if ( ! /\.(jpeg|jpg|gif|png|pdf)$/i . test ( newFile . name ) ) {
this . warningText = 'Unsupported file type. Allowed extensions are jpeg, jpg, gif,png and pdf.' ;
this . showWarning = true ;
this . showError ( 'Unsupported file type. Allowed extensions are jpeg, jpg, gif,png and pdf.' ) ;
return prevent ( )
}
this . files . forEach ( ( file ) => {
/ / p r e v e n t d u p l i c a t e s ( b a s e d o n f i l e n a m e a n d l e n g t h )
if ( file . name === newFile . name && file . length === newFile . length ) {
this . warningText = 'Duplicate file: ' + newFile . name ;
this . showWarning = true ;
return prevent ( ) ;
this . showError ( 'Duplicate file: ' + newFile . name ) ;
return prevent ( ) ;
}
} ) ;
}
if ( newFile ) {
/ / m a k e s u r e t h e u s e r i s n ' t u p l o a d i n g m o r e M B o f f i l e s t h a n a l l o w e d
if ( this . totalSize > this . maxMegabytes * 1024 * 1024 ) {
this . showError ( 'The total of all uploaded files for this form cannot exceed ' + this . maxMegabytes + ' MB. Please reduce the size of your files so the total is below this limit.' ) ;
/ / o n l y a l l o w o n e f i l e o v e r t h e l i m i t ( s o w e c a n s h o w t h e r e d m e s s a g i n g o n t h e s c r e e n )
let previousTotalSize = 0 ;
this . files . forEach ( ( file ) => {
if ( ( file . name !== newFile . name || file . size !== newFile . size ) && ! file . error ) {
previousTotalSize += file . size ;
}
} ) ;
/ / i f t h e u s e r i s m o r e t h a n o n e f i l e o v e r t h e l i m i t , t h e n b l o c k t h e u p l o a d
if ( previousTotalSize > this . maxMegabytes * 1024 * 1024 ) {
this . $refs . upload . remove ( newFile ) ;
return prevent ( ) ;
}
}
/ / i f i t ' s a P D F , m a k e s u r e i t ' s t h e o n l y i t e m b e i n g u p l o a d e d
if ( newFile . type === 'application/pdf' ) {
if ( this . files . length > 0 ) {
if ( this . files [ 0 ] . name != newFile . name || this . files [ 0 ] . length != newFile . length ) {
this . warningText = 'Only one PDF is allowed per form, and PDF documents cannot be combined with images.' ;
this . showWarning = true ;
this . showError ( 'Only one PDF is allowed per form, and PDF documents cannot be combined with images.' ) ;
this . $refs . upload . remove ( newFile ) ;
return prevent ( ) ;
}
@ -166,13 +228,12 @@ export default {
/ / i f i t ' s n o t a P D F , m a k e s u r e t h e r e a r e n o P D F s a l r e a d y u p l a o d e d
this . files . forEach ( ( file ) => {
if ( file . type === 'application/pdf' ) {
this . warningText = 'PDF documents cannot be combined with images.' ;
this . showWarning = true ;
this . showError ( 'PDF documents cannot be combined with images.' ) ;
this . $refs . upload . remove ( newFile ) ;
return prevent ( ) ;
}
} ) ;
}
}
/ / A d d e x t r a d a t a t o t o t h e f i l e o b j e c t
newFile . objectURL = ''
@ -213,12 +274,16 @@ export default {
this . files [ index ] . rotation += 90 ;
this . isDirty = true ;
} ,
dragging On ( ) {
dragOn ( ) {
this . dragging = true ;
} ,
dragging Off ( ) {
dragOff ( ) {
this . dragging = false ;
} ,
showError ( message ) {
this . warningText = message ;
this . showWarning = true ;
} ,
saveMetaData ( ) {
let allFiles = [ ] ;
this . files . forEach ( ( file ) => {
@ -259,10 +324,6 @@ export default {
border - radius : 6 px ;
padding : 18 px ;
& : hover . fa - plus - circle {
opacity : 0.85 ;
}
& . dragging {
background - color : # F2E3F2 ;
}
@ -295,6 +356,14 @@ export default {
. placeholder {
text - align : center ;
}
. error - top {
padding - bottom : 16 px ;
}
. error - bottom {
margin - bottom : - 10 px ;
}
}
h5 . uploader - label {