Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -199,6 +199,15 @@ |
200 | 200 | 'scripts' => array( |
201 | 201 | 'reviews.pager.js', |
202 | 202 | ), |
| 203 | + 'dependencies' => array( |
| 204 | + 'jquery.reviewState' |
| 205 | + ), |
| 206 | +); |
| 207 | + |
| 208 | +$wgResourceModules['jquery.reviewState'] = $moduleTemplate + array( |
| 209 | + 'scripts' => array( |
| 210 | + 'jquery.reviewState.js', |
| 211 | + ), |
203 | 212 | 'messages' => array( |
204 | 213 | 'reviews-pager-change-new', |
205 | 214 | 'reviews-pager-change-flagged', |
Index: trunk/extensions/Reviews/resources/jquery.reviewState.js |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Reviews MediaWiki extension. |
| 4 | + * @see https://www.mediawiki.org/wiki/Extension:Reviews |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $, mw ) { $.fn.reviewState = function() { |
| 11 | + |
| 12 | + var _this = this; |
| 13 | + |
| 14 | + this.updateStateLinks = function( $container, id, state ) { |
| 15 | + $container.text( '' ); |
| 16 | + |
| 17 | + $container.attr( { |
| 18 | + 'data-review-state': state |
| 19 | + } ); |
| 20 | + |
| 21 | + var linksForState = { |
| 22 | + 'new': ['flagged', 'reviewed'], |
| 23 | + 'flagged': ['new', 'reviewed'], |
| 24 | + 'reviewed': ['flagged'] |
| 25 | + }; |
| 26 | + |
| 27 | + for ( i in linksForState[state] ) { |
| 28 | + if ( linksForState[state].hasOwnProperty( i ) ) { |
| 29 | + var targetState = linksForState[state][i]; |
| 30 | + var isFirst = $container.text() === ''; |
| 31 | + |
| 32 | + if ( isFirst ) { |
| 33 | + $container.append( mw.msg( 'reviews-state-' + state ), ' (' ); |
| 34 | + } |
| 35 | + else { |
| 36 | + $container.append( ' | ' ); |
| 37 | + } |
| 38 | + |
| 39 | + $container.append( $( '<a>' ).attr( { |
| 40 | + 'class': 'review-flag-link', |
| 41 | + 'data-target': targetState |
| 42 | + } ).text( mw.msg( 'reviews-pager-change-' + targetState ) ).click( _this.onLinkClick ) ); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + $container.append( ')' ); |
| 47 | + }; |
| 48 | + |
| 49 | + this.onLinkClick = function() { |
| 50 | + var $this = $( this ); |
| 51 | + var $container = $this.closest( 'div' ); |
| 52 | + var state = $container.attr( 'data-review-state' ); |
| 53 | + var targetState = $this.attr( 'data-target' ); |
| 54 | + var id = $container.attr( 'data-review-id' ); |
| 55 | + |
| 56 | + if ( confirm( mw.msg( 'reviews-pager-confirm-' + targetState ) ) ) { |
| 57 | + var requestArgs = { |
| 58 | + 'action': 'flagreviews', |
| 59 | + 'format': 'json', |
| 60 | + 'token': mw.user.tokens.get( 'editToken' ), |
| 61 | + 'state': targetState, |
| 62 | + 'ids': id |
| 63 | + }; |
| 64 | + |
| 65 | + $container.text( mw.msg( 'reviews-pager-updating' ) ); |
| 66 | + |
| 67 | + $.post( |
| 68 | + wgScriptPath + '/api.php', |
| 69 | + requestArgs, |
| 70 | + function( data ) { |
| 71 | + if ( data.hasOwnProperty( 'success' ) && data.success ) { |
| 72 | + _this.updateStateLinks( $container, id, targetState ); |
| 73 | + } |
| 74 | + else { |
| 75 | + // TODO |
| 76 | + alert( 'Could not change the state of the review' ); |
| 77 | + |
| 78 | + _this.updateStateLinks( $container, id, state ); |
| 79 | + } |
| 80 | + } |
| 81 | + ); |
| 82 | + } |
| 83 | + }; |
| 84 | + |
| 85 | + this.setup = function() { |
| 86 | + var $this = $( _this ); |
| 87 | + |
| 88 | + _this.updateStateLinks( |
| 89 | + $this, |
| 90 | + $this.attr( 'data-review-id' ), |
| 91 | + $this.attr( 'data-review-state' ) |
| 92 | + ); |
| 93 | + }; |
| 94 | + |
| 95 | + this.setup(); |
| 96 | + |
| 97 | + return this; |
| 98 | + |
| 99 | +}; })( window.jQuery, window.mediaWiki ); |
Property changes on: trunk/extensions/Reviews/resources/jquery.reviewState.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 100 | + native |
Index: trunk/extensions/Reviews/resources/reviews.pager.js |
— | — | @@ -8,89 +8,9 @@ |
9 | 9 | |
10 | 10 | (function( $, mw ) { |
11 | 11 | |
12 | | - var _this = this; |
13 | | - |
14 | | - this.updateStateLinks = function( $container, id, state ) { |
15 | | - $container.text( '' ); |
16 | | - |
17 | | - $container.attr( { |
18 | | - 'data-review-state': state |
19 | | - } ); |
20 | | - |
21 | | - var linksForState = { |
22 | | - 'new': ['flagged', 'reviewed'], |
23 | | - 'flagged': ['new', 'reviewed'], |
24 | | - 'reviewed': ['flagged'] |
25 | | - }; |
26 | | - |
27 | | - for ( i in linksForState[state] ) { |
28 | | - if ( linksForState[state].hasOwnProperty( i ) ) { |
29 | | - var targetState = linksForState[state][i]; |
30 | | - var isFirst = $container.text() === ''; |
31 | | - |
32 | | - if ( isFirst ) { |
33 | | - $container.append( mw.msg( 'reviews-state-' + state ), ' (' ); |
34 | | - } |
35 | | - else { |
36 | | - $container.append( ' | ' ); |
37 | | - } |
38 | | - |
39 | | - $container.append( $( '<a>' ).attr( { |
40 | | - 'class': 'review-flag-link', |
41 | | - 'data-target': targetState |
42 | | - } ).text( mw.msg( 'reviews-pager-change-' + targetState ) ).click( _this.onLinkClick ) ); |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - $container.append( ')' ); |
47 | | - }; |
48 | | - |
49 | | - this.onLinkClick = function() { |
50 | | - var $this = $( this ); |
51 | | - var $container = $this.closest( 'div' ); |
52 | | - var state = $container.attr( 'data-review-state' ); |
53 | | - var targetState = $this.attr( 'data-target' ); |
54 | | - var id = $container.attr( 'data-review-id' ); |
55 | | - |
56 | | - if ( confirm( mw.msg( 'reviews-pager-confirm-' + targetState ) ) ) { |
57 | | - var requestArgs = { |
58 | | - 'action': 'flagreviews', |
59 | | - 'format': 'json', |
60 | | - 'token': mw.user.tokens.get( 'editToken' ), |
61 | | - 'state': targetState, |
62 | | - 'ids': id |
63 | | - }; |
64 | | - |
65 | | - $container.text( mw.msg( 'reviews-pager-updating' ) ); |
66 | | - |
67 | | - $.post( |
68 | | - wgScriptPath + '/api.php', |
69 | | - requestArgs, |
70 | | - function( data ) { |
71 | | - if ( data.hasOwnProperty( 'success' ) && data.success ) { |
72 | | - _this.updateStateLinks( $container, id, targetState ); |
73 | | - } |
74 | | - else { |
75 | | - // TODO |
76 | | - alert( 'Could not change the state of the review' ); |
77 | | - |
78 | | - _this.updateStateLinks( $container, id, state ); |
79 | | - } |
80 | | - } |
81 | | - ); |
82 | | - } |
83 | | - }; |
84 | | - |
85 | 12 | $( document ).ready( function() { |
86 | 13 | |
87 | | - $.each( $( '.reviews-state-controls' ), function( i, element ) { |
88 | | - $e = $( element ); |
89 | | - _this.updateStateLinks( |
90 | | - $e, |
91 | | - $e.attr( 'data-review-id' ), |
92 | | - $e.attr( 'data-review-state' ) |
93 | | - ); |
94 | | - } ); |
| 14 | + $( '.reviews-state-controls' ).reviewState(); |
95 | 15 | |
96 | 16 | } ); |
97 | 17 | |