r110788 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110787‎ | r110788 | r110789 >
Date:21:35, 6 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
make use of deferred pattern for deletion action
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.pager.js (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -277,11 +277,11 @@
278278 'ep-course-edit-token' => 'Enrollment token',
279279 'ep-course-edit-description' => 'Description',
280280 'ep-course-edit-name-format' => '$1 ($2)',
281 - 'ep-course-edit-name' => 'Name',
 281+ 'ep-course-edit-name' => 'Page title',
282282 'ep-course-edit-field' => 'Field of study',
283283 'ep-course-edit-level' => 'Course level',
284284 'ep-course-edit-term' => 'Academic term',
285 - 'ep-course-edit-mc' => 'Master course',
 285+ 'ep-course-edit-mc' => 'Course name',
286286 'ep-course-edit-lang' => 'Course language',
287287 'ep-addcourse' => 'There is no course with this name yet, but you can add it.',
288288 'ep-editcourse' => 'You are editing an existing course.',
Index: trunk/extensions/EducationProgram/resources/ep.js
@@ -10,7 +10,7 @@
1111
1212 var compatMode = undefined;
1313
14 - var ep = {
 14+ var ep = {
1515 msg: function () {
1616 // Yeah, doing it here, since "mw.loader.using( 'mediawiki.language',"
1717 // does not have mediaWiki.language loaded.
@@ -56,7 +56,7 @@
5757 msge: function () {
5858 return mw.html.escape( this.msg.apply( this, arguments ) );
5959 }
60 - }
 60+ };
6161
6262 mw.educationProgram = ep;
6363
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -45,26 +45,31 @@
4646 return this.enlist( args );
4747 },
4848
49 - remove: function( data, callback ) {
50 - var requestArgs = {
 49+ remove: function( data, args ) {
 50+ var requestArgs = $.extend( {
5151 'action': 'deleteeducation',
5252 'format': 'json',
5353 'token': window.mw.user.tokens.get( 'editToken' ),
5454 'ids': data.ids.join( '|' ),
5555 'type': data.type
56 - };
 56+ }, args );
 57+
 58+ var deferred = $.Deferred();
5759
5860 $.post(
5961 wgScriptPath + '/api.php',
6062 requestArgs,
6163 function( data ) {
62 - var success = data.hasOwnProperty( 'success' ) && data.success;
63 -
64 - callback( {
65 - 'success': success
66 - } );
 64+ if ( data.hasOwnProperty( 'success' ) && data.success ) {
 65+ deferred.resolve();
 66+ }
 67+ else {
 68+ deferred.reject();
 69+ }
6770 }
6871 );
 72+
 73+ return deferred.promise();
6974 }
7075
7176 };
Index: trunk/extensions/EducationProgram/resources/ep.pager.js
@@ -23,32 +23,26 @@
2424 if ( confirm( mw.msg( 'ep-pager-confirm-delete' ) ) ) {
2525 var $this = $( this );
2626
27 - ep.api.remove(
28 - {
29 - 'type': $this.attr( 'data-type' ),
30 - 'ids': [ $this.attr( 'data-id' ) ]
31 - },
32 - function ( result ) {
33 - if ( result.success ) {
34 - var $tr = $this.closest( 'tr' );
35 - var $table = $tr.closest( 'table' );
 27+ ep.api.remove( {
 28+ 'type': $this.attr( 'data-type' ),
 29+ 'ids': [ $this.attr( 'data-id' ) ]
 30+ } ).done( function() {
 31+ var $tr = $this.closest( 'tr' );
 32+ var $table = $tr.closest( 'table' );
3633
37 - if ( $table.find( 'tr' ).length > 2 ) {
38 - $tr.slideUp( 'slow', function () {
39 - $tr.remove();
40 - } );
41 - }
42 - else {
43 - $table.slideUp( 'slow', function () {
44 - $table.remove();
45 - } );
46 - }
47 - }
48 - else {
49 - alert( mw.msg( 'ep-pager-delete-fail' ) );
50 - }
 34+ if ( $table.find( 'tr' ).length > 2 ) {
 35+ $tr.slideUp( 'slow', function () {
 36+ $tr.remove();
 37+ } );
5138 }
52 - );
 39+ else {
 40+ $table.slideUp( 'slow', function () {
 41+ $table.remove();
 42+ } );
 43+ }
 44+ } ).fail( function() {
 45+ alert( mw.msg( 'ep-pager-delete-fail' ) );
 46+ } );
5347 }
5448 } );
5549
@@ -73,32 +67,26 @@
7468
7569 var pagerId = $( this ).attr( 'data-pager-id' );
7670
77 - ep.api.remove(
78 - {
79 - 'type': $( this ).attr( 'data-type' ),
80 - 'ids': ids
81 - },
82 - function ( result ) {
83 - if ( result.success ) {
84 - if ( ids.length > 0 && ( $table.find( 'tr' ).length - ids.length > 1 ) ) {
85 - for ( i in ids ) {
86 - if ( ids.hasOwnProperty( i ) ) {
87 - $( '#select-' + pagerId + '-' + ids[i] ).closest( 'tr' ).remove();
88 - }
89 - }
 71+ ep.api.remove( {
 72+ 'type': $( this ).attr( 'data-type' ),
 73+ 'ids': ids
 74+ } ).done( function() {
 75+ if ( ids.length > 0 && ( $table.find( 'tr' ).length - ids.length > 1 ) ) {
 76+ for ( i in ids ) {
 77+ if ( ids.hasOwnProperty( i ) ) {
 78+ $( '#select-' + pagerId + '-' + ids[i] ).closest( 'tr' ).remove();
9079 }
91 - else {
92 - $table.slideUp( 'slow', function () {
93 - $table.remove();
94 - $deleteButton.closest( 'fieldset' ).remove();
95 - } );
96 - }
9780 }
98 - else {
99 - alert( window.gM( 'ep-pager-delete-selected-fail', ids.length ) );
100 - }
10181 }
102 - );
 82+ else {
 83+ $table.slideUp( 'slow', function () {
 84+ $table.remove();
 85+ $deleteButton.closest( 'fieldset' ).remove();
 86+ } );
 87+ }
 88+ } ).fail( function() {
 89+ alert( window.gM( 'ep-pager-delete-selected-fail', ids.length ) );
 90+ } );
10391 } );
10492
10593 } );

Status & tagging log