web/public/s/js/channelEditJ.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 1.11

Size

Lines of Code 79
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 56
c 0
b 0
f 0
dl 0
loc 79
rs 10
wmc 10
mnd 1
bc 1
fnc 9
bpm 0.1111
cpm 1.1111
noi 6

5 Functions

Rating   Name   Duplication   Size   Complexity  
A channelEditJ.js ➔ onDrop 0 13 1
A channelEditJ.js ➔ getData 0 15 5
A channelEditJ.js ➔ draggables2json 0 8 2
A channelEditJ.js ➔ onDragStart 0 10 1
A channelEditJ.js ➔ onDragOver 0 3 1
1
var alerts = 0; 
2
$('#leftlayoutset' ).submit(
3
    function( e ) {
4
        var data = new FormData(this);
5
        jQuery.each(jQuery('#fileToUpload')[0].files, function(i, file) {
6
            data.append('file-'+i, file);
7
        });
8
9
        $.ajax( {
10
            url: '/post/channel_update_new',
11
            type: 'POST',
12
            data: data,
13
            cache: false,
14
            processData: false,
15
            contentType: false,
16
            success: function(result){
17
                alerts++;
18
                addAlert("editsuccess_" + alerts, "Successfully updated your channel!");
19
                showAlert("#editsuccess_" + alerts);
20
                console.log("DEBUG: " + result);
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...
21
            }
22
        } );
23
        e.preventDefault();
24
    } 
25
);
26
27
function getData() {
28
    var layout = draggables2json();
29
30
    $.ajax({
31
    url: 'set_customization.php',
32
    method: 'POST',
33
    dataType: 'text',
34
    data: {
35
        layout: layout,
36
    },
37
    success: function(response) {
0 ignored issues
show
Unused Code introduced by
The parameter response 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...
38
        alert("Successfully updated your channel layout.");
0 ignored issues
show
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
39
    }
40
    });
41
};
42
43
function onDragStart(event) {
44
  event
45
    .dataTransfer
46
    .setData('text/plain', event.target.id);
47
48
  event
49
    .currentTarget
50
    .style
51
    .backgroundColor = '#f2f2f2;';
52
}
53
54
function onDrop(event) {
55
  const id = event
56
    .dataTransfer
57
    .getData('text');
58
59
    const draggableElement = document.getElementById(id);
60
    const dropzone = event.target;
61
    dropzone.appendChild(draggableElement);
62
63
    event
64
    .dataTransfer
65
    .clearData();
66
}
67
68
function onDragOver(event) {
69
  event.preventDefault();
70
}
71
72
function draggables2json() {
73
  draggables = $("#layout").children();
0 ignored issues
show
Bug introduced by
The variable draggables seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.draggables.
Loading history...
74
  outj = {};
0 ignored issues
show
Bug introduced by
The variable outj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.outj.
Loading history...
75
  for (di=0; di < draggables.length; di++) {
0 ignored issues
show
Bug introduced by
The variable di seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.di.
Loading history...
76
    outj[di] = draggables[di].textContent.replace(/\s+$/, '');
77
  }
78
  return JSON.stringify(outj);
79
}