Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php |
— | — | @@ -157,7 +157,17 @@ |
158 | 158 | return wfMsgHtml( 'ep-course-no-instructors' ); |
159 | 159 | } |
160 | 160 | } |
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 | + */ |
162 | 172 | protected function getInstructorControls( EPCourse $course ) { |
163 | 173 | $user = $this->getUser(); |
164 | 174 | $links = array(); |
Index: trunk/extensions/EducationProgram/resources/ep.instructor.js |
— | — | @@ -109,20 +109,28 @@ |
110 | 110 | 'maxlength': 250, |
111 | 111 | 'id': 'ep-instructor-summaryinput' |
112 | 112 | } ); |
113 | | - |
| 113 | + |
| 114 | + this.getName = function() { |
| 115 | + return this.selfMode ? mw.user.name : this.nameInput.val(); |
| 116 | + }; |
| 117 | + |
114 | 118 | this.doAdd = function() { |
115 | 119 | var $add = $( '#ep-instructor-add-button' ); |
116 | 120 | var $cancel = $( '#ep-instructor-add-cancel-button' ); |
117 | 121 | |
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' ) ); |
120 | 124 | |
121 | | - ep.api.removeInstructor( { |
| 125 | + ep.api.addInstructor( { |
122 | 126 | 'courseid': this.courseId, |
123 | | - 'userid': this.userId, |
| 127 | + 'username': this.getName(), |
124 | 128 | 'reason': this.summaryInput.val() |
125 | 129 | } ).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 | + ) ); |
127 | 135 | $add.remove(); |
128 | 136 | $cancel.button( 'option', 'label', ep.msg( 'ep-instructor-add-close-button' ) ); |
129 | 137 | $cancel.focus(); |
— | — | @@ -132,11 +140,7 @@ |
133 | 141 | alert( ep.msg( 'ep-instructor-addittion-failed' ) ); |
134 | 142 | } ); |
135 | 143 | }; |
136 | | - |
137 | | - this.getName = function() { |
138 | | - return this.selfMode ? mw.user.name : this.nameInput.val(); |
139 | | - }; |
140 | | - |
| 144 | + |
141 | 145 | this.$dialog = $( '<div>' ).html( '' ).dialog( { |
142 | 146 | 'title': ep.msg( this.selfMode ? 'ep-instructor-add-self-title' : 'ep-instructor-add-title', this.getName() ), |
143 | 147 | 'minWidth': 550, |
— | — | @@ -187,7 +191,7 @@ |
188 | 192 | var enterHandler = function( event ) { |
189 | 193 | if ( event.which == '13' ) { |
190 | 194 | event.preventDefault(); |
191 | | - this.doAdd(); |
| 195 | + _this.doAdd(); |
192 | 196 | } |
193 | 197 | }; |
194 | 198 | |
Index: trunk/extensions/EducationProgram/resources/ep.api.js |
— | — | @@ -8,26 +8,65 @@ |
9 | 9 | |
10 | 10 | ( function ( $, mw ) { |
11 | 11 | |
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 = { |
20 | 13 | |
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 ); |
26 | 20 | |
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 | + |
32 | 71 | }; |
33 | 72 | |
34 | 73 | }( jQuery, mediaWiki ) ); |