Tobias Gritschacher has submitted this change and it was merged.
Change subject: Simplifying listview widget while introducing snaklistview
......................................................................
Simplifying listview widget while introducing snaklistview
The generic listview widget does not need a cascading DOM structure anymore.
The toolbar
placeholder needed for the references is moved to a new snaklistview template.
The actual snaklistview widget will be implemented in another change set.
Change-Id: Id2cbff8246baba9dad93e35a0dd1ff9cc1f9cbdf
---
M lib/resources/jquery.wikibase/jquery.wikibase.listview.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
M lib/resources/templates.php
M selenium/lib/modules/reference_module.rb
4 files changed, 32 insertions(+), 21 deletions(-)
Approvals:
Tobias Gritschacher: Verified; Looks good to me, approved
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
index eea643d..f817810 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
@@ -54,12 +54,6 @@
widgetBaseClass: 'wb-listview',
/**
- * Section node containing the list items
- * @type jQuery
- */
- $listItems: null,
-
- /**
* Short cut for 'listItemAdapter' option
* @type jQuery.wikibase.listview.ListItemAdapter
*/
@@ -75,9 +69,6 @@
'', // list items
'' // toolbar
],
- templateShortCuts: {
- '$listItems': '.wb-listview-items'
- },
value: null,
listItemAdapter: null
},
@@ -101,7 +92,7 @@
// apply template to this.element:
PARENT.prototype._create.call( this );
- this._createList(); // fill this.$listItems
+ this._createList(); // fill list with items
// remove list item after remove operation has finished
this.element.on( liAfterRemoveEvent, function( e ) {
@@ -130,7 +121,7 @@
},
/**
- * Will fill this.$listItems with sections DOM, all sections will
already contain their related
+ * Will fill the list element with sections DOM, all sections will
already contain their related
* list items DOM.
*
* @since 0.4
@@ -152,7 +143,7 @@
* @return {jQuery}
*/
items: function() {
- return this.$listItems.children();
+ return this.element.children();
},
/**
@@ -199,7 +190,7 @@
},
natively: function( event, value, $newLi ) {
// first insert DOM so value widget's events can
already bubble during initialization!
- this.$listItems.append( $newLi );
+ this.element.append( $newLi );
this._lia.newListItem( $newLi, value );
this._trigger( 'itemadded', null, [ value, $newLi ] );
@@ -218,7 +209,7 @@
removeItem: $.NativeEventHandler( 'removeitem', {
initially: function( event, $itemNode ) {
// check whether given node actually is in this list.
If not, fail!
- if( !$itemNode.parent( this.$listItems ).length ) {
+ if( !$itemNode.parent( this.element ).length ) {
throw new Error( 'The given node is not an
element in this list' );
}
// even though this information is kind of redundant
since the value can be accessed
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index 8bd0039..f55c89b 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -68,7 +68,13 @@
if( this.value() ) {
var statementGuid = this.value().getGuid();
- this.$references.listview( {
+ this.$references.append( mw.template( 'wb-snaklistview',
+ '', // listview placeholder
+ '' // toolbar placeholder
+ ) );
+
+ var $snaklistview = this.$references.find(
'.wb-snaklistview-listview' );
+ $snaklistview.listview( {
listItemAdapter: new
$.wikibase.listview.ListItemAdapter( {
listItemWidget:
$.wikibase.referenceview,
listItemWidgetValueAccessor: 'value',
@@ -170,6 +176,15 @@
} );
+ // Forward query for listview reference.
+ this.$references.data(
+ 'listview',
+ this.$references.find(
'.wb-snaklistview-listview' ).data( 'listview' )
+ );
+ // Simulate $.ui.Widget create call. (Will become
obsolete as soon as referenceview's
+ // inheritance is resolved.)
+ this.$references.children( '.wb-snaklistview'
).trigger( 'snaklistviewcreate' );
+
// Collapse references if there is at least one.
if ( this.$references.data( 'listview' ).items().length
> 0 ) {
this.$references.css( 'display', 'none' );
@@ -257,10 +272,10 @@
$.wikibase.toolbarcontroller.definition( 'addtoolbar', {
id: 'references',
selector: '.wb-statement-references-container',
- eventPrefix: 'referenceview',
+ eventPrefix: 'snaklistview',
baseClass: 'wb-referenceview',
options: {
- toolbarParentSelector: '.wb-statement-references >
.wb-listview-toolbar',
+ toolbarParentSelector: '.wb-statement-references
.wb-snaklistview > .wb-listview-toolbar',
customAction: function( event, $parent ) {
var statementView = $parent.closest(
'.wb-statementview' ).data( 'statementview' );
statementView.$references.data( 'listview'
).enterNewItem();
diff --git a/lib/resources/templates.php b/lib/resources/templates.php
index b54aea8..8e7bda6 100644
--- a/lib/resources/templates.php
+++ b/lib/resources/templates.php
@@ -125,8 +125,13 @@
$templates['wb-listview'] =
<<<HTML
-<div>
- <div class="wb-listview-items">$1</div> <!-- list members -->
+<div>$1</div>
+HTML;
+
+ $templates['wb-snaklistview'] =
+<<<HTML
+<div class="wb-snaklistview">
+ <div class="wb-snaklistview-listview">$1</div> <!-- listview -->
<div class="wb-listview-toolbar">$2</div> <!-- edit section -->
</div>
HTML;
diff --git a/selenium/lib/modules/reference_module.rb
b/selenium/lib/modules/reference_module.rb
index 0323a2e..63ba9b3 100644
--- a/selenium/lib/modules/reference_module.rb
+++ b/selenium/lib/modules/reference_module.rb
@@ -12,7 +12,7 @@
div(:referenceContainer, :class => "wb-statement-references-container")
div(:referenceHeading, :class => "wb-statement-references-heading")
link(:referenceHeadingToggleLink, :css => ".wb-statement-references-heading
a")
- div(:referenceListItems, :xpath => "//div[contains(@class,
'wb-statement-references')]/div[contains(@class, 'wb-listview-items')]")
+ div(:referenceListItems, :xpath => "//div[contains(@class,
'wb-statement-references')]/div[contains(@class, 'wb-snaklistview')]")
div(:reference1Property, :xpath => "//div[contains(@class,
'wb-referenceview')][1]/div[contains(@class,
'wb-reference-snaks')]/div[contains(@class, 'wb-snak-property-container')]/div")
div(:reference2Property, :xpath => "//div[contains(@class,
'wb-referenceview')][2]/div[contains(@class,
'wb-reference-snaks')]/div[contains(@class, 'wb-snak-property-container')]/div")
div(:reference3Property, :xpath => "//div[contains(@class,
'wb-referenceview')][3]/div[contains(@class,
'wb-reference-snaks')]/div[contains(@class, 'wb-snak-property-container')]/div")
@@ -25,7 +25,7 @@
link(:saveReference, :xpath => "//div[contains(@class,
'wb-claim-toolbar')]/span/span/span[contains(@class,
'wb-ui-toolbar-editgroup-ineditmode')]/span/a[text()='save']")
link(:cancelReference, :xpath => "//div[contains(@class,
'wb-claim-toolbar')]/span/span/span[contains(@class,
'wb-ui-toolbar-editgroup-ineditmode')]/span/a[text()='cancel']")
link(:removeReference, :xpath => "//div[contains(@class,
'wb-claim-toolbar')]/span/span/span[contains(@class,
'wb-ui-toolbar-editgroup-ineditmode')]/span/a[text()='remove']")
- link(:addReferenceToFirstClaim, :xpath => "//div[contains(@class,
'wb-statement-references-container')][1]/div[contains(@class,
'wb-statement-references')]/div[contains(@class,
'wb-listview-toolbar')]/div/span/span/a")
+ link(:addReferenceToFirstClaim, :xpath => "//div[contains(@class,
'wb-statement-references-container')][1]/div[contains(@class,
'wb-statement-references')]/div[contains(@class,
'wb-snaklistview')]/div[contains(@class,
'wb-listview-toolbar')]/div/span/span/a")
link(:editReference1, :xpath => "//div[contains(@class,
'wb-referenceview')][1]/div[contains(@class,
'wb-claim-toolbar')]/span/span/span/span/a[text()='edit']")
def wait_for_reference_value_box
--
To view, visit https://gerrit.wikimedia.org/r/52612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id2cbff8246baba9dad93e35a0dd1ff9cc1f9cbdf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits