Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155467
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, 50 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/67/155467/1
diff --git a/handlebars/compiled/flow_block_topiclist.handlebars.php
b/handlebars/compiled/flow_block_topiclist.handlebars.php
index 91af18c..6a6d6a1 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 58bf65c..e3bc31f 100644
--- a/modules/new/components/flow-board.js
+++ b/modules/new/components/flow-board.js
@@ -700,7 +700,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]' ),
@@ -708,6 +709,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';
@@ -716,31 +718,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(
@@ -758,10 +773,13 @@
) ).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
@@ -2267,7 +2285,8 @@
* @return {bool} true if success
*/
function flowBoardComponentResetPreview( $cancelButton, $target
) {
- var $button = $cancelButton.closest( 'form' ).find(
'[name=preview]' ),
+ var $form = $cancelButton.closest( 'form' ),
+ $button = $form.find( '[name=preview]' ),
oldData = $button.data( 'flow-return-to-edit' );
if ( oldData ) {
@@ -2280,8 +2299,8 @@
$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 3b631e9..8401cca 100644
--- a/tests/qunit/new/components/test_flow-board.js
+++ b/tests/qunit/new/components/test_flow-board.js
@@ -14,9 +14,10 @@
}
} );
-QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 4, function(
assert ) {
+QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 6, function(
assert ) {
var $container = $( '<div>' ),
$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 ),
@@ -38,11 +39,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.FlowBoardComponent.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: newchange
Gerrit-Change-Id: I9ff430981e6cf0177fb90e18da12b0c89c5abd2d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits