Passed
Push — master ( e7a545...e1164f )
by
unknown
01:05 queued 17s
created

drupal/sites/default/boinc/modules/flag_abuse_reason/includes/flag_abuse_reason.js   A

Complexity

Total Complexity 17
Complexity/F 17

Size

Lines of Code 109
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 55
c 0
b 0
f 0
dl 0
loc 109
rs 10
wmc 17
mnd 16
bc 16
fnc 1
bpm 16
cpm 17
noi 1
1
/** 
2
 * @file
3
 *
4
 * Javascript for flag_abuse_reason. Shows the dropdown box defined in
5
 * the template.
6
 */
7
8
/**
9
 * Useful variables/parameters
10
 *
11
 * data.contentId   - Id of content, e.g., node id, comment id, etc.
12
 * data.contentType - Type of content, e.g., node, comment, etc.
13
 * data.flagName    - Name of the flag.
14
 * data.flagStatus  - State of the flag.
15
 */
16
17
$(document).bind('flagGlobalBeforeLinkUpdate', function(event, data) {
18
  /* dd is the dropdown defined the boinc template.
19
   */
20
  var dd = 'flag_abuse_reason-dropdown-' + data.contentType + '-' + data.contentId;
21
  var ddelement = document.getElementById(dd);
22
23
  // Only node, comment, and user types are defined.
24
  switch (data.contentType) {
25
    case 'node':
26
    /**
27
     * Node
28
     */
29
    // User clicks on the Report link
30
    if ( window.getComputedStyle(ddelement).display === "none" &&
31
         data.flagName == "abuse_node_meta" && 
32
         data.flagStatus == "flagged" ) {
33
      ddelement.style.display = "block";
34
    }
35
  
36
    if ( window.getComputedStyle(ddelement).display === "block" ) {
37
      // User clicks on any of the flags in the drop down
38
      if ( data.flagName != "abuse_node_meta" && 
39
  	 data.flagStatus == "flagged" ) {
40
        ddelement.style.display = "none";
41
      }
42
      // User clicks on Cancel Report
43
      else if ( data.flagName == "abuse_node_meta" && 
44
  	      data.flagStatus == "unflagged" ) {
45
        ddelement.style.display = "none";
46
      }
47
    }
48
49
    // User unflags by Cancel Report - refresh page
50
    if ( window.getComputedStyle(ddelement).display === "none" &&
51
         data.flagName == "abuse_node_meta" &&
52
         data.flagStatus == "unflagged" ) {
53
	window.location.reload();
54
    }
55
56
    break;
57
58
    case 'comment':
59
    /**
60
     * Comments
61
     */
62
    // User clicks on the Report link
63
    if ( window.getComputedStyle(ddelement).display === "none" &&
64
         data.flagName == "abuse_comment_meta" && 
65
         data.flagStatus == "flagged" ) {
66
      ddelement.style.display = "block";
67
    }
68
  
69
    if ( window.getComputedStyle(ddelement).display === "block" ) {
70
      // User clicks on any of the flags in the drop down
71
      if ( data.flagName != "abuse_comment_meta" && 
72
  	 data.flagStatus == "flagged" ) {
73
        ddelement.style.display = "none";
74
      }
75
      // User clicks on Cancel Report
76
      else if ( data.flagName == "abuse_comment_meta" && 
77
  	      data.flagStatus == "unflagged" ) {
78
        ddelement.style.display = "none";
79
      }
80
    }
81
82
    // User unflags by Cancel Report - refresh page
83
    if ( window.getComputedStyle(ddelement).display === "none" &&
84
         data.flagName == "abuse_comment_meta" &&
85
         data.flagStatus == "unflagged" ) {
86
	window.location.reload();
87
    }
88
89
    break;
90
91
    case 'user':
92
  /**
93
   * User
94
   */
95
  // User clicks on the Report link
96
    if ( window.getComputedStyle(ddelement).display === "none" &&
97
         data.flagName == "abuse_user_meta" && 
98
         data.flagStatus == "flagged" ) {
99
      ddelement.style.display = "block";
100
    }
101
  
102
    if ( window.getComputedStyle(ddelement).display === "block" ) {
103
      // User clicks on any of the flags in the drop down
104
      if ( data.flagName != "abuse_user_meta" && 
105
  	 data.flagStatus == "flagged" ) {
106
        ddelement.style.display = "none";
107
      }
108
      // User clicks on Cancel Report
109
      else if ( data.flagName == "abuse_user_meta" && 
110
  	      data.flagStatus == "unflagged" ) {
111
        ddelement.style.display = "none";
112
      }
113
    }
114
115
    // User unflags by Cancel Report - refresh page
116
    if ( window.getComputedStyle(ddelement).display === "none" &&
117
         data.flagName == "abuse_user_meta" &&
118
         data.flagStatus == "unflagged" ) {
119
	window.location.reload();
120
    }
121
122
    break;
123
  } //switch
124
125
});
126
0 ignored issues
show
Coding Style introduced by
Additional whitespace found at end of file
Loading history...
127