r85569 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85568‎ | r85569 | r85570 >
Date:20:08, 6 April 2011
Author:kaldari
Status:deferred
Tags:
Comment:
refactor feedback code
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -1207,6 +1207,34 @@
12081208 launchFeedback: function() {
12091209 _this = this;
12101210
 1211+ var displayError = function( message ) {
 1212+ $('#mwe-upwiz-feedback-form div').hide(); // remove everything else from the dialog box
 1213+ $('#mwe-upwiz-feedback-form').append ( $('<div style="color:#990000;margin-top:0.4em;"></div>').msg( message ) );
 1214+ }
 1215+
 1216+ var useTokenToPostFeedback = function( token ) {
 1217+ $.ajax({
 1218+ url: wgScriptPath + '/api.php?',
 1219+ data: 'action=edit&title='+encodeURIComponent(mw.UploadWizard.config['feedbackPage'])+'&section=new&summary='+encodeURIComponent(subject)+'&text='+encodeURIComponent(message)+'&format=json&token='+encodeURIComponent(token),
 1220+ dataType: 'json',
 1221+ type: 'POST',
 1222+ success: function( data ) {
 1223+ if ( typeof data.edit != 'undefined' ) {
 1224+ if ( data.edit.result == "Success" ) {
 1225+ $feedbackForm.dialog("close"); // edit complete, close dialog box
 1226+ } else {
 1227+ displayError( 'mwe-upwiz-feedback-error1' ); // unknown API result
 1228+ }
 1229+ } else {
 1230+ displayError( 'mwe-upwiz-feedback-error2' ); // edit failed
 1231+ }
 1232+ },
 1233+ error: function( xhr ) {
 1234+ displayError( 'mwe-upwiz-feedback-error3' ); // ajax request failed
 1235+ }
 1236+ }); // close Ajax request
 1237+ }; // close useTokenToPost function
 1238+
12111239 // Set up buttons for dialog box. We have to do it the hard way since the json keys are localized
12121240 var cancelButton = gM( 'mwe-upwiz-feedback-cancel' );
12131241 var submitButton = gM( 'mwe-upwiz-feedback-submit' );
@@ -1221,36 +1249,9 @@
12221250 if ( message.indexOf('~~~~') == -1 ) {
12231251 message = message+' ~~~~';
12241252 }
1225 - var useTokenToPost = function( token ) {
1226 - $.ajax({
1227 - url: wgScriptPath + '/api.php?',
1228 - data: 'action=edit&title='+encodeURIComponent(mw.UploadWizard.config['feedbackPage'])+'&section=new&summary='+encodeURIComponent(subject)+'&text='+encodeURIComponent(message)+'&format=json&token='+encodeURIComponent(token),
1229 - dataType: 'json',
1230 - type: 'POST',
1231 - success: function( data ) {
1232 - if ( typeof data.edit != 'undefined' ) {
1233 - if ( data.edit.result == "Success" ) {
1234 - $feedbackForm.dialog("close");
1235 - } else {
1236 - displayError( 'mwe-upwiz-feedback-error1' );
1237 - }
1238 - } else {
1239 - displayError( 'mwe-upwiz-feedback-error2' );
1240 - }
1241 - },
1242 - error: function( xhr ) {
1243 - displayError( 'mwe-upwiz-feedback-error3' );
1244 - }
1245 - }); // close Ajax request
1246 - }; // close useTokenToPost function
1247 - _this.api.getEditToken( useTokenToPost );
 1253+ _this.api.getEditToken( useTokenToPostFeedback );
12481254 }; // close submit button function
12491255
1250 - var displayError = function( message ) {
1251 - $('#mwe-upwiz-feedback-form div').hide(); // remove everything else from the dialog box
1252 - $('#mwe-upwiz-feedback-form').append ( $('<div style="color:#990000;margin-top:0.4em;"></div>').msg( message ) );
1253 - }
1254 -
12551256 // Construct the feedback form
12561257 var feedbackLink = '<a href="'+wgArticlePath.replace( '$1', mw.UploadWizard.config['feedbackPage'].replace( /\s/g, '_' ) )+'" target="_blank">'+mw.UploadWizard.config['feedbackPage']+'</a>';
12571258 $feedbackForm = $('<div id="mwe-upwiz-feedback-form" style="position:relative;"></div>')

Status & tagging log