Bsitu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/89142


Change subject: Post a reply to a topic
......................................................................

Post a reply to a topic

Change-Id: Id174f5e21e570eba5486ae3bd393f4228fd50d48
---
M modules/discussion/forms.js
M modules/discussion/styles/topic.less
M modules/discussion/ui.js
M templates/topic.html.php
4 files changed, 142 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/42/89142/1

diff --git a/modules/discussion/forms.js b/modules/discussion/forms.js
index 7ec80dc..860e6ed 100644
--- a/modules/discussion/forms.js
+++ b/modules/discussion/forms.js
@@ -14,6 +14,11 @@
                '.flow-newtopic-submit'
        );
 
+       $container.find( 'form.flow-topic-reply-form' ).flow( 
'setupEmptyDisabler',
+               ['.flow-topic-reply-content'],
+               '.flow-topic-reply-submit'
+       );
+
        // Overload 'new topic' handler.
        $container.flow( 'setupFormHandler',
                '.flow-newtopic-submit',
@@ -78,6 +83,49 @@
                }
        );
 
+       // Overload 'topic reply' handler
+       $container.flow( 'setupFormHandler',
+               '.flow-topic-reply-submit',
+               mw.flow.api.reply,
+               function() {
+                       var $form = $( this ).closest( '.flow-topic-reply-form' 
),
+                               workflowId = $( this ).flow( 
'getTopicWorkflowId' ),
+                               replyToId = $( this )
+                                       .closest( '.flow-topic-reply-container' 
)
+                                       .data( 'post-id' ),
+                               content = mw.flow.editor.getContent( 
$form.find( '.flow-topic-reply-content' ) );
+
+                       return [ workflowId, replyToId, content ];
+               },
+               function ( workflowId, replyTo, content ) {
+                       return content;
+               },
+               function ( promise ) {
+                       promise
+                               .done( function ( output ) {
+                                       // Replies are currently sorted in 
timestamp descending order.
+                                       // If we change it to ascending order, 
then we need to append
+                                       // the new element to the end of the 
container and remove the
+                                       // sliding-up effect
+                                       var $replyContainer = $( this )
+                                                       .closest( 
'.flow-topic-container' ).children(":first"),
+                                               $newRegion = $( output.rendered 
)
+                                                       .hide()
+                                                       .insertAfter( 
$replyContainer )
+                                                       .trigger( 'flow_init' )
+                                                       .slideDown();
+                                       $( 'html,body' ).animate( {
+                                               'scrollTop': $( '#flow-topic-' 
+ $( this ).closest( '.flow-topic-container' ).data( 'topic-id' ) ).offset().top
+                                       }, 500 );
+                                       // Reset the form
+                                       // @Todo - this works but doesn't seem 
right
+                                       var $form = $( this ).closest( 
'.flow-topic-reply-form' );
+                                       mw.flow.editor.destroy( $form.find( 
'.flow-topic-reply-content' ) );
+                                       mw.flow.editor.load( $form.find( 
'.flow-topic-reply-content' ) );
+                               } );
+               }
+       );
+
        // Overload 'edit post' link.
        $container.find( '.flow-edit-post-link' )
                .click( function ( e ) {
diff --git a/modules/discussion/styles/topic.less 
b/modules/discussion/styles/topic.less
index cf5b924..b50ad25 100644
--- a/modules/discussion/styles/topic.less
+++ b/modules/discussion/styles/topic.less
@@ -187,3 +187,24 @@
                }
        }
 }
+
+.flow-topic-reply-container {
+       padding-left: 22px;
+       margin-top: 20px;
+
+       .flow-creator {
+               font-weight: bold;
+               color: @post-title-color;
+               padding-bottom: 22px;
+       }
+
+       .flow-topic-reply-form {
+               margin-top: 22px;
+
+               .flow-post-form-controls {
+                       text-align: right;
+               }
+       }
+
+       
+}
diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js
index e863619..b1be8fc 100644
--- a/modules/discussion/ui.js
+++ b/modules/discussion/ui.js
@@ -142,6 +142,33 @@
                        .after( ' ' )
                        .insertBefore( $container.find( '.flow-newtopic-form 
input[type=submit]' ) );
 
+               // Hide all Reply/Thanks buttons
+               $container.find( '.flow-post-main .flow-post-interaction' 
).hide();
+               $container.find( '.flow-post-main' ).hover( function() {
+                               $( this ).find( '.flow-post-interaction' 
).show(); },
+                       function() { 
+                               $( this ).find( '.flow-post-interaction' 
).hide();
+                       }
+               );
+       
+               // Set up topic reply form
+               $container.find( '.flow-topic-reply-content' ).each( function() 
{
+                       mw.flow.editor.load( $( this ) );
+               } );
+
+               // Set up the scroll to new topic reply form
+               $container.find( '.flow-topic-posts-meta .flow-post-number' 
).click(
+                       function( e ) {
+                               var $hideElement = $( this ).closest( 
'.flow-topic-container' ).children( '.flow-post-container' ), self = this;
+                               e.stopPropagation();
+                               $hideElement.slideDown( function() {
+                                       $( 'html,body' ).animate( {
+                                               'scrollTop': $( 
'#flow-topic-reply-' + $( self ).data( 'topic-id' ) ).offset().top
+                                       }, 500 );
+                               } );
+                       }
+               );
+
                // Set up folding
                $container.find( '.flow-titlebar' )
                        .click( function ( e ) {
diff --git a/templates/topic.html.php b/templates/topic.html.php
index 0349b00..8eccf20 100644
--- a/templates/topic.html.php
+++ b/templates/topic.html.php
@@ -67,7 +67,7 @@
 
        <ul class="flow-topic-posts-meta">
                <li>@todo: participants</li>
-               <li>@todo: # comments</li>
+               <li class="flow-post-number" data-topic-id="<?php echo 
$topic->getId()->getHex() ?>">@todo: # comments</li>
        </ul>
 
        <?php
@@ -101,10 +101,54 @@
                </span>
        </p>
 </div>
-
 <?php
 foreach( $root->getChildren() as $child ) {
        echo $this->renderPost( $child, $block, $root );
 }
+
+// Topic reply box
+echo Html::openElement( 'div', array(
+       'class' => 'flow-topic-reply-container flow-post-container',
+       'data-post-id' => $root->getRevisionId()->getHex(),
+       'id' => 'flow-topic-reply-' . $topic->getId()->getHex()
+) );
+?>
+       <span class="flow-creator">
+               <span class="flow-creator-simple" style="display: inline">
+                       <?php echo htmlspecialchars( $user->getName() ); ?>
+               </span>
+               <span class="flow-creator-full" style="display: none">
+                       <?php echo $this->userToolLinks( $user->getId(), 
$user->getName() ); ?>
+               </span>
+       </span>
+<?php
+       echo Html::openElement( 'form', array(
+               'method' => 'POST',
+               'action' => $this->generateUrl( $block->getWorkflow(), 'reply' 
),
+               'class' => 'flow-topic-reply-form',
+       ) ),
+       Html::element( 'input', array(
+               'type' => 'hidden',
+               'name' => $block->getName() . '[replyTo]',
+               'value' => $topic->getId()->getHex(),
+       ) ),
+       Html::element( 'input', array(
+               'type' => 'hidden',
+               'name' => 'wpEditToken',
+               'value' => $editToken,
+       ) ),
+       Html::textarea( $block->getName() . '[topic-reply-content]', '', array(
+               'placeholder' => wfMessage( 'flow-newtopic-content-placeholder' 
)->text(),
+               'class' => 'flow-input mw-ui-input flow-topic-reply-content',
+       ) ),
+       Html::openElement( 'div', array( 'class' => 'flow-post-form-controls' ) 
),
+       Html::element( 'input', array(
+               'type' => 'submit',
+               'value' => wfMessage( 'flow-reply-submit', 
$root->getCreatorName( $user ) )->text(),
+               'class' => 'mw-ui-button mw-ui-constructive 
flow-topic-reply-submit',
+       ) ),
+       Html::closeElement( 'div' ),
+       Html::closeElement( 'form' ),
+       Html::closeElement( 'div' );
 ?>
 </div>

-- 
To view, visit https://gerrit.wikimedia.org/r/89142
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id174f5e21e570eba5486ae3bd393f4228fd50d48
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to