Conditions | 4 |
Paths | 170 |
Total Lines | 153 |
Code Lines | 105 |
Lines | 29 |
Ratio | 18.95 % |
Changes | 5 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
35 | initDropzone() { |
||
36 | if (typeof Dropzone != 'undefined') { |
||
37 | //Dropzone.autoDiscover = false; |
||
38 | |||
39 | // Cards version |
||
40 | if($('#dropzone-cards').length) { |
||
41 | let dropzoneCardsElement = $('#dropzone-cards'); |
||
42 | let dropzoneCardsActionUrl = dropzoneCardsElement.data('action-url'); |
||
43 | |||
44 | let dropzoneCardsFilePreview = dropzoneCardsElement.find('#dropzone-cards-template'); |
||
45 | dropzoneCardsFilePreview.removeAttr('id'); |
||
46 | |||
47 | let dropzoneCardsFilePreviewTemplate = dropzoneCardsFilePreview.parent().html(); |
||
48 | dropzoneCardsFilePreview.parent().remove(); |
||
49 | |||
50 | let dropzoneCards = $('#dropzone-cards-form').dropzone({ |
||
51 | url: dropzoneCardsActionUrl, |
||
52 | autoProcessQueue: true, |
||
53 | thumbnailWidth: null, |
||
54 | thumbnailHeight: null, |
||
55 | previewTemplate: dropzoneCardsFilePreviewTemplate |
||
56 | }); |
||
57 | |||
58 | View Code Duplication | dropzoneCards.on("addedfile", function (file) { |
|
|
|||
59 | console.log('titit'); |
||
60 | var fileId = 'media' + document.querySelectorAll('.media-list-item').length; |
||
61 | file.previewElement.getElementsByTagName('input')[0].setAttribute('id', fileId); |
||
62 | file.previewElement.getElementsByTagName('label')[0].setAttribute('for', fileId); |
||
63 | |||
64 | var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif']; |
||
65 | if (imagesFileTypes.indexOf(file.type) != -1) { |
||
66 | file.previewElement.querySelector('.media-item-file-details').style.display = 'none'; |
||
67 | } else if (file.type === 'application/pdf') { |
||
68 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
69 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>'; |
||
70 | } else if (file.type === 'application/doc' | 'application/docx') { |
||
71 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
72 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>'; |
||
73 | } else if (file.type === 'application/ppt' | 'application/pptx') { |
||
74 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
75 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>'; |
||
76 | } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') { |
||
77 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
78 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>'; |
||
79 | } else if (file.type === 'audio/mpeg') { |
||
80 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
81 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>'; |
||
82 | } else { |
||
83 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
84 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>'; |
||
85 | } |
||
86 | }); |
||
87 | |||
88 | dropzoneCards.on("success", function (file, resp) { |
||
89 | file.previewElement.querySelector(".media-list-item").classList.remove('uploading'); |
||
90 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
91 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
92 | }); |
||
93 | |||
94 | dropzoneCards.on("error", function (file) { |
||
95 | file.previewElement.querySelector(".media-list-item").classList.remove('uploading'); |
||
96 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
97 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
98 | }); |
||
99 | } |
||
100 | |||
101 | // Table version |
||
102 | if($('#dropzone-table').length) { |
||
103 | let dropzoneTableElement = $('#dropzone-table'); |
||
104 | let dropzoneTableActionUrl = dropzoneTableElement.data('action-url'); |
||
105 | |||
106 | let dropzoneTableFilePreview = dropzoneTableElement.find('#dropzone-table-template'); |
||
107 | dropzoneTableFilePreview.removeAttr('id'); |
||
108 | |||
109 | let dropzoneTableFilePreviewTemplate = dropzoneTableFilePreview.parent().html(); |
||
110 | dropzoneTableFilePreview.parent().remove(); |
||
111 | |||
112 | let dropzoneTable = $('#dropzone-table-form').dropzone({ |
||
113 | url: dropzoneTableActionUrl, |
||
114 | autoProcessQueue: false, |
||
115 | thumbnailWidth: null, |
||
116 | thumbnailHeight: null, |
||
117 | previewTemplate: dropzoneTableFilePreviewTemplate, // Define the container to display the previews |
||
118 | previewsContainer: ".media-list-table", |
||
119 | clickable: "#dropzone-add-file", // Define the element that should be used as click trigger to select files. |
||
120 | }); |
||
121 | |||
122 | dropzoneTable.on("addedfile", function (file) { |
||
123 | console.log('test'); |
||
124 | var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif']; |
||
125 | if (imagesFileTypes.indexOf(file.type) != -1) { |
||
126 | file.previewElement.querySelector('.media-item-file-details').style.display = 'none'; |
||
127 | } else if (file.type === 'application/pdf') { |
||
128 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
129 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>'; |
||
130 | } else if (file.type === 'application/doc' | 'application/docx') { |
||
131 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
132 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>'; |
||
133 | } else if (file.type === 'application/ppt' | 'application/pptx') { |
||
134 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
135 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>'; |
||
136 | } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') { |
||
137 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
138 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>'; |
||
139 | } else if (file.type === 'audio/mpeg') { |
||
140 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
141 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>'; |
||
142 | } else { |
||
143 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
144 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>'; |
||
145 | } |
||
146 | // Hookup the start button |
||
147 | file.previewElement.querySelector(".start").onclick = function() { dropzoneTable.enqueueFile(file); }; |
||
148 | }); |
||
149 | |||
150 | dropzoneTable.on("totaluploadprogress", function(progress) { |
||
151 | document.querySelector("#dropzone-table-total-progress .progress-bar").style.width = progress + "%"; |
||
152 | }); |
||
153 | |||
154 | dropzoneTable.on("sending", function(file) { |
||
155 | // Show the total progress bar when upload starts |
||
156 | document.querySelector("#dropzone-table-total-progress").style.opacity = "1"; |
||
157 | // And disable the start button |
||
158 | file.previewElement.querySelector(".start").setAttribute("disabled", "disabled"); |
||
159 | }); |
||
160 | |||
161 | dropzoneTable.on("success", function (file, resp) { |
||
162 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
163 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
164 | }); |
||
165 | |||
166 | dropzoneTable.on("error", function (file) { |
||
167 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
168 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
169 | }); |
||
170 | |||
171 | dropzoneTable.on("queuecomplete", function(progress) { |
||
172 | document.querySelector("#dropzone-table-total-progress").style.opacity = "0"; |
||
173 | }); |
||
174 | |||
175 | // Setup the buttons for all transfers |
||
176 | // The "add files" button doesn't need to be setup because the config |
||
177 | // `clickable` has already been specified. |
||
178 | document.querySelector("#dropzone-table-actions .start").onclick = function() { |
||
179 | dropzoneTable.enqueueFiles(dropzoneTable.getFilesWithStatus(Dropzone.ADDED)); |
||
180 | }; |
||
181 | |||
182 | document.querySelector("#dropzone-table-actions .cancel").onclick = function() { |
||
183 | dropzoneTable.removeAllFiles(true); |
||
184 | }; |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | |||
192 | } |