Skip to content

Commit 8e5af93

Browse files
authored
Merge pull request #115 from vrajroham/vue2
No more tragedy of dropzoneOptions and props
2 parents 89b9335 + e20e12f commit 8e5af93

File tree

6 files changed

+79
-62
lines changed

6 files changed

+79
-62
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
A Vue component for file uploads, powered by [Dropzone.js](http://www.dropzonejs.com/). [Check out the demo](https://rowanwins.github.io/vue-dropzone/dist/index.html).
44

5-
## Up for adoption
6-
This component is looking for a new owner, see [here for further details](https://github.com/rowanwins/vue-dropzone/issues/105) if you're interested in helping out.
7-
85
## Install
96
````
107
// For Vue.js 2.0+
@@ -55,6 +52,8 @@ You'll also need to load either the [Material Icon](https://material.io/icons/)
5552
## Props
5653
Many of these props are inherited from [dropzone configuration so see their doco](http://www.dropzonejs.com/#configuration-options) for further details.
5754

55+
> <b>Important</b> :<br> - If you are using following options as `props` (attributes) to component then use `dash-seperated` names of `props`. <br>E.g. `paramName` becomes `:param-name=""`, `showRemoveLink` becomes `:show-remove-link=""`. <br><br> - If you are passing props using `dropzoneOptions` object then, use prop names <b>same</b> as given in below table. <br>E.g. `:dropzone-options="customOptionsObject"`. `customOptionsObject` is defined in `data()` with following `props` names.
56+
5857
| Prop Name | Type | Description |
5958
|----------|------|--------------|
6059
| id | String | A string by which to identify the component, can be anything. **Required**|

dev/bundle.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue2-dropzone.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<dropzone ref="myVueDropzone" id="dropzone" url="https://httpbin.org/post"
88
v-on:vdropzone-success="showSuccess"
99
v-bind:dropzone-options="dropzoneOptions"
10-
v-bind:use-custom-dropzone-options="false">
10+
v-bind:max-number-of-files="2"
11+
v-bind:use-custom-dropzone-options="true">
1112
</dropzone>
1213
</div>
13-
<button v-on:click="process">process</button>
1414
</div>
1515
</template>
1616

@@ -24,7 +24,12 @@
2424
data () {
2525
return {
2626
ok: true,
27-
dropzoneOptions: {autoProcessQueue: false}
27+
dropzoneOptions: {
28+
autoProcessQueue: true,
29+
},
30+
language: {
31+
dictDefaultMessage : 'Hi'
32+
}
2833
}
2934
},
3035
methods: {

src/index.vue

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,46 @@
150150
},
151151
getQueuedFiles: function () {
152152
return this.dropzone.getQueuedFiles();
153-
}
153+
},
154+
getProp:function(attribute_prop,object_prop){
155+
if (!this.useCustomDropzoneOptions)
156+
return attribute_prop;
157+
158+
if (object_prop !== undefined && object_prop !== null && object_prop !== '')
159+
return object_prop;
160+
else
161+
return attribute_prop;
162+
},
163+
154164
},
155165
computed: {
156166
languageSettings () {
157167
let defaultValues = {
158-
dictDefaultMessage: '<br>Drop files here to upload',
159-
dictCancelUpload: 'Cancel upload',
168+
dictDefaultMessage : '<br>Drop files here to upload',
169+
dictCancelUpload : 'Cancel upload',
160170
dictCancelUploadConfirmation: 'Are you sure you want to cancel this upload?',
161-
dictFallbackMessage: 'Your browser does not support drag and drop file uploads.',
162-
dictFallbackText: 'Please use the fallback form below to upload your files like in the olden days.',
163-
dictFileTooBig: 'File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.',
164-
dictInvalidFileType: `You can't upload files of this type.`,
165-
dictMaxFilesExceeded: 'You can not upload any more files. (max: {{maxFiles}})',
166-
dictRemoveFile: 'Remove',
167-
dictRemoveFileConfirmation: null,
168-
dictResponseError: 'Server responded with {{statusCode}} code.'
169-
};
171+
dictFallbackMessage : 'Your browser does not support drag and drop file uploads.',
172+
dictFallbackText : 'Please use the fallback form below to upload your files like in the olden days.',
173+
dictFileTooBig : 'File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.',
174+
dictInvalidFileType : `You can't upload files of this type.`,
175+
dictMaxFilesExceeded : 'You can not upload any more files. (max: {{maxFiles}})',
176+
dictRemoveFile : 'Remove',
177+
dictRemoveFileConfirmation : null,
178+
dictResponseError : 'Server responded with {{statusCode}} code.'
179+
};
170180
171181
for (let attrname in this.language) {
172182
defaultValues[attrname] = this.language[attrname]
173183
}
174184
185+
if (this.useCustomDropzoneOptions) {
186+
if (this.dropzoneOptions.language) {
187+
for (let attrname in this.dropzoneOptions.language) {
188+
defaultValues[attrname] = this.dropzoneOptions.language[attrname]
189+
}
190+
}
191+
}
192+
175193
return defaultValues
176194
},
177195
cloudIcon: function () {
@@ -202,41 +220,36 @@
202220
}
203221
let Dropzone = require('dropzone');
204222
Dropzone.autoDiscover = false;
205-
let element = document.getElementById(this.id);
206-
207-
if (!this.useCustomDropzoneOptions) {
208-
this.dropzone = new Dropzone(element, {
209-
clickable: this.clickable,
210-
paramName: this.paramName,
211-
thumbnailWidth: this.thumbnailWidth,
212-
thumbnailHeight: this.thumbnailHeight,
213-
maxFiles: this.maxNumberOfFiles,
214-
maxFilesize: this.maxFileSizeInMB,
215-
addRemoveLinks: this.showRemoveLink,
216-
acceptedFiles: this.acceptedFileTypes,
217-
autoProcessQueue: this.autoProcessQueue,
218-
headers: this.headers,
219-
previewTemplate: this.previewTemplate(this),
220-
dictDefaultMessage: this.cloudIcon + this.languageSettings.dictDefaultMessage,
221-
dictCancelUpload: this.languageSettings.dictCancelUpload,
222-
dictCancelUploadConfirmation: this.languageSettings.dictCancelUploadConfirmation,
223-
dictFallbackMessage: this.languageSettings.dictFallbackMessage,
224-
dictFallbackText: this.languageSettings.dictFallbackText,
225-
dictFileTooBig: this.languageSettings.dictFileTooBig,
226-
dictInvalidFileType: this.languageSettings.dictInvalidFileType,
227-
dictMaxFilesExceeded: this.languageSettings.dictMaxFilesExceeded,
228-
dictRemoveFile: this.languageSettings.dictRemoveFile,
229-
dictRemoveFileConfirmation: this.languageSettings.dictRemoveFileConfirmation,
230-
dictResponseError: this.languageSettings.dictResponseError,
231-
resizeWidth:this.resizeWidth,
232-
resizeHeight:this.resizeHeight,
233-
resizeMimeType:this.resizeMimeType,
234-
resizeQuality:this.resizeQuality,
235-
resizeMethod:this.resizeMethod,
236-
})
237-
} else {
238-
this.dropzone = new Dropzone(element, this.dropzoneOptions);
239-
}
223+
let element = document.getElementById(this.id);
224+
this.dropzone = new Dropzone(element, {
225+
clickable : this.getProp(this.clickable,this.dropzoneOptions.clickable),
226+
paramName : this.getProp(this.paramName,this.dropzoneOptions.paramName),
227+
thumbnailWidth : this.getProp(this.thumbnailWidth,this.dropzoneOptions.thumbnailWidth),
228+
thumbnailHeight : this.getProp(this.thumbnailHeight,this.dropzoneOptions.thumbnailHeight),
229+
maxFiles : this.getProp(this.maxNumberOfFiles,this.dropzoneOptions.maxNumberOfFiles),
230+
maxFilesize : this.getProp(this.maxFileSizeInMB,this.dropzoneOptions.maxFileSizeInMB),
231+
addRemoveLinks : this.getProp(this.showRemoveLink,this.dropzoneOptions.showRemoveLink),
232+
acceptedFiles : this.getProp(this.acceptedFileTypes,this.dropzoneOptions.acceptedFileTypes),
233+
autoProcessQueue : this.getProp(this.autoProcessQueue,this.dropzoneOptions.autoProcessQueue),
234+
headers : this.getProp(this.headers,this.dropzoneOptions.headers),
235+
previewTemplate : this.previewTemplate(this),
236+
dictDefaultMessage : this.cloudIcon + this.languageSettings.dictDefaultMessage,
237+
dictCancelUpload : this.languageSettings.dictCancelUpload,
238+
dictCancelUploadConfirmation: this.languageSettings.dictCancelUploadConfirmation,
239+
dictFallbackMessage : this.languageSettings.dictFallbackMessage,
240+
dictFallbackText : this.languageSettings.dictFallbackText,
241+
dictFileTooBig : this.languageSettings.dictFileTooBig,
242+
dictInvalidFileType : this.languageSettings.dictInvalidFileType,
243+
dictMaxFilesExceeded : this.languageSettings.dictMaxFilesExceeded,
244+
dictRemoveFile : this.languageSettings.dictRemoveFile,
245+
dictRemoveFileConfirmation : this.languageSettings.dictRemoveFileConfirmation,
246+
dictResponseError : this.languageSettings.dictResponseError,
247+
resizeWidth : this.getProp(this.resizeWidth,this.dropzoneOptions.resizeWidth),
248+
resizeHeight : this.getProp(this.resizeHeight,this.dropzoneOptions.resizeHeight),
249+
resizeMimeType : this.getProp(this.resizeMimeType,this.dropzoneOptions.resizeMimeType),
250+
resizeQuality : this.getProp(this.resizeQuality,this.dropzoneOptions.resizeQuality),
251+
resizeMethod : this.getProp(this.resizeMethod,this.dropzoneOptions.resizeMethod)
252+
})
240253
241254
// Handle the dropzone events
242255
let vm = this;

0 commit comments

Comments
 (0)