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 ( e018a8...9950db )
by
unknown
03:23
created

Upload.js ➔ ... ➔ dropzoneCardsForm.success   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 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 = dropzoneCards.find('#dropzone-cards-template');
46
                dropzoneCardsFilePreview.removeAttr('id');
47
48
                let dropzoneCardsFilePreviewTemplate = dropzoneCardsFilePreview.parent().html();
49
                dropzoneCardsFilePreview.parent().remove();
50
51
                let dropzoneCardsForm = new Dropzone('#dropzone-cards-form', {
52
                    url: dropzoneCardsActionUrl,
53
                    autoProcessQueue: true,
54
                    thumbnailWidth: null,
55
                    thumbnailHeight: null,
56
                    previewTemplate: dropzoneCardsFilePreviewTemplate
57
                });
58
59 View Code Duplication
                dropzoneCardsForm.on("addedfile", function (file) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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') {
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...
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
                dropzoneCardsForm.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...
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
                dropzoneCardsForm.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
            const dropzoneTable = $('#dropzone-table');
103
            if(dropzoneTable.length) {
104
105
                let dropzoneTableActionUrl = dropzoneTable.data('action-url');
106
107
                let dropzoneTableFilePreview = dropzoneTable.find('#dropzone-table-template');
108
                dropzoneTableFilePreview.removeAttr('id');
109
110
                let dropzoneTableFilePreviewTemplate = dropzoneTableFilePreview.parent().html();
111
                dropzoneTableFilePreview.parent().remove();
112
113
                let dropzoneTableForm = new Dropzone('#dropzone-table-form', {
114
                    url: dropzoneTableActionUrl,
115
                    autoProcessQueue: false,
116
                    thumbnailWidth: null,
117
                    thumbnailHeight: null,
118
                    previewTemplate: dropzoneTableFilePreviewTemplate, // Define the container to display the previews
119
                    previewsContainer: ".media-list-table",
120
                    clickable: "#dropzone-add-file", // Define the element that should be used as click trigger to select files.
121
                });
122
                
123
                dropzoneTableForm.on("addedfile", function (file) {
124
                    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...
125
                    var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'];
126
                    if (imagesFileTypes.indexOf(file.type) != -1) {
127
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'none';
128
                    } else if (file.type === 'application/pdf') {
129
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
130
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>';
131
                    } 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...
132
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
133
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>';
134
                    } else if (file.type === 'application/ppt' | 'application/pptx') {
135
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
136
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>';
137
                    } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') {
138
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
139
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>';
140
                    } else if (file.type === 'audio/mpeg') {
141
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
142
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>';
143
                    } else {
144
                        file.previewElement.querySelector('.media-item-file-details').style.display = 'block';
145
                        file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>';
146
                    }
147
                    // Hookup the start button
148
                    file.previewElement.querySelector(".start").onclick = function() { dropzoneTableForm.enqueueFile(file); };
149
                });
150
151
                dropzoneTableForm.on("totaluploadprogress", function(progress) {
152
                    document.querySelector("#dropzone-table-total-progress .progress-bar").style.width = progress + "%";
153
                });
154
155
                dropzoneTableForm.on("sending", function(file) {
156
                    // Show the total progress bar when upload starts
157
                    document.querySelector("#dropzone-table-total-progress").style.opacity = "1";
158
                    // And disable the start button
159
                    file.previewElement.querySelector(".start").setAttribute("disabled", "disabled");
160
                });
161
162
                dropzoneTableForm.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...
163
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
164
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
165
                });
166
167
                dropzoneTableForm.on("error", function (file) {
168
                    file.previewElement.querySelector(".upload-progress").style.display = 'none';
169
                    file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type;
170
                });
171
172
                dropzoneTableForm.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...
173
                    document.querySelector("#dropzone-table-total-progress").style.opacity = "0";
174
                });
175
176
                // Setup the buttons for all transfers
177
                // The "add files" button doesn't need to be setup because the config
178
                // `clickable` has already been specified.
179
                document.querySelector("#dropzone-table-actions .start").onclick = function() {
180
                    dropzoneTableForm.enqueueFiles(dropzoneTableForm.getFilesWithStatus(Dropzone.ADDED));
181
                };
182
183
                document.querySelector("#dropzone-table-actions .cancel").onclick = function() {
184
                    dropzoneTableForm.removeAllFiles(true);
185
                };
186
            }
187
        }
188
    }
189
190
    initDropify(){
191
        $('.dropify').dropify();
192
    }
193
}