Passed
Push — master ( 78492a...4f268f )
by Paul
04:26
created

+/scripts/admin/status.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 35
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 0
nc 2
dl 0
loc 35
rs 10
c 2
b 1
f 0
wmc 9
mnd 1
bc 5
fnc 5
bpm 1
cpm 1.8
noi 0

2 Functions

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