Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php |
— | — | @@ -127,10 +127,14 @@ |
128 | 128 | $stats['instructors'] = '<ul>'; |
129 | 129 | |
130 | 130 | foreach ( $instructors as /* EPInstructor */ $instructor ) { |
131 | | - $instructor->getUserLink() . $instructor->getToolLinks( $this->getContext() ); |
| 131 | + $stats['instructors'] .= |
| 132 | + '<li>' |
| 133 | + . $instructor->getUserLink() |
| 134 | + . $instructor->getToolLinks( $this->getContext(), $course ) |
| 135 | + . '</li>'; |
132 | 136 | } |
133 | 137 | |
134 | | - $stats['instructors'] = '</ul>'; |
| 138 | + $stats['instructors'] .= '</ul>'; |
135 | 139 | } |
136 | 140 | else { |
137 | 141 | $stats['instructors'] = wfMsgHtml( 'ep-course-no-instructors' ); |
Index: trunk/extensions/EducationProgram/includes/EPInstructor.php |
— | — | @@ -109,26 +109,30 @@ |
110 | 110 | * @since 0.1 |
111 | 111 | * |
112 | 112 | * @param IContextSource $context |
| 113 | + * @param EPCourse|null $course |
113 | 114 | * |
114 | 115 | * @return string |
115 | 116 | */ |
116 | | - public function getToolLinks( IContextSource $context ) { |
| 117 | + public function getToolLinks( IContextSource $context, EPCourse $course = null ) { |
117 | 118 | $links = array(); |
118 | 119 | |
119 | 120 | $items[] = Linker::userTalkLink( $this->getUser()->getId(), $this->getUser()->getName() ); |
120 | 121 | |
121 | 122 | $links[] = Linker::link( SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() ), wfMsgHtml( 'contribslink' ) ); |
122 | 123 | |
123 | | - if ( $context->getUser()->isAllowed( 'instructor' ) ) { |
| 124 | + if ( !is_null( $course ) && $context->getUser()->isAllowed( 'ep-instructor' ) ) { |
124 | 125 | $links[] = Html::element( |
125 | 126 | 'a', |
126 | 127 | array( |
127 | 128 | 'href' => '#', |
128 | 129 | 'class' => 'ep-instructor-remove', |
129 | | - 'data-id' => $this->getId() |
| 130 | + 'data-courseid' => $course->getId(), |
| 131 | + 'data-userid' => $this->getUser()->getId(), |
130 | 132 | ), |
131 | 133 | wfMsg( 'ep-instructor-remove' ) |
132 | 134 | ); |
| 135 | + |
| 136 | + $context->getOutput()->addModules( 'ep.instructor' ); |
133 | 137 | } |
134 | 138 | |
135 | 139 | return ' <span class="mw-usertoollinks">(' . $context->getLanguage()->pipeList( $links ) . ')</span>'; |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -346,6 +346,8 @@ |
347 | 347 | * @return array of EPInstructor |
348 | 348 | */ |
349 | 349 | public function getInstructors() { |
| 350 | + $this->setField( 'instructors', array( 1 ) ); |
| 351 | + |
350 | 352 | if ( $this->instructors === false ) { |
351 | 353 | $this->instructors = array(); |
352 | 354 | |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -359,6 +359,19 @@ |
360 | 360 | 'specialmycourses-summary-name' => 'Course name', |
361 | 361 | 'specialmycourses-summary-org' => 'Institution name', |
362 | 362 | 'ep-mycourses-not-a-student' => 'You are not enrolled in any [[Special:Courses|courses]].', |
| 363 | + |
| 364 | + // ep.instructor |
| 365 | + 'ep-instructor-remove-title' => 'Remove instructor from course', |
| 366 | + 'ep-instructor-remove-button' => 'Remove instructor', |
| 367 | + 'ep-instructor-removing' => 'Removing...', |
| 368 | + 'ep-instructor-removal-success' => 'This instructor has been successfully removed from this course.', |
| 369 | + 'ep-instructor-close-button' => 'Close', |
| 370 | + 'ep-instructor-remove-retry' => 'Retry', |
| 371 | + 'ep-instructor-remove-failed' => 'Something went wrong - could not remove the instructor from the course.', |
| 372 | + 'ep-instructor-cancel-button' => 'Cancel', |
| 373 | + |
| 374 | + // EPInstrucor |
| 375 | + 'ep-instructor-remove' => 'remove from course', |
363 | 376 | ); |
364 | 377 | |
365 | 378 | /** Message documentation (Message documentation) |
Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -322,6 +322,26 @@ |
323 | 323 | ), |
324 | 324 | ); |
325 | 325 | |
| 326 | +$wgResourceModules['ep.instructor'] = $moduleTemplate + array( |
| 327 | + 'scripts' => array( |
| 328 | + 'ep.instructor.js', |
| 329 | + ), |
| 330 | + 'dependencies' => array( |
| 331 | + 'jquery.ui.dialog', |
| 332 | + 'ep.api', |
| 333 | + ), |
| 334 | + 'messages' => array( |
| 335 | + 'ep-instructor-remove-title', |
| 336 | + 'ep-instructor-remove-button', |
| 337 | + 'ep-instructor-removing', |
| 338 | + 'ep-instructor-removal-success', |
| 339 | + 'ep-instructor-close-button', |
| 340 | + 'ep-instructor-remove-retry', |
| 341 | + 'ep-instructor-remove-failed', |
| 342 | + 'ep-instructor-cancel-button', |
| 343 | + ), |
| 344 | +); |
| 345 | + |
326 | 346 | unset( $moduleTemplate ); |
327 | 347 | |
328 | 348 | $egEPSettings = array(); |
Index: trunk/extensions/EducationProgram/resources/ep.api.js |
— | — | @@ -31,6 +31,31 @@ |
32 | 32 | } |
33 | 33 | ); |
34 | 34 | }; |
| 35 | + |
| 36 | + this.addInstructor = function( args ) { |
| 37 | + var requestArgs = $.extend( { |
| 38 | + 'action': 'addinstructor', |
| 39 | + 'format': 'json', |
| 40 | + 'token': window.mw.user.tokens.get( 'editToken' ) |
| 41 | + }, args ); |
| 42 | + |
| 43 | + var deferred = $.Deferred(); |
| 44 | + |
| 45 | + $.post( |
| 46 | + wgScriptPath + '/api.php', |
| 47 | + requestArgs, |
| 48 | + function( data ) { |
| 49 | + if ( data.hasOwnProperty( 'success' ) && data.success ) { |
| 50 | + deferred.resolve(); |
| 51 | + } |
| 52 | + else { |
| 53 | + deferred.reject(); |
| 54 | + } |
| 55 | + } |
| 56 | + ); |
| 57 | + |
| 58 | + return deferred.promise(); |
| 59 | + }; |
35 | 60 | |
36 | 61 | } ); |
37 | 62 | |
Index: trunk/extensions/EducationProgram/resources/ep.instructor.js |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Education Program MediaWiki extension. |
| 4 | + * @see https://www.mediawiki.org/wiki/Extension:Education_Program |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $, mw, ep ) { |
| 11 | + |
| 12 | + $( document ).ready( function() { |
| 13 | + |
| 14 | + $( '.ep-instructor-remove' ).click( function( event ) { |
| 15 | + var $this = $( this ), |
| 16 | + courseId = $this.attr( 'data-courseid' ), |
| 17 | + userId = $this.attr( 'data-userid' ), |
| 18 | + $dialog = null; |
| 19 | + |
| 20 | + $dialog = $( '<div />' ).html( '' ).dialog( { |
| 21 | + 'title': mw.msg( 'ep-instructor-remove-title' ), |
| 22 | + 'minWidth': 550, |
| 23 | + 'buttons': [ |
| 24 | + { |
| 25 | + 'text': mw.msg( 'ep-instructor-remove-button' ), |
| 26 | + 'id': 'instructor-remove-button', |
| 27 | + 'click': function() { |
| 28 | + var $remove = $( '#ep-instructor-remove-button' ); |
| 29 | + var $cancel = $( '#reminder-cancel-button' ); |
| 30 | + |
| 31 | + $remove.button( 'option', 'disabled', true ); |
| 32 | + $remove.button( 'option', 'label', mw.msg( 'ep-instructor-removing' ) ); |
| 33 | + |
| 34 | + ep.api.addInstructor( { |
| 35 | + 'courseid': courseId, |
| 36 | + 'userid': userId |
| 37 | + } ).done( function() { |
| 38 | + $dialog.text( mw.msg( 'ep-instructor-removal-success' ) ); |
| 39 | + $remove.remove(); |
| 40 | + $cancel.button( 'option', 'label', mw.msg( 'ep-instructor-close-button' ) ); |
| 41 | + } ).fail( function() { |
| 42 | + $remove.button( 'option', 'label', mw.msg( 'ep-instructor-remove-retry' ) ); |
| 43 | + $remove.button( 'option', 'disabled', false ); |
| 44 | + alert( mw.msg( 'ep-instructor-remove-failed' ) ); |
| 45 | + } ); |
| 46 | + } |
| 47 | + }, |
| 48 | + { |
| 49 | + 'text': mw.msg( 'ep-instructor-cancel-button' ), |
| 50 | + 'id': 'instructor-cancel-button', |
| 51 | + 'click': function() { |
| 52 | + $dialog.dialog( 'close' ); |
| 53 | + } |
| 54 | + } |
| 55 | + ] |
| 56 | + } ); |
| 57 | + |
| 58 | + // TODO: input to provide reason/comment for log |
| 59 | + } ); |
| 60 | + |
| 61 | + } ); |
| 62 | + |
| 63 | +})( window.jQuery, window.mediaWiki, window.educationProgram ); |
\ No newline at end of file |
Property changes on: trunk/extensions/EducationProgram/resources/ep.instructor.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |