Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -93,6 +93,7 @@ |
94 | 94 | $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php'; |
95 | 95 | $wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php'; |
96 | 96 | $wgAutoloadClasses['EPPageObject'] = dirname( __FILE__ ) . '/includes/EPPageObject.php'; |
| 97 | +$wgAutoloadClasses['EPFailForm'] = dirname( __FILE__ ) . '/includes/EPFailForm.php'; |
97 | 98 | |
98 | 99 | $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php'; |
99 | 100 | $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php'; |
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php |
— | — | @@ -26,28 +26,7 @@ |
27 | 27 | $this->displayNavigation(); |
28 | 28 | |
29 | 29 | if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
30 | | - $out->addWikiMsg( 'ep-course-create', $name ); |
31 | | - |
32 | | - $bracketPos = strpos( $name, '(' ); |
33 | | - |
34 | | - if ( $bracketPos !== false ) { |
35 | | - if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) { |
36 | | - $bracketPos -= 1; |
37 | | - } |
38 | | - |
39 | | - $newName = substr( $name, 0, $bracketPos ); |
40 | | - } |
41 | | - |
42 | | - EPCourse::displayAddNewRegion( |
43 | | - $this->getContext(), |
44 | | - array( |
45 | | - 'name' => $this->getRequest()->getText( |
46 | | - 'newname', |
47 | | - $newName |
48 | | - ), |
49 | | - 'term' => $this->getRequest()->getText( 'newterm', '' ), |
50 | | - ) |
51 | | - ); |
| 30 | + $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) ); |
52 | 31 | } |
53 | 32 | else { |
54 | 33 | $out->addWikiMsg( 'ep-course-none', $name ); |
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php |
— | — | @@ -14,7 +14,36 @@ |
15 | 15 | public function onView() { |
16 | 16 | $this->getOutput()->addModules( array( 'ep.datepicker', 'ep.combobox' ) ); |
17 | 17 | |
18 | | - return parent::onView(); |
| 18 | + $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_> |
| 19 | + |
| 20 | + if ( !$this->isNewPost() && !$c::hasIdentifier( $this->getTitle()->getText() ) ) { |
| 21 | + $name = $this->getTitle()->getText(); |
| 22 | + $bracketPos = strpos( $name, '(' ); |
| 23 | + |
| 24 | + if ( $bracketPos !== false ) { |
| 25 | + if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) { |
| 26 | + $bracketPos -= 1; |
| 27 | + } |
| 28 | + |
| 29 | + $name = substr( $name, 0, $bracketPos ); |
| 30 | + } |
| 31 | + |
| 32 | + EPCourse::displayAddNewRegion( |
| 33 | + $this->getContext(), |
| 34 | + array( |
| 35 | + 'name' => $this->getRequest()->getText( |
| 36 | + 'newname', |
| 37 | + $name |
| 38 | + ), |
| 39 | + 'term' => $this->getRequest()->getText( 'newterm', '' ), |
| 40 | + ) |
| 41 | + ); |
| 42 | + |
| 43 | + return ''; |
| 44 | + } |
| 45 | + else { |
| 46 | + return parent::onView(); |
| 47 | + } |
19 | 48 | } |
20 | 49 | |
21 | 50 | protected function getItemClass() { |
— | — | @@ -142,17 +171,19 @@ |
143 | 172 | * @see SpecialEPFormPage::getNewData() |
144 | 173 | */ |
145 | 174 | protected function getNewData() { |
146 | | - return array( |
147 | | - 'org_id' => $this->getRequest()->getVal( 'neworg' ), |
148 | | - 'name' => wfMsgExt( |
149 | | - 'ep-course-edit-name-format', |
150 | | - 'parsemag', |
151 | | - $this->getRequest()->getVal( 'newname' ), |
152 | | - $this->getRequest()->getVal( 'newterm' ) |
153 | | - ), |
154 | | - 'term' => $this->getRequest()->getVal( 'newterm' ), |
155 | | - 'mc' => $this->getRequest()->getVal( 'newname' ), |
| 175 | + $data = parent::getNewData(); |
| 176 | + |
| 177 | + $data['org_id'] = $this->getRequest()->getVal( 'neworg' ); |
| 178 | + $data['name'] = wfMsgExt( |
| 179 | + 'ep-course-edit-name-format', |
| 180 | + 'parsemag', |
| 181 | + $data['name'], |
| 182 | + $this->getRequest()->getVal( 'newterm' ) |
156 | 183 | ); |
| 184 | + $data['term'] = $this->getRequest()->getVal( 'newterm' ); |
| 185 | + $data['mc'] = $data['name']; |
| 186 | + |
| 187 | + return $data; |
157 | 188 | } |
158 | 189 | |
159 | 190 | /** |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | $this->getOutput()->addModules( 'ep.formpage' ); |
18 | 18 | |
19 | 19 | if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
| 20 | + |
20 | 21 | $this->showForm(); |
21 | 22 | } |
22 | 23 | else { |
— | — | @@ -155,8 +156,10 @@ |
156 | 157 | ); |
157 | 158 | } |
158 | 159 | |
159 | | - $form = new HTMLForm( $fields, $this->getContext() ); |
| 160 | + $form = new EPFailForm( $fields, $this->getContext() ); |
160 | 161 | |
| 162 | + $form->setQuery( array( 'action' => 'edit' ) ); |
| 163 | + |
161 | 164 | $form->setSubmitCallback( array( $this, 'handleSubmission' ) ); |
162 | 165 | $form->setSubmitText( wfMsg( 'educationprogram-org-submit' ) ); |
163 | 166 | $form->setSubmitTooltip( 'ep-form-save' ); |
Index: trunk/extensions/EducationProgram/includes/EPFailForm.php |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * I so love HTMLForm. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file EPFailForm.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class EPFailForm extends HTMLForm { |
| 16 | + |
| 17 | + /** |
| 18 | + * Wrap the form innards in an actual <form> element |
| 19 | + * @param $html String HTML contents to wrap. |
| 20 | + * @return String wrapped HTML. |
| 21 | + */ |
| 22 | + function wrapForm( $html ) { |
| 23 | + |
| 24 | + # Include a <fieldset> wrapper for style, if requested. |
| 25 | + if ( $this->mWrapperLegend !== false ) { |
| 26 | + $html = Xml::fieldset( $this->mWrapperLegend, $html ); |
| 27 | + } |
| 28 | + # Use multipart/form-data |
| 29 | + $encType = $this->mUseMultipart |
| 30 | + ? 'multipart/form-data' |
| 31 | + : 'application/x-www-form-urlencoded'; |
| 32 | + # Attributes |
| 33 | + $attribs = array( |
| 34 | + 'action' => $this->getTitle()->getFullURL( $this->query ), |
| 35 | + 'method' => $this->mMethod, |
| 36 | + 'class' => 'visualClear', |
| 37 | + 'enctype' => $encType, |
| 38 | + ); |
| 39 | + if ( !empty( $this->mId ) ) { |
| 40 | + $attribs['id'] = $this->mId; |
| 41 | + } |
| 42 | + |
| 43 | + return Html::rawElement( 'form', $attribs, $html ); |
| 44 | + } |
| 45 | + |
| 46 | + protected $query = array(); |
| 47 | + |
| 48 | + public function setQuery( array $query ) { |
| 49 | + $this->query = $query; |
| 50 | + } |
| 51 | + |
| 52 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/EducationProgram/includes/EPFailForm.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |
Index: trunk/extensions/EducationProgram/resources/ep.addcourse.js |
— | — | @@ -20,6 +20,18 @@ |
21 | 21 | ); |
22 | 22 | } ); |
23 | 23 | |
| 24 | + var list = [ 'neworg', 'newname', 'newterm' ]; |
| 25 | + |
| 26 | + for ( i in list ) { |
| 27 | + if ( list.hasOwnProperty( i ) ) { |
| 28 | + var $element = $( '#' + list[i] ), |
| 29 | + val = $element.val(); |
| 30 | + |
| 31 | + $element.removeAttr( 'value' ); |
| 32 | + $element.val( val ); |
| 33 | + } |
| 34 | + } |
| 35 | + |
24 | 36 | $( '.ep-course-add' ).removeAttr( 'disabled' ); |
25 | 37 | |
26 | 38 | } ); |