Index: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php |
— | — | @@ -56,6 +56,7 @@ |
57 | 57 | 'story_title', |
58 | 58 | 'story_text', |
59 | 59 | 'story_is_published', |
| 60 | + 'story_author_image', |
60 | 61 | 'story_image_hidden' |
61 | 62 | ), |
62 | 63 | array( 'story_is_hidden' => 0 ) |
— | — | @@ -96,33 +97,58 @@ |
97 | 98 | * @return string |
98 | 99 | */ |
99 | 100 | private function getStorySegments( $story ) { |
100 | | - $imageSrc = 'http://upload.wikimedia.org/wikipedia/mediawiki/9/99/SemanticMaps.png'; // TODO: get cropped image here |
| 101 | + global $wgTitle; |
101 | 102 | |
| 103 | + $editUrl = SpecialPage::getTitleFor( 'story', $story->story_title )->getFullURL('action=edit&returnto=' . $wgTitle->getPrefixedText() ); |
| 104 | + $editUrl = Xml::escapeJsString( $editUrl ); |
| 105 | + |
102 | 106 | $title = htmlspecialchars( $story->story_title ); |
103 | 107 | $text = htmlspecialchars( $story->story_text ); |
104 | 108 | |
105 | 109 | $publishAction = $story->story_is_published ? 'unpublish' : 'publish'; |
106 | | - // Uses storyboard-unpublish or storyboard-publish |
107 | | - $publishMsg = htmlspecialchars( wfMsg( "storyboard-$publishAction" ) ); |
| 110 | + // Uses storyboard-unpublish or storyboard-publish. |
| 111 | + $publishMsg = htmlspecialchars( wfMsg( "storyboard-$publishAction" ) ); |
108 | 112 | |
109 | | - $imageAction = $story->story_image_hidden ? 'unhideimage' : 'hideimage'; |
110 | | - // Uses storyboard-unhideimage or storyboard-hideimage |
111 | | - $imageMsg = htmlspecialchars( wfMsg( "storyboard-$imageAction" ) ); |
112 | | - |
113 | 113 | $editMsg = htmlspecialchars( wfMsg( 'edit' ) ); |
114 | | - $hideMsg = htmlspecialchars( wfMsg( 'hide' ) ); |
115 | | - $deleteImageMsg = htmlspecialchars( wfMsg( 'storyboard-deleteimage' ) ); |
| 114 | + $hideMsg = htmlspecialchars( wfMsg( 'hide' ) ); |
116 | 115 | |
117 | | - global $wgTitle; |
118 | | - $editUrl = SpecialPage::getTitleFor( 'story', $story->story_title )->getFullURL('action=edit&returnto=' . $wgTitle->getPrefixedText() ); |
119 | | - $editUrl = Xml::escapeJsString( $editUrl ); |
| 116 | + $imageHtml = ''; |
| 117 | + $imageButtonsHtml = ''; |
120 | 118 | |
| 119 | + if ( $story->story_author_image ) { |
| 120 | + $imageAction = $story->story_image_hidden ? 'unhideimage' : 'hideimage'; |
| 121 | + // Uses storyboard-unhideimage or storyboard-hideimage. |
| 122 | + $imageMsg = htmlspecialchars( wfMsg( "storyboard-$imageAction" ) ); |
| 123 | + |
| 124 | + $deleteImageMsg = htmlspecialchars( wfMsg( 'storyboard-deleteimage' ) ); |
| 125 | + |
| 126 | + $imgAttribs = array( |
| 127 | + 'src' => $story->story_author_image, |
| 128 | + 'class' => 'story-image', |
| 129 | + 'id' => "story_image_$story->story_id", |
| 130 | + 'title' => $title, |
| 131 | + 'alt' => $title |
| 132 | + ); |
| 133 | + |
| 134 | + if ( $story->story_image_hidden ) { |
| 135 | + $imgAttribs['style'] = 'display:none;'; |
| 136 | + } |
| 137 | + |
| 138 | + $imageHtml = Html::element( 'img', $imgAttribs ); |
| 139 | + |
| 140 | + $imageButtonsHtml = <<<EOT |
| 141 | + <button type="button" |
| 142 | + onclick="stbDoStoryAction( this, $story->story_id, '$imageAction' )" id="image_button_$story->story_id">$imageMsg</button> |
| 143 | + <button type="button" onclick="stbDeleteStoryImage( this, $story->story_id )">$deleteImageMsg</button> |
| 144 | +EOT; |
| 145 | + } |
| 146 | + |
121 | 147 | return <<<EOT |
122 | 148 | <table width="100%" border="1" id="story_$story->story_id"> |
123 | 149 | <tr> |
124 | 150 | <td> |
125 | 151 | <div class="story"> |
126 | | - <img src="http://upload.wikimedia.org/wikipedia/mediawiki/9/99/SemanticMaps.png" class="story-image"> |
| 152 | + $imageHtml |
127 | 153 | <div class="story-title">$title</div><br /> |
128 | 154 | $text |
129 | 155 | </div> |
— | — | @@ -132,9 +158,7 @@ |
133 | 159 | <td align="center" height="35"> |
134 | 160 | <button type="button" onclick="stbDoStoryAction( this, $story->story_id, '$publishAction' )">$publishMsg</button> |
135 | 161 | <button type="button" onclick="window.location='$editUrl'">$editMsg</button> |
136 | | - <button type="button" onclick="stbDoStoryAction( this, $story->story_id, 'hide' )">$hideMsg</button> |
137 | | - <button type="button" onclick="stbDoStoryAction( this, $story->story_id, '$imageAction' )">$imageMsg</button> |
138 | | - <button type="button" onclick="stbDeleteStoryImage( this, $story->story_id )">$deleteImageMsg</button> |
| 162 | + <button type="button" onclick="stbDoStoryAction( this, $story->story_id, 'hide' )">$hideMsg</button>$imageButtonsHtml |
139 | 163 | </td> |
140 | 164 | </tr> |
141 | 165 | </table> |
Index: trunk/extensions/Storyboard/storyboard.js |
— | — | @@ -98,12 +98,22 @@ |
99 | 99 | if ( data.storyreview ) { |
100 | 100 | switch( data.storyreview.action ) { |
101 | 101 | case 'publish' : case 'unpublish' : case 'hide' : |
| 102 | + sender.innerHTML = 'Done'; // TODO: i18n |
102 | 103 | jQuery( '#story_' + data.storyreview.id ).slideUp( 'slow', function () { |
103 | 104 | jQuery( this ).remove(); |
104 | 105 | } ); |
105 | 106 | // TODO: would be neat to update the other list when doing an (un)publish here |
106 | 107 | break; |
107 | | - // TODO: add handling for the other actions |
| 108 | + case 'hideimage' : case 'unhideimage' : |
| 109 | + stbToggeShowImage( sender, data.storyreview.id, data.storyreview.action ); |
| 110 | + break; |
| 111 | + case 'deleteimage' : |
| 112 | + sender.innerHTML = 'Image deleted'; // TODO: i18n |
| 113 | + jQuery( '#story_image_' + data.storyreview.id ).slideUp( 'slow', function () { |
| 114 | + jQuery( this ).remove(); |
| 115 | + } ); |
| 116 | + document.getElementById( 'image_button_' + data.storyreview.id ).disabled = true; |
| 117 | + break; |
108 | 118 | } |
109 | 119 | } else { |
110 | 120 | alert( 'An error occured:\n' + data.error.info ); // TODO: i18n |
— | — | @@ -113,6 +123,35 @@ |
114 | 124 | } |
115 | 125 | |
116 | 126 | /** |
| 127 | + * Updates the show/hide image button after a hideimage/unhideimage |
| 128 | + * action has completed sucesfully. Also updates the image on the |
| 129 | + * page itself accordingly, and hooks up the correct event to the button. |
| 130 | + * |
| 131 | + * @param sender The button that invoked the completed action. |
| 132 | + * @param storyId The id of the story that has been affected. |
| 133 | + * @param completedAction The name ofthe action that has been performed. |
| 134 | + */ |
| 135 | +function stbToggeShowImage( sender, storyId, completedAction ) { |
| 136 | + if ( completedAction == 'hideimage' ) { |
| 137 | + jQuery( '#story_image_' + storyId ).slideUp( 'slow', function () { |
| 138 | + sender.innerHTML = 'Show image'; // TODO: i18n |
| 139 | + sender.onclick = function() { |
| 140 | + stbDoStoryAction( sender, storyId, 'unhideimage' ); |
| 141 | + }; |
| 142 | + sender.disabled = false; |
| 143 | + } ); |
| 144 | + } else { |
| 145 | + jQuery( '#story_image_' + storyId ).slideDown( 'slow', function () { |
| 146 | + sender.innerHTML = 'Hide image'; // TODO: i18n |
| 147 | + sender.onclick = function() { |
| 148 | + stbDoStoryAction( sender, storyId, 'hideimage' ); |
| 149 | + }; |
| 150 | + sender.disabled = false; |
| 151 | + } ); |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +/** |
117 | 156 | * Asks the user to confirm the deletion of an image, and if confirmed, calls stbDoStoryAction with action=delete. |
118 | 157 | * |
119 | 158 | * @param sender The UI element invocing the action, typically a button. |
— | — | @@ -123,7 +162,7 @@ |
124 | 163 | function stbDeleteStoryImage( sender, storyid ) { |
125 | 164 | var confirmed = confirm( 'Are you sure you want to permanently delete this stories image?' ); // TODO: i18n |
126 | 165 | if ( confirmed ) { |
127 | | - doStoryAction( sender, storyid, 'deleteimage' ); |
| 166 | + stbDoStoryAction( sender, storyid, 'deleteimage' ); |
128 | 167 | } |
129 | 168 | return confirmed; |
130 | 169 | } |
\ No newline at end of file |