Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -552,6 +552,9 @@ |
553 | 553 | 'ep-instructor-addittion-self-success', |
554 | 554 | 'ep-online-addittion-self-success', |
555 | 555 | 'ep-campus-addittion-self-success', |
| 556 | + 'ep-instructor-addittion-null', |
| 557 | + 'ep-online-addittion-null', |
| 558 | + 'ep-campus-addittion-null', |
556 | 559 | 'ep-instructor-add-close-button', |
557 | 560 | 'ep-online-add-close-button', |
558 | 561 | 'ep-campus-add-close-button', |
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php |
— | — | @@ -172,7 +172,7 @@ |
173 | 173 | 'student', |
174 | 174 | true, |
175 | 175 | $revAction |
176 | | - ); |
| 176 | + ) !== false; |
177 | 177 | |
178 | 178 | if ( $success ) { |
179 | 179 | $this->showSuccess( wfMessage( 'ep-disenroll-success' ) ); |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -149,7 +149,7 @@ |
150 | 150 | foreach ( $courses as /* EPCourse */ $course ) { |
151 | 151 | $courseIds[] = $course->getId(); |
152 | 152 | $course->setUpdateSummaries( false ); |
153 | | - $success = $course->enlistUsers( $this->getField( 'user_id' ), $this->getRoleName() ) && $success; |
| 153 | + $success = $course->enlistUsers( $this->getField( 'user_id' ), $this->getRoleName() ) !== false && $success; |
154 | 154 | $course->setUpdateSummaries( true ); |
155 | 155 | } |
156 | 156 | |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -565,7 +565,7 @@ |
566 | 566 | * @param boolean $save |
567 | 567 | * @param EPRevisionAction|null $revAction |
568 | 568 | * |
569 | | - * @return boolean Success indicator |
| 569 | + * @return integer|false The amount of enlisted users or false on failiure |
570 | 570 | */ |
571 | 571 | public function enlistUsers( $newUsers, $role, $save = true, EPRevisionAction $revAction = null ) { |
572 | 572 | $roleMap = array( |
— | — | @@ -595,10 +595,10 @@ |
596 | 596 | $this->logRoleChange( $action, $role, $addedUsers, $revAction->getComment() ); |
597 | 597 | } |
598 | 598 | |
599 | | - return $success; |
| 599 | + return $success ? count( $addedUsers ) : false; |
600 | 600 | } |
601 | 601 | else { |
602 | | - return true; |
| 602 | + return 0; |
603 | 603 | } |
604 | 604 | } |
605 | 605 | |
— | — | @@ -614,7 +614,7 @@ |
615 | 615 | * @param boolean $save |
616 | 616 | * @param EPRevisionAction|null $revAction |
617 | 617 | * |
618 | | - * @return boolean Success indicator |
| 618 | + * @return integer|false The amount of unenlisted users or false on failiure |
619 | 619 | */ |
620 | 620 | public function unenlistUsers( $sadUsers, $role, $save = true, EPRevisionAction $revAction = null ) { |
621 | 621 | $sadUsers = (array)$sadUsers; |
— | — | @@ -656,10 +656,10 @@ |
657 | 657 | $this->logRoleChange( $action, $role, $removedUsers, $revAction->getComment() ); |
658 | 658 | } |
659 | 659 | |
660 | | - return $success; |
| 660 | + return $success ? count( $removedUsers ) : false; |
661 | 661 | } |
662 | 662 | else { |
663 | | - return true; |
| 663 | + return 0; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -626,6 +626,7 @@ |
627 | 627 | 'ep-instructor-adding' => 'Adding...', |
628 | 628 | 'ep-instructor-addittion-success' => '$1 has been successfully added as {{GENDER:$1|instructor}} for course $2!', |
629 | 629 | 'ep-instructor-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|instructor}} for course $2!', |
| 630 | + 'ep-instructor-addittion-null' => '$1 has already been added as {{GENDER:$1|instructor}} to course $2', |
630 | 631 | 'ep-instructor-add-close-button' => 'Close', |
631 | 632 | 'ep-instructor-add-retry' => 'Retry', |
632 | 633 | 'ep-instructor-addittion-failed' => 'Something went wrong - could not add the instructor to the course.', |
— | — | @@ -652,6 +653,7 @@ |
653 | 654 | 'ep-online-adding' => 'Adding...', |
654 | 655 | 'ep-online-addittion-success' => '$1 has been successfully added as {{GENDER:$1|Online Ambassador}} for course $2!', |
655 | 656 | 'ep-online-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|Online Ambassador}} for course $2!', |
| 657 | + 'ep-online-addittion-null' => '$1 has already been added as {{GENDER:$1|Online Ambassador}} to course $2', |
656 | 658 | 'ep-online-add-close-button' => 'Close', |
657 | 659 | 'ep-online-add-retry' => 'Retry', |
658 | 660 | 'ep-online-addittion-failed' => 'Something went wrong - could not add the Online Ambassador to the course.', |
— | — | @@ -678,6 +680,7 @@ |
679 | 681 | 'ep-campus-adding' => 'Adding...', |
680 | 682 | 'ep-campus-addittion-success' => '$1 has been successfully added as {{GENDER:$1|Campus Ambassador}} for course $2!', |
681 | 683 | 'ep-campus-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|Campus Ambassador}} for course $2!', |
| 684 | + 'ep-campus-addittion-null' => '$1 has already been added as {{GENDER:$1|Campus Ambassador}} to course $2', |
682 | 685 | 'ep-campus-add-close-button' => 'Close', |
683 | 686 | 'ep-campus-add-retry' => 'Retry', |
684 | 687 | 'ep-campus-addittion-failed' => 'Something went wrong - could not add the Campus Ambassador to the course.', |
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php |
— | — | @@ -52,26 +52,32 @@ |
53 | 53 | $this->dieUsage( wfMsg( 'ep-enlist-invalid-course' ), 'invalid-course' ); |
54 | 54 | } |
55 | 55 | |
56 | | - $success = false; |
57 | | - |
58 | 56 | $revAction = new EPRevisionAction(); |
59 | 57 | $revAction->setUser( $this->getUser() ); |
60 | 58 | $revAction->setComment( $params['reason'] ); |
61 | 59 | |
62 | 60 | switch ( $params['subaction'] ) { |
63 | 61 | case 'add': |
64 | | - $success = $course->enlistUsers( array( $userId ), $params['role'], true, $revAction ); |
| 62 | + $enlistmentResult = $course->enlistUsers( array( $userId ), $params['role'], true, $revAction ); |
65 | 63 | break; |
66 | 64 | case 'remove': |
67 | | - $success = $course->unenlistUsers( array( $userId ), $params['role'], true, $revAction ); |
| 65 | + $enlistmentResult = $course->unenlistUsers( array( $userId ), $params['role'], true, $revAction ); |
68 | 66 | break; |
69 | 67 | } |
70 | 68 | |
71 | 69 | $this->getResult()->addValue( |
72 | 70 | null, |
73 | 71 | 'success', |
74 | | - $success |
| 72 | + $success = $enlistmentResult !== false |
75 | 73 | ); |
| 74 | + |
| 75 | + if ( $enlistmentResult !== false ) { |
| 76 | + $this->getResult()->addValue( |
| 77 | + null, |
| 78 | + 'count', |
| 79 | + $enlistmentResult |
| 80 | + ); |
| 81 | + } |
76 | 82 | } |
77 | 83 | |
78 | 84 | /** |
Index: trunk/extensions/EducationProgram/resources/ep.api.js |
— | — | @@ -24,10 +24,10 @@ |
25 | 25 | requestArgs, |
26 | 26 | function( data ) { |
27 | 27 | if ( data.hasOwnProperty( 'success' ) && data.success ) { |
28 | | - deferred.resolve(); |
| 28 | + deferred.resolve( data ); |
29 | 29 | } |
30 | 30 | else { |
31 | | - deferred.reject(); |
| 31 | + deferred.reject( data ); |
32 | 32 | } |
33 | 33 | } |
34 | 34 | ); |
Index: trunk/extensions/EducationProgram/resources/ep.enlist.js |
— | — | @@ -136,8 +136,8 @@ |
137 | 137 | }; |
138 | 138 | |
139 | 139 | this.doAdd = function() { |
140 | | - var $add = $( '#ep-' + role + '-add-button' ); |
141 | | - var $cancel = $( '#ep-' + role + '-add-cancel-button' ); |
| 140 | + var $add = $( '#ep-' + role + '-add-button' ), |
| 141 | + $cancel = $( '#ep-' + role + '-add-cancel-button' ); |
142 | 142 | |
143 | 143 | $add.button( 'option', 'disabled', true ); |
144 | 144 | $add.button( 'option', 'label', ep.msg( 'ep-' + role + '-adding' ) ); |
— | — | @@ -147,9 +147,18 @@ |
148 | 148 | 'username': _this.getName(), |
149 | 149 | 'reason': _this.summaryInput.val(), |
150 | 150 | 'role': role |
151 | | - } ).done( function() { |
| 151 | + } ).done( function( data ) { |
| 152 | + var messageKey = null; |
| 153 | + |
| 154 | + if ( data.count === 0 ) { |
| 155 | + messageKey = 'ep-' + role + '-addittion-null'; |
| 156 | + } |
| 157 | + else { |
| 158 | + messageKey = this.selfMode ? 'ep-' + role + '-addittion-self-success' : 'ep-' + role + '-addittion-success'; |
| 159 | + } |
| 160 | + |
152 | 161 | _this.$dialog.text( ep.msg( |
153 | | - _this.selfMode ? 'ep-' + role + '-addittion-self-success' : 'ep-' + role + '-addittion-success', |
| 162 | + messageKey, |
154 | 163 | _this.getName(), |
155 | 164 | _this.courseName |
156 | 165 | ) ); |
— | — | @@ -158,16 +167,18 @@ |
159 | 168 | $cancel.button( 'option', 'label', ep.msg( 'ep-' + role + '-add-close-button' ) ); |
160 | 169 | $cancel.focus(); |
161 | 170 | |
162 | | - // TODO: link name to user page and show control links |
163 | | - $ul = $( '#ep-course-' + role ).find( 'ul' ); |
| 171 | + if ( data.count > 0 ) { |
| 172 | + // TODO: link name to user page and show control links |
| 173 | + $ul = $( '#ep-course-' + role ).find( 'ul' ); |
164 | 174 | |
165 | | - if ( $ul.length < 1 ) { |
166 | | - $ul = $( '<ul>' ); |
167 | | - $( '#ep-course-' + role ).html( $ul ); |
| 175 | + if ( $ul.length < 1 ) { |
| 176 | + $ul = $( '<ul>' ); |
| 177 | + $( '#ep-course-' + role ).html( $ul ); |
| 178 | + } |
| 179 | + |
| 180 | + $ul.append( $( '<li>' ).text( _this.getName() ) ); |
168 | 181 | } |
169 | | - |
170 | | - $ul.append( $( '<li>' ).text( _this.getName() ) ) |
171 | | - } ).fail( function() { |
| 182 | + } ).fail( function( data ) { |
172 | 183 | // TODO: implement nicer handling for fails caused by invalid user name |
173 | 184 | |
174 | 185 | $add.button( 'option', 'disabled', false ); |