GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0e4d57...84f40e )
by Nur
03:48 queued 18s
created

Upload.js ➔ constructor   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
nop 0
1
/**
2
 * This file is part of the O2System Venus UI Framework package.
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @author         Steeve Andrian Salim
8
 * @copyright      Copyright (c) Steeve Andrian Salim
9
 */
10
// ------------------------------------------------------------------------
11
12
import * as $ from 'jquery';
13
import * as Dropzone from 'dropzone';
14
import 'dropify/dist/js/dropify';
15
16
/**
17
 * Class Upload
18
 *
19
 * @author          Teguh Rianto
20
 * @package         Components
21
 */
22
export default class Upload {
23
    constructor() {
24
        /**
25
         * Init dropzone
26
         */
27
        this.initDropzone();
28
29
        /**
30
         * Init dropify
31
         */
32
        this.initDropify();
33
    }
34
35
    initDropzone() {
36
        if (typeof Dropzone != 'undefined') {
37
            //Dropzone.autoDiscover = false;
38
39
            // Cards version
40
            const dropzoneCards = $('#dropzone-cards');
41
            if(dropzoneCards.length) {
42
43
                let dropzoneCardsActionUrl = dropzoneCards.data('action-url');
44
45
                let dropzoneCardsFilePreview = dropzoneCardsElement.find('#dropzone-cards-template');
0 ignored issues
show
Bug introduced by
The variable dropzoneCardsElement seems to be never declared. If this is a global, consider adding a /** global: dropzoneCardsElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
                dropzoneCardsFilePreview.removeAttr('id');
47
48
                let dropzoneCardsFilePreviewTemplate = dropzoneCardsFilePreview.parent().html();
49
                dropzoneCardsFilePreview.parent().remove();
50
51
                let dropzoneCardForms = $('#dropzone-cards-form').dropzone({
0 ignored issues
show
Unused Code introduced by
The variable dropzoneCardForms seems to be never used. Consider removing it.
Loading history...
52
                    url: dropzoneCardsActionUrl,
53
                    autoProcessQueue: true,
54
                    thumbnailWidth: null,
55
                    thumbnailHeight: null,
56
                    previewTemplate: dropzoneCardsFilePreviewTemplate
57
                });
58
59 View Code Duplication
                dropzoneCards.on("addedfile", function (file) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
60
                    console.log('titit');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
61
                    var fileId = 'media' + document.querySelectorAll('.media-list-item').length;
62
                    file.previewElement.getElementsByTagName('input')[0].setAttribute('id', fileId);
63
                    file.previewElement.getElementsByTagName('label')[0].setAttribute('for', fileId);
64
65
                    var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'];
66
                    if (imagesFileTypes.indexOf(file.type) != -1) {
67
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'none';
68
                    } else if (file.type === 'application/pdf') {
69
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
70
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>';
71
                    } else if (file.type === 'application/doc' | 'application/docx') {
0 ignored issues
show
introduced by
You have used a bitwise operator | in a condition. Did you maybe want to use the logical operator ||
Loading history...
72
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
73
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>';
74
                    } else if (file.type === 'application/ppt' | 'application/pptx') {
75
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
76
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>';
77
                    } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') {
78
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
79
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>';
80
                    } else if (file.type === 'audio/mpeg') {
81
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
82
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>';
83
                    } else {
84
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
85
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>';
86
                    }
87
                });
88
89
                dropzoneCards.on("success", function (file, resp) {
0 ignored issues
show
Unused Code introduced by
The parameter resp is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
90
                    file.previewElement.querySelector(".media-list-item").classList.remove('uploading');
91
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
92
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
93
                });
94
95
                dropzoneCards.on("error", function (file) {
96
                    file.previewElement.querySelector(".media-list-item").classList.remove('uploading');
97
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
98
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
99
                });
100
            }
101
102
            // Table version
103
            const dropzoneTable = $('#dropzone-table');
104
            if(dropzoneTable.length) {
105
106
                let dropzoneTableActionUrl = dropzoneTable.data('action-url');
0 ignored issues
show
Bug introduced by
The local (let) variable dropzoneTable is used before it is defined. This will cause a reference error.
Loading history...
107
108
                let dropzoneTableFilePreview = dropzoneTableElement.find('#dropzone-table-template');
0 ignored issues
show
Bug introduced by
The variable dropzoneTableElement seems to be never declared. If this is a global, consider adding a /** global: dropzoneTableElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
109
                dropzoneTableFilePreview.removeAttr('id');
110
111
                let dropzoneTableFilePreviewTemplate = dropzoneTableFilePreview.parent().html();
112
                dropzoneTableFilePreview.parent().remove();
113
114
                let dropzoneTable = $('#dropzone-table-form').dropzone({
115
                    url: dropzoneTableActionUrl,
116
                    autoProcessQueue: false,
117
                    thumbnailWidth: null,
118
                    thumbnailHeight: null,
119
                    previewTemplate: dropzoneTableFilePreviewTemplate, // Define the container to display the previews
120
                    previewsContainer: ".media-list-table",
121
                    clickable: "#dropzone-add-file", // Define the element that should be used as click trigger to select files.
122
                });
123
                
124
                dropzoneTable.on("addedfile", function (file) {
125
                    console.log('test');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
126
                    var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'];
127
                    if (imagesFileTypes.indexOf(file.type) != -1) {
128
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'none';
129
                    } else if (file.type === 'application/pdf') {
130
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
131
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>';
132
                    } else if (file.type === 'application/doc' | 'application/docx') {
0 ignored issues
show
introduced by
You have used a bitwise operator | in a condition. Did you maybe want to use the logical operator ||
Loading history...
133
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
134
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>';
135
                    } else if (file.type === 'application/ppt' | 'application/pptx') {
136
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
137
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>';
138
                    } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') {
139
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
140
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>';
141
                    } else if (file.type === 'audio/mpeg') {
142
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
143
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>';
144
                    } else {
145
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
146
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>';
147
                    }
148
                    // Hookup the start button
149
                    file.previewElement.querySelector(".start").onclick = function() { dropzoneTable.enqueueFile(file); };
150
                });
151
152
                dropzoneTable.on("totaluploadprogress", function(progress) {
153
                    document.querySelector("#dropzone-table-total-progress .progress-bar").style.width = progress + "%";
154
                });
155
156
                dropzoneTable.on("sending", function(file) {
157
                    // Show the total progress bar when upload starts
158
                    document.querySelector("#dropzone-table-total-progress").style.opacity = "1";
159
                    // And disable the start button
160
                    file.previewElement.querySelector(".start").setAttribute("disabled", "disabled");
161
                });
162
163
                dropzoneTable.on("success", function (file, resp) {
0 ignored issues
show
Unused Code introduced by
The parameter resp is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
164
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
165
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
166
                });
167
168
                dropzoneTable.on("error", function (file) {
169
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
170
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
171
                });
172
173
                dropzoneTable.on("queuecomplete", function(progress) {
0 ignored issues
show
Unused Code introduced by
The parameter progress is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
174
                    document.querySelector("#dropzone-table-total-progress").style.opacity = "0";
175
                });
176
177
                // Setup the buttons for all transfers
178
                // The "add files" button doesn't need to be setup because the config
179
                // `clickable` has already been specified.
180
                document.querySelector("#dropzone-table-actions .start").onclick = function() {
181
                    dropzoneTable.enqueueFiles(dropzoneTable.getFilesWithStatus(Dropzone.ADDED));
182
                };
183
184
                document.querySelector("#dropzone-table-actions .cancel").onclick = function() {
185
                    dropzoneTable.removeAllFiles(true);
186
                };
187
            }
188
        }
189
    }
190
191
    initDropify(){
192
        $('.dropify').dropify();
193
    }
194
}