r109015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109014‎ | r109015 | r109016 >
Date:00:55, 16 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on ui stuff to remove instructors from courses
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPInstructor.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.instructor.js (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -127,10 +127,14 @@
128128 $stats['instructors'] = '<ul>';
129129
130130 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>';
132136 }
133137
134 - $stats['instructors'] = '</ul>';
 138+ $stats['instructors'] .= '</ul>';
135139 }
136140 else {
137141 $stats['instructors'] = wfMsgHtml( 'ep-course-no-instructors' );
Index: trunk/extensions/EducationProgram/includes/EPInstructor.php
@@ -109,26 +109,30 @@
110110 * @since 0.1
111111 *
112112 * @param IContextSource $context
 113+ * @param EPCourse|null $course
113114 *
114115 * @return string
115116 */
116 - public function getToolLinks( IContextSource $context ) {
 117+ public function getToolLinks( IContextSource $context, EPCourse $course = null ) {
117118 $links = array();
118119
119120 $items[] = Linker::userTalkLink( $this->getUser()->getId(), $this->getUser()->getName() );
120121
121122 $links[] = Linker::link( SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() ), wfMsgHtml( 'contribslink' ) );
122123
123 - if ( $context->getUser()->isAllowed( 'instructor' ) ) {
 124+ if ( !is_null( $course ) && $context->getUser()->isAllowed( 'ep-instructor' ) ) {
124125 $links[] = Html::element(
125126 'a',
126127 array(
127128 'href' => '#',
128129 'class' => 'ep-instructor-remove',
129 - 'data-id' => $this->getId()
 130+ 'data-courseid' => $course->getId(),
 131+ 'data-userid' => $this->getUser()->getId(),
130132 ),
131133 wfMsg( 'ep-instructor-remove' )
132134 );
 135+
 136+ $context->getOutput()->addModules( 'ep.instructor' );
133137 }
134138
135139 return ' <span class="mw-usertoollinks">(' . $context->getLanguage()->pipeList( $links ) . ')</span>';
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -346,6 +346,8 @@
347347 * @return array of EPInstructor
348348 */
349349 public function getInstructors() {
 350+ $this->setField( 'instructors', array( 1 ) );
 351+
350352 if ( $this->instructors === false ) {
351353 $this->instructors = array();
352354
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -359,6 +359,19 @@
360360 'specialmycourses-summary-name' => 'Course name',
361361 'specialmycourses-summary-org' => 'Institution name',
362362 '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',
363376 );
364377
365378 /** Message documentation (Message documentation)
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -322,6 +322,26 @@
323323 ),
324324 );
325325
 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+
326346 unset( $moduleTemplate );
327347
328348 $egEPSettings = array();
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -31,6 +31,31 @@
3232 }
3333 );
3434 };
 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+ };
3560
3661 } );
3762
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
164 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r109016follow up to r109015 for commenting out debug line and also fixed var name failjeroendedauw00:59, 16 January 2012

Status & tagging log