r109190 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109189‎ | r109190 | r109191 >
Date:19:32, 17 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
finish up on base instructor management functionality
Modified paths:
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.instructor.js (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -157,7 +157,17 @@
158158 return wfMsgHtml( 'ep-course-no-instructors' );
159159 }
160160 }
161 -
 161+
 162+ /**
 163+ * Returns instructor addition controls for the course if the
 164+ * current user has the right permissions.
 165+ *
 166+ * @since 0.1
 167+ *
 168+ * @param EPCourse $course
 169+ *
 170+ * @return string
 171+ */
162172 protected function getInstructorControls( EPCourse $course ) {
163173 $user = $this->getUser();
164174 $links = array();
Index: trunk/extensions/EducationProgram/resources/ep.instructor.js
@@ -109,20 +109,28 @@
110110 'maxlength': 250,
111111 'id': 'ep-instructor-summaryinput'
112112 } );
113 -
 113+
 114+ this.getName = function() {
 115+ return this.selfMode ? mw.user.name : this.nameInput.val();
 116+ };
 117+
114118 this.doAdd = function() {
115119 var $add = $( '#ep-instructor-add-button' );
116120 var $cancel = $( '#ep-instructor-add-cancel-button' );
117121
118 - $remove.button( 'option', 'disabled', true );
119 - $remove.button( 'option', 'label', ep.msg( 'ep-instructor-adding' ) );
 122+ $add.button( 'option', 'disabled', true );
 123+ $add.button( 'option', 'label', ep.msg( 'ep-instructor-adding' ) );
120124
121 - ep.api.removeInstructor( {
 125+ ep.api.addInstructor( {
122126 'courseid': this.courseId,
123 - 'userid': this.userId,
 127+ 'username': this.getName(),
124128 'reason': this.summaryInput.val()
125129 } ).done( function() {
126 - _this.$dialog.text( ep.msg( _this.selfMode ? 'ep-instructor-addittion-self-success' : 'ep-instructor-addittion-success', this.getName() ) );
 130+ _this.$dialog.text( ep.msg(
 131+ _this.selfMode ? 'ep-instructor-addittion-self-success' : 'ep-instructor-addittion-success',
 132+ _this.getName(),
 133+ _this.courseName
 134+ ) );
127135 $add.remove();
128136 $cancel.button( 'option', 'label', ep.msg( 'ep-instructor-add-close-button' ) );
129137 $cancel.focus();
@@ -132,11 +140,7 @@
133141 alert( ep.msg( 'ep-instructor-addittion-failed' ) );
134142 } );
135143 };
136 -
137 - this.getName = function() {
138 - return this.selfMode ? mw.user.name : this.nameInput.val();
139 - };
140 -
 144+
141145 this.$dialog = $( '<div>' ).html( '' ).dialog( {
142146 'title': ep.msg( this.selfMode ? 'ep-instructor-add-self-title' : 'ep-instructor-add-title', this.getName() ),
143147 'minWidth': 550,
@@ -187,7 +191,7 @@
188192 var enterHandler = function( event ) {
189193 if ( event.which == '13' ) {
190194 event.preventDefault();
191 - this.doAdd();
 195+ _this.doAdd();
192196 }
193197 };
194198
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -8,26 +8,65 @@
99
1010 ( function ( $, mw ) {
1111
12 - mw.educationProgram.remove = function( data, callback ) {
13 - var requestArgs = {
14 - 'action': 'deleteeducation',
15 - 'format': 'json',
16 - 'token': window.mw.user.tokens.get( 'editToken' ),
17 - 'ids': data.ids.join( '|' ),
18 - 'type': data.type
19 - };
 12+ mw.educationProgram.api = {
2013
21 - $.post(
22 - wgScriptPath + '/api.php',
23 - requestArgs,
24 - function( data ) {
25 - var success = data.hasOwnProperty( 'success' ) && data.success;
 14+ instructor: function( args ) {
 15+ var requestArgs = $.extend( {
 16+ 'action': 'instructor',
 17+ 'format': 'json',
 18+ 'token': window.mw.user.tokens.get( 'editToken' )
 19+ }, args );
2620
27 - callback( {
28 - 'success': success
29 - } );
30 - }
31 - );
 21+ var deferred = $.Deferred();
 22+
 23+ $.post(
 24+ wgScriptPath + '/api.php',
 25+ requestArgs,
 26+ function( data ) {
 27+ if ( data.hasOwnProperty( 'success' ) && data.success ) {
 28+ deferred.resolve();
 29+ }
 30+ else {
 31+ deferred.reject();
 32+ }
 33+ }
 34+ );
 35+
 36+ return deferred.promise();
 37+ },
 38+
 39+ addInstructor: function( args ) {
 40+ args.subaction = 'add';
 41+ return this.instructor( args );
 42+ },
 43+
 44+ removeInstructor: function( args ) {
 45+ args.subaction = 'remove';
 46+ return this.instructor( args );
 47+ },
 48+
 49+ remove: function( data, callback ) {
 50+ var requestArgs = {
 51+ 'action': 'deleteeducation',
 52+ 'format': 'json',
 53+ 'token': window.mw.user.tokens.get( 'editToken' ),
 54+ 'ids': data.ids.join( '|' ),
 55+ 'type': data.type
 56+ };
 57+
 58+ $.post(
 59+ wgScriptPath + '/api.php',
 60+ requestArgs,
 61+ function( data ) {
 62+ var success = data.hasOwnProperty( 'success' ) && data.success;
 63+
 64+ callback( {
 65+ 'success': success
 66+ } );
 67+ }
 68+ );
 69+ }
 70+
3271 };
3372
3473 }( jQuery, mediaWiki ) );

Status & tagging log