Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css |
— | — | @@ -116,9 +116,10 @@ |
117 | 117 | .article-assessment-wrapper .article-assessment-rating-field-name { |
118 | 118 | float: left; |
119 | 119 | width: 90px; |
| 120 | + font-weight: bold; |
| 121 | + font-size: 11px; |
120 | 122 | } |
121 | | -.article-assessment-wrapper .article-assessment-rating-field-value-wrapper, |
122 | | -.article-assessment-wrapper .article-assessment-rating-field-value-disabled { |
| 123 | +.article-assessment-wrapper .article-assessment-rating-field-value-wrapper { |
123 | 124 | background: url( ../images/rating_bg.gif ) 0 0 no-repeat; |
124 | 125 | width: 120px; |
125 | 126 | height: 13px; |
— | — | @@ -126,6 +127,7 @@ |
127 | 128 | float: left; |
128 | 129 | padding: 2px; |
129 | 130 | text-indent: -9999px; |
| 131 | + margin-top: 2px; |
130 | 132 | } |
131 | 133 | .article-assessment-wrapper .article-assessment-rate-instructions, |
132 | 134 | .article-assessment-wrapper .article-assessment-rate-feedback, |
— | — | @@ -146,19 +148,37 @@ |
147 | 149 | float: right; |
148 | 150 | display: block; |
149 | 151 | } |
150 | | -.article-assessment-wrapper .article-assessment-rating-field-value-disabled { |
151 | | - background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat; |
152 | | -} |
153 | 152 | .article-assessment-wrapper .article-assessment-wrapper .article-assessment-rating-fields { |
154 | 153 | margin: 8px 0; |
155 | 154 | } |
156 | 155 | .article-assessment-wrapper .article-assessment-rating-fields .field-wrapper { |
157 | 156 | margin-bottom: 5px; |
158 | 157 | } |
| 158 | +.article-assessment-rating-count { |
| 159 | + font-size: 11px; |
| 160 | + margin-left: 5px; |
| 161 | + float: left; |
| 162 | +} |
| 163 | +.article-assessment-submit input { |
| 164 | + margin: 2px 0; |
| 165 | +} |
| 166 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value-wrapper { |
| 167 | + background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat; |
| 168 | +} |
| 169 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value { |
| 170 | + display: none; |
| 171 | +} |
| 172 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-count { |
| 173 | + display: none; |
| 174 | +} |
| 175 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-name { |
| 176 | + color: #9f9f9f; |
| 177 | +} |
159 | 178 | /* Self Clearing Floats */ |
160 | 179 | .article-assessment-wrapper .article-assessment-information:after, |
161 | 180 | .article-assessment-wrapper .field-wrapper:after, |
162 | 181 | .article-assessment-wrapper .article-assessment-rating-fields:after, |
| 182 | +.article-assessment-rating:after, |
163 | 183 | .article-assessment-wrapper .article-assessment-submit:after, |
164 | 184 | .article-assessment-wrapper .rating-fields:after { |
165 | 185 | content: "."; |
— | — | @@ -170,6 +190,7 @@ |
171 | 191 | .article-assessment-wrapper .field-wrapper, |
172 | 192 | .article-assessment-wrapper .article-assessment-information, |
173 | 193 | .article-assessment-wrapper .article-assessment-rating-fields, |
| 194 | +.article-assessment-rating, |
174 | 195 | .article-assessment-wrapper .article-assessment-submit, |
175 | 196 | .article-assessment-wrapper .rating-fields { |
176 | 197 | display: inline-block; |
— | — | @@ -177,6 +198,7 @@ |
178 | 199 | * html .article-assessment-wrapper .field-wrapper, |
179 | 200 | * html .article-assessment-wrapper .article-assessment-information, |
180 | 201 | * html .article-assessment-wrapper .article-assessment-rating-fields, |
| 202 | +* html .article-assessment-rating, |
181 | 203 | * html .article-assessment-wrapper .article-assessment-submit, |
182 | 204 | * html .article-assessment-wrapper .rating-fields { |
183 | 205 | height: 1%; |
— | — | @@ -184,6 +206,7 @@ |
185 | 207 | .article-assessment-wrapper .field-wrapper, |
186 | 208 | .article-assessment-wrapper .article-assessment-information, |
187 | 209 | .article-assessment-wrapper .article-assessment-rating-fields, |
| 210 | +.article-assessment-rating, |
188 | 211 | .article-assessment-wrapper .article-assessment-submit, |
189 | 212 | .article-assessment-wrapper .rating-fields { |
190 | 213 | display: block; |
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | 'fieldPrefix': 'articleassessment-rating-', |
20 | 20 | 'fieldHTML': '<div class="field-wrapper"> \ |
21 | 21 | <label for="rating_{FIELD}" original-title="{HINT}" class="rating-field-label">{LABEL}</label> \ |
22 | | - <select id="rating_{FIELD}" name="rating[{FIELD}]" class="rating-field"> \ |
| 22 | + <select id="rating_{FIELD}" name="rating{FIELD}" class="rating-field"> \ |
23 | 23 | <option value="1">1</option> \ |
24 | 24 | <option value="2">2</option> \ |
25 | 25 | <option value="3">3</option> \ |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | </fieldset> \ |
50 | 50 | </form> \ |
51 | 51 | </div>', |
52 | | - 'ratingHTML': '<div class="article-assessment-rating"> \ |
| 52 | + 'ratingHTML': '<div class="article-assessment-rating" id="articleassessment-rating-{FIELD}"> \ |
53 | 53 | <span class="article-assessment-rating-field-name">{LABEL}</span> \ |
54 | 54 | <span class="article-assessment-rating-field-value-wrapper"> \ |
55 | 55 | <span class="article-assessment-rating-field-value">{VALUE}</span> \ |
— | — | @@ -76,24 +76,63 @@ |
77 | 77 | .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback') ) |
78 | 78 | .replace( /\{YOURFEEDBACK\}/g, mw.usability.getMsg('articleassessment-yourfeedback') ) |
79 | 79 | .replace( /\{ARTICLERATING\}/g, mw.usability.getMsg('articleassessment-articlerating' ) ) |
80 | | - .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' ) ) |
81 | | - .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' ) ) ); |
| 80 | + .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' ) |
| 81 | + .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) |
| 82 | + .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' ) |
| 83 | + .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) ); |
82 | 84 | for( var field in settings.fieldMessages ) { |
83 | 85 | $output.find( '.article-assessment-rating-fields' ) |
84 | 86 | .append( $( settings.fieldHTML |
85 | 87 | .replace( /\{LABEL\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) ) |
86 | | - .replace( /\{FIELD\}/g, mw.usability.getMsg( settings.fieldMessages[field] ) ) |
| 88 | + .replace( /\{FIELD\}/g, "[" + settings.fieldMessages[field] + "]" ) |
87 | 89 | .replace( /\{HINT\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) ); |
88 | 90 | $output.find( '#article-assessment-ratings' ) |
89 | 91 | .append( $( settings.ratingHTML |
90 | 92 | .replace( /\{LABEL\}/g, mw.usability.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) ) |
| 93 | + .replace( /\{FIELD\}/g, settings.fieldMessages[field] ) |
91 | 94 | .replace( /\{VALUE\}/g, '0%' ) |
92 | 95 | .replace( /\{COUNT\}/g, mw.usability.getMsg( 'field-count' ) ) ) |
93 | 96 | ); |
94 | 97 | } |
95 | | - |
| 98 | + $output.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings }); |
| 99 | + // hook up the ratings show/hide |
| 100 | + $output |
| 101 | + .find( '.article-assessment-show-ratings a' ) |
| 102 | + .click( function() { |
| 103 | + $( this ) |
| 104 | + .parent() |
| 105 | + .hide(); |
| 106 | + $output |
| 107 | + .find( '#article-assessment-ratings' ) |
| 108 | + .removeClass( 'article-assessment-ratings-disabled' ) |
| 109 | + .end() |
| 110 | + .find( '.article-assessment-hide-ratings' ) |
| 111 | + .show(); |
| 112 | + return false; |
| 113 | + } ) |
| 114 | + .end() |
| 115 | + .find( '.article-assessment-hide-ratings a' ) |
| 116 | + .click( function() { |
| 117 | + $( this ) |
| 118 | + .parent() |
| 119 | + .hide(); |
| 120 | + $output |
| 121 | + .find( '#article-assessment-ratings' ) |
| 122 | + .addClass( 'article-assessment-ratings-disabled' ) |
| 123 | + .end() |
| 124 | + .find( '.article-assessment-show-ratings' ) |
| 125 | + .show(); |
| 126 | + return false; |
| 127 | + } ) |
| 128 | + .click(); |
96 | 129 | $( '#catlinks' ).before( $output ); |
97 | 130 | |
| 131 | + // set the height of our smaller fieldset to match the taller |
| 132 | + if( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) { |
| 133 | + $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() ); |
| 134 | + } else { |
| 135 | + $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() ); |
| 136 | + } |
98 | 137 | // attempt to fetch the ratings |
99 | 138 | $.ArticleAssessment.fn.getRatingData(); |
100 | 139 | |
— | — | @@ -115,15 +154,6 @@ |
116 | 155 | } |
117 | 156 | } ); |
118 | 157 | }); |
119 | | - // if the rating is stale, add the stale class |
120 | | - if( true /* replace with conditional based on returned results of past user ratings */ ) { |
121 | | - // add the stale star class to each on star |
122 | | - $( '.ui-stars-star-on' ) |
123 | | - .addClass( 'ui-stars-star-stale' ); |
124 | | - // add the stale message |
125 | | - $( '.article-assessment-submit' ) |
126 | | - .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) ); |
127 | | - } |
128 | 158 | // intialize the tooltips |
129 | 159 | $( '.field-wrapper label[original-title]' ).each(function() { |
130 | 160 | $( this ) |
— | — | @@ -131,38 +161,63 @@ |
132 | 162 | .attr( 'original-title', $( this ).attr( 'original-title' ) ) |
133 | 163 | .tipsy( { gravity : 'se', opacity: '0.9', } ) ); |
134 | 164 | } ); |
135 | | - // initialize the ratings |
136 | | - $( '.article-assessment-rating-field-value' ).each( function() { |
137 | | - $( this ) |
138 | | - .css( { |
139 | | - 'width': 120 - ( 120 * ( parseInt( $( this ).text() ) / 100 ) ) + "px" |
140 | | - } ) |
141 | | - } ); |
142 | 165 | // bind submit event to the form |
143 | | - |
| 166 | + $( '#article-assessment' ).submit( function() { $.ArticleAssessment.fn.submitRating(); return false; } ); |
144 | 167 | // prevent the submit button for being active until all ratings are filled out |
145 | 168 | |
146 | 169 | }, |
147 | 170 | 'getRatingData': function() { |
148 | | - var request = $j.ajax( { |
| 171 | + var request = $.ajax( { |
149 | 172 | url: wgScriptPath + '/api.php', |
150 | 173 | data: { |
151 | | - 'action': 'articleassessment', |
152 | | - 'getCumulativeResults': 1, |
153 | | - 'pageId': wgArticleId, |
154 | | - 'revId': wgCurRevisionId |
| 174 | + 'action': 'query', |
| 175 | + 'list': 'articleassessment', |
| 176 | + 'aarevid': wgCurRevisionId, |
| 177 | + 'aapageid': wgArticleId, |
| 178 | + 'format': 'json' |
155 | 179 | }, |
156 | 180 | dataType: 'json', |
157 | 181 | success: function( data ) { |
158 | | - console.log(data); |
| 182 | + $.ArticleAssessment.fn.afterGetRatingData( data ); |
159 | 183 | }, |
160 | 184 | error: function(XMLHttpRequest, textStatus, errorThrown) { |
161 | | - console.log(XMLHttpRequest, textStatus, errorThrown); |
| 185 | + // console.log(XMLHttpRequest, textStatus, errorThrown); |
162 | 186 | } |
163 | 187 | } ); |
164 | 188 | }, |
| 189 | + 'afterGetRatingData' : function( data ) { |
| 190 | + var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings; |
| 191 | + // add the correct data to the markup |
| 192 | + for( rating in data.query.articleassessment[0].ratings) { |
| 193 | + var rating = data.query.articleassessment[0].ratings[rating], |
| 194 | + $rating = $( '#' + rating.ratingdesc ), |
| 195 | + label = mw.usability.getMsg( 'articleassessment-noratings', [rating.total, rating.count] ); |
| 196 | + $rating |
| 197 | + .find( '.article-assessment-rating-field-value' ) |
| 198 | + .text( rating.total ) |
| 199 | + .end() |
| 200 | + .find( '.article-assessment-rating-count' ) |
| 201 | + .text( label ); |
| 202 | + } |
| 203 | + // if the rating is stale, add the stale class |
| 204 | + if( true /* replace with conditional based on returned results of past user ratings */ ) { |
| 205 | + // add the stale star class to each on star |
| 206 | + $( '.ui-stars-star-on' ) |
| 207 | + .addClass( 'ui-stars-star-stale' ); |
| 208 | + // add the stale message |
| 209 | + $( '.article-assessment-submit' ) |
| 210 | + .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) ); |
| 211 | + } |
| 212 | + // initialize the ratings |
| 213 | + $( '.article-assessment-rating-field-value' ).each( function() { |
| 214 | + $( this ) |
| 215 | + .css( { |
| 216 | + 'width': 120 - ( 120 * ( parseFloat( $( this ).text() ) / 5 ) ) + "px" |
| 217 | + } ) |
| 218 | + } ); |
| 219 | + }, |
165 | 220 | 'getUserRatingData': function() { |
166 | | - var request = $j.ajax( { |
| 221 | + var request = $.ajax( { |
167 | 222 | url: wgScriptPath + '/api.php', |
168 | 223 | data: { |
169 | 224 | 'action': 'articleassessment', |
— | — | @@ -176,21 +231,34 @@ |
177 | 232 | console.log(data); |
178 | 233 | }, |
179 | 234 | error: function(XMLHttpRequest, textStatus, errorThrown) { |
180 | | - console.log(XMLHttpRequest, textStatus, errorThrown); |
| 235 | + // console.log( XMLHttpRequest, textStatus, errorThrown ); |
181 | 236 | } |
182 | 237 | } ); |
183 | 238 | }, |
184 | | - 'submit': function() { |
| 239 | + 'submitRating': function() { |
185 | 240 | // clear out the stale message |
186 | | - var request = $j.ajax( { |
| 241 | + var results = {}; |
| 242 | + $( '.rating-field input' ).each( function() { |
| 243 | + // expects the hidden inputs to have names like 'rating[field-name]' which we use to |
| 244 | + // be transparent about what values we're sending to the server |
| 245 | + var fieldName = $( this ).attr('name').match(/\[([a-zA-Z0-9\-]*)\]/)[1]; |
| 246 | + results[ fieldName ] = $( this ).val(); |
| 247 | + } ); |
| 248 | + var request = $.ajax( { |
187 | 249 | url: wgScriptPath + '/api.php', |
188 | 250 | data: { |
189 | | - 'action': 'ratearticle', |
190 | | - 'data': ratingsData |
| 251 | + 'action': 'articleassessment', |
| 252 | + 'aarevid': wgCurRevisionId, |
| 253 | + 'aapageid': wgArticleId, |
| 254 | + 'aar1' : results['wellsourced'], |
| 255 | + 'aar2' : results['neutrality'], |
| 256 | + 'aar3' : results['completeness'], |
| 257 | + 'aar4' : results['readability'], |
| 258 | + 'format': 'json' |
191 | 259 | }, |
192 | 260 | dataType: 'json', |
193 | 261 | success: function( data ) { |
194 | | - $this.suggestions( 'suggestions', data[1] ); |
| 262 | + console.log(data); |
195 | 263 | } |
196 | 264 | } ); |
197 | 265 | } |
— | — | @@ -198,7 +266,6 @@ |
199 | 267 | }; |
200 | 268 | // FIXME - this should be moved out of here |
201 | 269 | $( document ).ready( function () { |
202 | | - console.log(this); |
203 | | - $.ArticleAssessment.fn.init( { 'endpoint': wgScriptPath + "/api.php" } ); |
| 270 | + $.ArticleAssessment.fn.init( ); |
204 | 271 | } ); //document ready |
205 | 272 | } )( jQuery ); |
\ No newline at end of file |