jenkins-bot has submitted this change and it was merged.
Change subject: Show topic heading in previews
......................................................................
Show topic heading in previews
Bug: 68135
Change-Id: I9ff430981e6cf0177fb90e18da12b0c89c5abd2d
---
M handlebars/compiled/flow_block_topiclist.handlebars.php
M handlebars/flow_newtopic_form.handlebars
M modules/new/components/flow-board.js
M tests/qunit/new/components/test_flow-board.js
4 files changed, 53 insertions(+), 39 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/handlebars/compiled/flow_block_topiclist.handlebars.php
b/handlebars/compiled/flow_block_topiclist.handlebars.php
index d59d041..65b9c3b 100644
--- a/handlebars/compiled/flow_block_topiclist.handlebars.php
+++ b/handlebars/compiled/flow_block_topiclist.handlebars.php
@@ -132,7 +132,7 @@
required
type="text" placeholder="'.LCRun3::ch($cx, 'l10n',
Array(Array('flow-newtopic-start-placeholder'),Array()), 'encq').'"
data-role="title"/>
<textarea name="topiclist_content"
- data-flow-preview-template="flow_post"
+ data-flow-preview-template="flow_topic"
class="mw-ui-input flow-form-collapsible
mw-ui-input-large"
placeholder="'.LCRun3::ch($cx, 'l10n',
Array(Array('flow-newtopic-content-placeholder',((is_array($cx['scopes'][0]) &&
isset($cx['scopes'][0]['title'])) ? $cx['scopes'][0]['title'] :
null)),Array()), 'encq').'" data-role="content" required></textarea>
diff --git a/handlebars/flow_newtopic_form.handlebars
b/handlebars/flow_newtopic_form.handlebars
index 204bd87..d8fd016 100644
--- a/handlebars/flow_newtopic_form.handlebars
+++ b/handlebars/flow_newtopic_form.handlebars
@@ -12,7 +12,7 @@
required
type="text" placeholder="{{l10n
"flow-newtopic-start-placeholder"}}" data-role="title"/>
<textarea name="topiclist_content"
- data-flow-preview-template="flow_post"
+ data-flow-preview-template="flow_topic"
class="mw-ui-input flow-form-collapsible
mw-ui-input-large"
placeholder="{{l10n "flow-newtopic-content-placeholder"
@root.title}}" data-role="content" required></textarea>
diff --git a/modules/new/components/flow-board.js
b/modules/new/components/flow-board.js
index 334f262..9363333 100644
--- a/modules/new/components/flow-board.js
+++ b/modules/new/components/flow-board.js
@@ -706,7 +706,8 @@
* @param {jqXHR} jqxhr
*/
FlowBoardComponent.UI.events.apiHandlers.preview = function(
info, data, jqxhr ) {
- var $button = $( this ),
+ var revision, creator,
+ $button = $( this ),
$form = $button.closest( 'form' ),
flowBoard =
FlowBoardComponent.prototype.getInstanceByElement( $form ),
$titleField = $form.find( 'input' ).filter(
'[data-role=title]' ),
@@ -714,6 +715,7 @@
templateParams,
$target = info.$target,
username = mw.user.getName(),
+ id = Math.random(),
previewTemplate = $target.data(
'flow-preview-template' ),
contentNode = $target.data( 'flow-preview-node'
) || 'content';
@@ -722,31 +724,44 @@
return;
}
- templateParams = {
- postId: Math.random(),
- creator: {
- links: {
- contribs: {
- url: mw.util.getUrl(
'Special:Contributions/' + username ),
- exists: true,
- title: username
- }
- },
- name: username ||
flowBoard.TemplateEngine.l10n( 'flow-anonymous' )
+ creator = {
+ links: {
+ contribs: {
+ url: mw.util.getUrl(
'Special:Contributions/' + username ),
+ exists: true,
+ title: username
+ }
},
+ name: username ||
flowBoard.TemplateEngine.l10n( 'flow-anonymous' )
+ };
+
+ revision = {
+ postId: id,
+ creator: creator,
+ replies: [ id ],
isPreview: true
};
- templateParams[contentNode] = {
+ revision[contentNode] = {
content: data['flow-parsoid-utils'].content,
format: data['flow-parsoid-utils'].format
};
- // @todo don't do these. it's a catch-all for the
templates which expect a revision key, and those that don't.
- templateParams.revision = templateParams;
-
- if ( $titleField.length ) {
- templateParams.title = $titleField.val();
- }
+ templateParams = {
+ content: {
+ content: $titleField.val() || '',
+ format: 'content'
+ },
+ creator: creator,
+ posts: {},
+ // @todo don't do these. it's a catch-all for
the templates which expect a revision key, and those that don't.
+ revision: revision,
+ reply_count: 1,
+ last_updated: +new Date(),
+ replies: [ id ],
+ revisions: {}
+ };
+ templateParams.posts[id] = { 0: id };
+ templateParams.revisions[id] = revision;
// Render the preview warning
$previewContainer = $(
flowBoard.TemplateEngine.processTemplateGetFragment(
@@ -764,15 +779,18 @@
) ).children()
);
- // Hide the original textarea
+ // Hide any input fields
+ $form.find( 'input, textarea' )
+ .addClass( 'flow-preview-target-hidden' );
+
+ // Insert the new preview before the form
$target
- .addClass( 'flow-preview-target-hidden' )
- // Insert the new preview
+ .parent( 'form' )
.before( $previewContainer );
// On cancel, make the preview get removed and reset
the form back to its original state
flowBoardComponentAddCancelCallback( $form, function ()
{
- flowBoardComponentResetPreview( $button,
$target );
+ flowBoardComponentResetPreview( $button );
} );
// Assign the reset-preview information for later use
@@ -1215,7 +1233,6 @@
return false;
}
} );
-
// If all the text fields are empty, OR if the user
confirms to close this with text already entered, do it.
if ( !changedFieldCount || confirm(
flowBoard.TemplateEngine.l10n( 'flow-cancel-warning' ) ) ) {
// Reset the form content
@@ -1794,7 +1811,7 @@
// If any preview is visible cancel it
// Must be done before compressing text areas because
// the preview may have manipulated them.
- if ( $form.find( '.flow-preview-warning' ).length ) {
+ if ( $form.parent().find( '.flow-preview-warning'
).length ) {
flowBoardComponentResetPreview(
$form.find(
'button[data-role="cancel"]' )
);
@@ -2269,25 +2286,19 @@
/**
* Removes the preview and unhides the form fields.
* @param {jQuery} $cancelButton
- * @param {jQuery} [$target]
* @return {bool} true if success
*/
- function flowBoardComponentResetPreview( $cancelButton, $target
) {
- var $button = $cancelButton.closest( 'form' ).find(
'[name=preview]' ),
+ function flowBoardComponentResetPreview( $cancelButton ) {
+ var $form = $cancelButton.closest( 'form' ),
+ $button = $form.find( '[name=preview]' ),
oldData = $button.data( 'flow-return-to-edit' );
if ( oldData ) {
// We're in preview mode. Revert it back.
$button.text( oldData.text );
- // Find the target
- if ( !$target || !$target.length ) {
- $target = $button.findWithParent(
$button.data( 'flowApiTarget' ) );
- $target = !$target || !$target.length ?
$button : $target;
- }
-
- // Show the target again
- $target.removeClass(
'flow-preview-target-hidden' ).focus();
+ // Show the inputs again
+ $form.find( '.flow-preview-target-hidden'
).removeClass( 'flow-preview-target-hidden' ).focus();
// Remove the preview
oldData.$nodes.remove();
diff --git a/tests/qunit/new/components/test_flow-board.js
b/tests/qunit/new/components/test_flow-board.js
index be569fc..3b71c69 100644
--- a/tests/qunit/new/components/test_flow-board.js
+++ b/tests/qunit/new/components/test_flow-board.js
@@ -13,9 +13,10 @@
}
} );
-QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 4, function(
assert ) {
+QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 6, function(
assert ) {
var $container = this.$el,
$form = $( '<form>' ).appendTo( $container ),
+ $input = $( '<input value="HEADING">' ).appendTo( $form ),
$textarea = $( '<textarea
data-flow-preview-template="flow_post">text</textarea>' ).appendTo( $form ),
$btn = $( '<button name="preview">' ).
appendTo( $form ),
@@ -35,11 +36,13 @@
// check all is well.
assert.strictEqual( $container.find( '.flow-preview-warning' ).length,
1, 'There is a preview warning.' );
assert.strictEqual( $textarea.hasClass( 'flow-preview-target-hidden' ),
true, 'Textarea is hidden.' );
+ assert.strictEqual( $input.hasClass( 'flow-preview-target-hidden' ),
true, 'Input is hidden.' );
// now cancel the form
this.UI.events.interactiveHandlers.cancelForm.call( $btn, new $.Event()
);
assert.strictEqual( $container.find( '.flow-preview-warning' ).length,
0, 'There is no preview warning.' );
assert.strictEqual( $textarea.hasClass( 'flow-preview-target-hidden' ),
false, 'Textarea is no longer hidden.' );
+ assert.strictEqual( $input.hasClass( 'flow-preview-target-hidden' ),
false, 'Input is no longer hidden.' );
} );
} ( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/155467
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9ff430981e6cf0177fb90e18da12b0c89c5abd2d
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits