Passed
Push — master ( 203c84...bd5512 )
by Paul
04:35
created

+/scripts/admin/status.js   A

Complexity

Total Complexity 8
Complexity/F 2

Size

Lines of Code 28
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
nc 2
dl 0
loc 28
rs 10
c 1
b 1
f 0
wmc 8
mnd 1
bc 4
fnc 4
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A GLSR.status.onClick 0 17 3
1
/** global: GLSR, site_reviews, x */
2
GLSR.status = function( selector ) {
3
	var elements = document.querySelectorAll( selector );
4
	if( !elements.length )return;
5
	elements.forEach( function( el ) {
6
		el.addEventListener( 'click', this.onClick );
7
	}.bind( this ));
8
};
9
10
GLSR.status.prototype = {
11
12
	onClick: function( ev ) {
13
		var post_id = ev.target.href.match(/post=([0-9]+)/);
14
		var status = ev.target.href.match(/action=([a-z]+)/);
15
		if( post_id === null || status === null )return;
16
		var request = {
17
			action: 'change-review-status',
18
			nonce: site_reviews.status_nonce,
19
			post_id: post_id[1],
20
			status: status[1],
21
		};
22
		GLSR.postAjax( ev, request, function( response ) {
23
			if( !response.class )return;
24
			var el = x( ev.target );
25
			el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class );
26
			el.closest( 'td.column-title' ).find( 'strong' ).html( response.link );
27
		});
28
	},
29
};
30