Completed
Branch master (2f299a)
by Ron
11:00
created

app.js ➔ multiFileDrop   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
nc 1
nop 1
dl 0
loc 62
c 0
b 0
f 0
cc 1
rs 8.9919

1 Function

Rating   Name   Duplication   Size   Complexity  
A app.js ➔ ... ➔ $(ꞌ#dropzone-boxꞌ).dropzone.init 0 48 1

How to fix   Long Method   

Long Method

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:

1
//  Third Party Libraries
2
require('./bootstrap');
3
require('jquery-easing');
4
require('datatables.net-bs4');
5
require('dropzone');
6
require('select2');
7
//require('clipboard');
8
9
$(document).ready(function()
10
{
11
    //  Enable any tooltips on the page
12
    initTooltip();
13
});
14
15
//  Initialize any tooltips on the page
16
function initTooltip()
17
{
18
    $('[data-tooltip="tooltip"]').tooltip();
19
}
20
21
/////////////////////////// Drag and Drop/File Upload Functions ////////////////////////////////////
22
//  Initialize drag and drop for only one file
23
function fileDrop(form)
24
{
25
    //  Initialize Drag and Drop            
26
    var drop = $('#dropzone-box').dropzone(
0 ignored issues
show
Unused Code introduced by
The variable drop seems to be never used. Consider removing it.
Loading history...
27
    {
28
        url: form.attr('action'),
29
        autoProcessQueue: false,
30
        maxFilesize: maxUpload,
0 ignored issues
show
Bug introduced by
The variable maxUpload seems to be never declared. If this is a global, consider adding a /** global: maxUpload */ 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...
31
        uploadMultiple: false,
32
        parallelUploads: 1,
33
        maxFiles: 1,
34
        addRemoveLinks: true,
35
        init: function()
36
        {
37
            var myDrop = this;
38
            form.on('submit', function(e, formData)
0 ignored issues
show
Unused Code introduced by
The parameter formData 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...
39
            {
40
                e.preventDefault();
41
                myDrop.processQueue();
42
                $('#forProgressBar').show();
43
                $('.submit-button').attr('disabled', true);
44
            });
45
            this.on('sending',  function(file, xhr, formData)
46
            {
47
                var formArray = form.serializeArray();
48
                $.each(formArray, function()
49
                {
50
                    formData.append(this.name, this.value);
51
                });
52
            });
53
            this.on('totaluploadprogress', function(progress)
54
            {
55
                $("#progressBar").css("width", Math.round(progress)+"%");
56
                $("#progressStatus").text(Math.round(progress)+"%");
57
                console.log(progress);
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...
58
            });
59
            this.on('reset', function()
60
            {
61
                $('#form-errors').addClass('d-none');
62
            });
63
            this.on('success', function(files, response)
64
            {    
65
                uploadComplete(response);
66
            });
67
            this.on('error', function(file, response)
68
            {
69
                uploadFailed(response);
70
            });
71
        }
72
    });  
73
}
74
75
//  Initialize drag and drop for multiple file uploads
76
function multiFileDrop(form)
77
{
78
    //  Initialize Drag and Drop            
79
    var drop = $('#dropzone-box').dropzone(
0 ignored issues
show
Unused Code introduced by
The variable drop seems to be never used. Consider removing it.
Loading history...
80
    {
81
        url: form.attr('action'),
82
        autoProcessQueue: false,
83
        uploadMultiple: true,
84
        parallelUploads: 10,
85
        maxFiles: 10,
86
        maxFilesize: maxUpload,
0 ignored issues
show
Bug introduced by
The variable maxUpload seems to be never declared. If this is a global, consider adding a /** global: maxUpload */ 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...
87
        addRemoveLinks: true,
88
        init: function()
89
        {
90
            var myDrop = this;
91
            form.on('submit', function(e, formData)
0 ignored issues
show
Unused Code introduced by
The parameter formData 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...
92
            {
93
                e.preventDefault();
94
                if(myDrop.getQueuedFiles().length > 0)
95
                {
96
                    myDrop.processQueue();
97
                    $('#forProgressBar').show();
98
                    $('.submit-button').attr('disabled', true);
99
                }
100
                else
101
                {
102
                    $.post(form.attr('action'), form.serialize(), function(data)
103
                    {
104
                        uploadComplete(data);
105
                    });
106
                }
107
            });
108
            this.on('sendingmultiple',  function(file, xhr, formData)
109
            {
110
                var formArray = form.serializeArray();
111
                $.each(formArray, function()
112
                {
113
                    formData.append(this.name, this.value);
114
                });
115
            });
116
            this.on('totaluploadprogress', function(progress)
117
            {
118
                $("#progressBar").css("width", Math.round(progress)+"%");
119
                $("#progressStatus").text(Math.round(progress)+"%");
120
                console.log(progress);
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...
121
            });
122
            this.on('reset', function()
123
            {
124
                $('#form-errors').addClass('d-none');
125
            });
126
            this.on('successmultiple', function(files, response)
127
            {    
128
                this.removeAllFiles(true);
129
                uploadComplete(response);
130
            });
131
            this.on('errormultiple', function(file, response)
132
            {
133
                uploadFailed(response);
134
            });
135
        }
136
    });
137
}
138
139
//  Reset the progress bar and drag and drop box
140
function resetProgressBar()
141
{
142
    $('#dragndrop-notice').text('Or Drag Files Here');
143
    $('#progressBar').css('width', '0%').attr('aria-valuenow', 0);
144
    $('#progressStatus').text('');
145
    $('#forProgressBar').hide();
146
}
147
148
//  Reset the Edit Modal to its default state
149
function resetEditModal()
150
{
151
    $('#edit-modal').modal('hide');
152
    $('#edit-modal').find('.modal-title').text('');
153
    $('#edit-modal').find('.modal-body').text('');
154
}
155
156
//////////////////////////////////////////////////////////////////////////////////////////
157
158
//  Make the functions in this file globally accessable
159
window.resetProgressBar = resetProgressBar;
160
window.resetEditModal   = resetEditModal;
161
window.fileDrop         = fileDrop;
162
window.multiFileDrop    = multiFileDrop;
163