Passed
Push — master ( 6e3134...9d1f81 )
by Paul
04:23
created

+/scripts/admin/status.js   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 2
nop 1
dl 0
loc 33
rs 9.0879
c 1
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A GLSR.Status.onClick_ 0 17 3
A GLSR.Status 0 7 2
1
/** global: GLSR, jQuery */
2
;(function( x ) {
3
4
	'use strict';
5
6
	GLSR.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
	GLSR.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
})( jQuery );
35