| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  | const DropZone = require("dropzone"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const template = `
 | 
					
						
							|  |  |  |     <div class="dropzone-container"> | 
					
						
							|  |  |  |         <div class="dz-message">{{placeholder}}</div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const props = ['placeholder', 'uploadUrl', 'uploadedTo']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO - Remove jQuery usage
 | 
					
						
							|  |  |  | function mounted() { | 
					
						
							|  |  |  |    let container = this.$el; | 
					
						
							|  |  |  |    let _this = this; | 
					
						
							| 
									
										
										
										
											2018-03-19 02:08:37 +08:00
										 |  |  |    this._dz = new DropZone(container, { | 
					
						
							| 
									
										
										
										
											2018-03-18 21:14:11 +08:00
										 |  |  | 	addRemoveLinks: true, | 
					
						
							|  |  |  | 	dictRemoveFile: trans('components.image_upload_remove'), | 
					
						
							| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  |         url: function() { | 
					
						
							|  |  |  |             return _this.uploadUrl; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         init: function () { | 
					
						
							|  |  |  |             let dz = this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             dz.on('sending', function (file, xhr, data) { | 
					
						
							|  |  |  |                 let token = window.document.querySelector('meta[name=token]').getAttribute('content'); | 
					
						
							|  |  |  |                 data.append('_token', token); | 
					
						
							|  |  |  |                 let uploadedTo = typeof _this.uploadedTo === 'undefined' ? 0 : _this.uploadedTo; | 
					
						
							|  |  |  |                 data.append('uploaded_to', uploadedTo); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             dz.on('success', function (file, data) { | 
					
						
							|  |  |  |                 _this.$emit('success', {file, data}); | 
					
						
							|  |  |  |                 $(file.previewElement).fadeOut(400, function () { | 
					
						
							|  |  |  |                     dz.removeFile(file); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             dz.on('error', function (file, errorMessage, xhr) { | 
					
						
							|  |  |  |                 _this.$emit('error', {file, errorMessage, xhr}); | 
					
						
							| 
									
										
										
										
											2018-03-24 22:54:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  |                 function setMessage(message) { | 
					
						
							|  |  |  |                     $(file.previewElement).find('[data-dz-errormessage]').text(message); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-18 21:14:11 +08:00
										 |  |  |                 if (xhr && xhr.status === 413) setMessage(trans('errors.server_upload_limit')); | 
					
						
							| 
									
										
										
										
											2018-03-19 04:39:01 +08:00
										 |  |  |                 else if (errorMessage.file) setMessage(errorMessage.file); | 
					
						
							| 
									
										
										
										
											2018-03-24 22:54:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |    }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function data() { | 
					
						
							| 
									
										
										
										
											2018-03-19 02:08:37 +08:00
										 |  |  |     return {}; | 
					
						
							| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 02:08:37 +08:00
										 |  |  | const methods = { | 
					
						
							|  |  |  |     onClose: function () { | 
					
						
							|  |  |  |         this._dz.removeAllFiles(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 04:33:00 +08:00
										 |  |  | module.exports = { | 
					
						
							|  |  |  |     template, | 
					
						
							|  |  |  |     props, | 
					
						
							|  |  |  |     mounted, | 
					
						
							|  |  |  |     data, | 
					
						
							| 
									
										
										
										
											2018-03-19 02:08:37 +08:00
										 |  |  |     methods | 
					
						
							| 
									
										
										
										
											2018-03-18 21:14:11 +08:00
										 |  |  | }; |