Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/179101
Change subject: Removed movetoolbar definitions
......................................................................
Removed movetoolbar definitions
As per discussions and ->58050 as well as ->74297 in particular, the broken
"move" toolbar
feature is removed in order to allow sane refactoring of the components having
managed the
API's "index" parameter. "move" feature will be reimplemented as soon as
->74297 is done
while ->58050 may be set to "fixed" after having merged this change.
Change-Id: Idfe47d0d24b967b8fa94d3fc8e30212da601cadd
---
M lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
M repo/resources/entityChangers/ClaimsChanger.js
M repo/resources/entityChangers/ReferencesChanger.js
M repo/resources/wikibase.ui.entityViewInit.js
7 files changed, 8 insertions(+), 874 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/01/179101/1
diff --git
a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
index f661279..38de6df 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplistview.js
@@ -78,20 +78,6 @@
.on( afterStopEditingEvent, function( event, dropValue ) {
self._toggleGroupTitleClass( $( event.target ),
'wb-error' );
self._removeGroupTitleClass( $( event.target ),
'wb-edit' );
-
- if( dropValue ) {
- // Re-order claimlistviews according to their
initial indices:
- var listview = self.$listview.data( 'listview'
),
- $claimlistviews = listview.items();
-
- for( var i = 0; i <
$claimlistviews.length; i++ ) {
- var lia =
listview.listItemAdapter(),
- claimlistviewInstance =
lia.liInstance( $claimlistviews.eq( i ) );
- listview.move(
$claimlistviews.eq( i ), claimlistviewInstance.getInitialIndex() );
- }
- } else {
- self.__updateIndices( !dropValue );
- }
} )
.on( startEditingEvent, function( event ) {
self._addGroupTitleClass( $( event.target ), 'wb-edit'
);
@@ -142,25 +128,6 @@
_createClaimGroupListview: function() {
var self = this;
- function indexOf( claim, claimGroupSet ) {
- var offset = 0,
- curIndex = null;
-
- if( !claim || !claimGroupSet ) {
- return curIndex;
- }
- claimGroupSet.each( function( propertyId, claimGroup ) {
- var indexInGroup =
claimGroup.getItemContainer().indexOf( claim );
- if( indexInGroup !== -1 ) {
- curIndex = offset + indexInGroup;
- } else {
- offset +=
claimGroup.getItemContainer().length;
- }
- return curIndex === null;
- } );
- return curIndex;
- }
-
this.$listview.listview( {
listItemAdapter: new
$.wikibase.listview.ListItemAdapter( {
listItemWidget: $.wikibase.claimlistview,
@@ -168,10 +135,6 @@
return {
value: value,
entityType: self.option(
'entityType' ),
- firstClaimIndex: value &&
indexOf(
-
value.getItemContainer().toArray()[0],
- self.option( 'value' )
- ),
dataTypeStore: self.option(
'dataTypeStore' ),
entityStore: self.option(
'entityStore' ),
valueViewBuilder: self.option(
'valueViewBuilder' ),
@@ -322,42 +285,6 @@
},
/**
- * Updates the claimlistview indices as well as their claimview indices.
- *
- * @param {boolean} save
- *
- * @deprecated See bug #56050
- */
- __updateIndices: function( save ) {
- var index = 0,
- listview = this.$listview.data( 'listview' ),
- $claimlistviews = listview.items();
-
- for( var i = 0; i < $claimlistviews.length; i++ ) {
- var claimlistview =
listview.listItemAdapter().liInstance(
- $claimlistviews.eq( i )
- );
-
- var claimlistviewListview =
claimlistview.$listview.data( 'listview' ),
- $claimviews = claimlistviewListview.items();
-
- for( var j = 0; j < $claimviews.length; j++ ) {
- if( j === 0 ) {
- claimlistview.option(
'firstClaimIndex', index );
-
- if( save ) {
- claimlistview._initialIndex =
index;
- }
- }
-
- claimlistview.__updateClaimIndices( save );
-
- index++;
- }
- }
- },
-
- /**
* @see jQuery.ui.TemplatedWidget._setOption
*/
_setOption: function( key, value ) {
@@ -445,131 +372,6 @@
]();
}
);
- }
- }
-} );
-
-// TODO: The following toolbar manages claimviews/statementviews as well as
claimgrouplistviews.
-// There should be separate toolbars for managing the content of these two
widgets.
-$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
- id: 'claimlistview-claimview',
- selector: '.wb-claimview',
- events: {
- 'claimviewstartediting statementviewstartediting': function(
event, toolbarController ) {
- // Initialize movetoolbar.
-
- var $claimview = $( event.target ),
- $claimlistview = $claimview.closest(
':wikibase-claimlistview' ),
- claimlistview = $claimlistview.data(
'claimlistview' ),
- claimlistviewListview =
claimlistview.$listview.data( 'listview' ),
- claimview =
claimlistviewListview.listItemAdapter().liInstance( $claimview ),
- $claimviews = claimlistviewListview.items(),
- $claimgrouplistview = $claimlistview.closest(
':wikibase-claimgrouplistview' ),
- claimgrouplistview = $claimgrouplistview.data(
'claimgrouplistview' ),
- claimgrouplistviewListview =
claimgrouplistview.$listview.data( 'listview' ),
- $claimlistviews =
claimgrouplistviewListview.items();
-
- if( !claimview || !claimview.value() ) {
- // Do not initialize the movetoolbar when the
claim is pending since that might
- // cause disturbances with the indices.
- return;
- }
-
- $claimview.movetoolbar( {
- $container: $( '<div/>' ).appendTo( $claimview )
- } );
-
- // If the claimview is the topmost claimview in the
topmost claimgroup, the "move up"
- // button needs to be disabled; Same for the "move
down" button if the claimview is
- // the bottommost claimview in the bottommost
claimgroup.
- var isInTopmostClaimgroup =
$claimlistviews.first().get( 0 ) === $claimlistview.get( 0 ),
- isTopmostInClaimlistview =
$claimviews.first().get( 0 ) === $claimview.get( 0 ),
- isInBottommostClaimgroup =
$claimlistviews.last().get( 0 ) === $claimlistview.get( 0 ),
- isBottommostInClaimlistview =
$claimviews.last().get( 0 ) === $claimview.get( 0 );
-
- if ( isInTopmostClaimgroup && isTopmostInClaimlistview
) {
- $claimview.data( 'movetoolbar' ).getButton(
'up' ).disable();
- }
-
- if( isInBottommostClaimgroup &&
isBottommostInClaimlistview ) {
- $claimview.data( 'movetoolbar' ).getButton(
'down' ).disable();
- }
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'statementviewafterstopediting',
- function( event, toolbarcontroller ) {
- // Destroy movetoolbar.
-
- var $claimview = $( event.target ),
- movetoolbar = $claimview.data(
'movetoolbar' );
-
- if( movetoolbar ) {
- // Toolbar might be destroyed
already by cancelling a pending claimview.
-
toolbarcontroller.destroyToolbar( movetoolbar );
- }
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown',
- function( event ) {
- var $claimview = $( event.target ),
- claimview = $claimview.data(
'claimview' )
- || $claimview.data(
'statementview' );
-
- if( !claimview ) {
- // Not the event of the
corresponding toolbar but of some other movetoolbar.
- return;
- }
-
- var action = ( event.type ===
'movetoolbarup' ) ? 'moveUp' : 'moveDown',
- $claimlistview =
$claimview.closest( ':wikibase-claimlistview' ),
- claimlistview =
$claimlistview.data( 'claimlistview' ),
- claimlistviewListview =
claimlistview.$listview.data( 'listview' ),
- $claimviews =
claimlistviewListview.items(),
- $claimgrouplistview =
$claimlistview.closest( ':wikibase-claimgrouplistview' ),
- claimgrouplistview =
$claimgrouplistview.data( 'claimgrouplistview' ),
- claimgrouplistviewListview =
claimgrouplistview.$listview.data( 'listview' );
-
- // Determine whether the whole group
has to be moved:
- var isTopmostInClaimlistview =
$claimview.get( 0 ) === $claimviews.first().get( 0 ),
- isBottommostInClaimlistview =
$claimview.get( 0 ) === $claimviews.last().get( 0 );
-
- if(
- isTopmostInClaimlistview &&
action === 'moveUp'
- || isBottommostInClaimlistview
&& action === 'moveDown'
- ) {
-
claimgrouplistviewListview[action]( $claimlistview );
- } else {
- claimlistviewListview[action](
$claimview );
- }
-
- // Reflect the position change in the
button state:
- $claimviews =
claimlistviewListview.items();
- $claimlistviews =
claimgrouplistviewListview.items();
- isTopmostInClaimlistview =
$claimview.get( 0 ) === $claimviews.first().get( 0 );
- isBottommostInClaimlistview =
$claimview.get( 0 ) === $claimviews.last().get( 0 );
-
- var movetoolbar = $claimview.data(
'movetoolbar' ),
- isInTopmostClaimgroup =
$claimlistviews.first().get( 0 ) === $claimlistview.get( 0 ),
- isInBottommostClaimgroup =
$claimlistviews.last().get( 0 ) === $claimlistview.get( 0 ),
- isTopmost =
isTopmostInClaimlistview && isInTopmostClaimgroup,
- isBottommost =
isBottommostInClaimlistview && isInBottommostClaimgroup;
-
- movetoolbar.getButton( 'up' )[isTopmost
? 'disable' : 'enable' ]();
- movetoolbar.getButton( 'down'
)[isBottommost ? 'disable' : 'enable' ]();
-
- claimgrouplistview.__updateIndices();
-
- // Stop repeatedly triggering the event
on the moved DOM node:
- event.stopImmediatePropagation();
- }
- );
-
}
}
} );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
index aec6af1..0a017c3 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
@@ -25,12 +25,6 @@
*
* @option {dataTypes.DataTypeStore} dataTypeStore
*
- * @option {number|null} [firstClaimIndex] The index of the claimlistview's
first statement within a
- * list of statements.
- * Default: null
- * TODO: Remove this option and use a proper mechanism to store the
ordered statement structure
- * at a higher level independent from claimlistview (bug #56050).
- *
* @event startediting: Triggered when one of the claimlistview's items enters
edit mode.
* (1) {jQuery.Event}
*
@@ -67,7 +61,6 @@
entityType: null,
dataTypeStore: null,
entityStore: null,
- firstClaimIndex: null,
valueViewBuilder: null,
entityChangersFactory: null
},
@@ -77,14 +70,6 @@
* @type {$.wikibase.statementview}
*/
_listItemWidget: null,
-
- /**
- * The index of the claimlistview's first statement within the flat
list of statements (if it is
- * contained within a list of statements). The initial index is stored
to be able to detect whether
- * the index has changed and the statement list does not feature its
initial value.
- * @type {number|null}
- */
- _initialIndex: null,
/**
* @type {wb.entityChangers.ClaimsChanger}
@@ -109,8 +94,6 @@
this._listItemWidget = $.wikibase.statementview;
- this._initialIndex = this.option( 'firstClaimIndex' );
-
this._claimsChanger =
this.options.entityChangersFactory.getClaimsChanger();
this._createListView();
@@ -130,17 +113,6 @@
.on( afterStopEditingEvent, function( event, dropValue ) {
var $statementview = $( event.target ),
statementview = lia.liInstance( $statementview
);
-
- if( dropValue ) {
- // Re-order statements according to their
initial indices:
- var listview = self.$listview.data( 'listview'
),
- $statementviews = listview.items();
-
- for( var i = 0; i < $statementviews.length; i++
) {
- var statementviewInstance =
listview.listItemAdapter().liInstance( $statementviews.eq( i ) );
- listview.move( $statementviews.eq( i ),
statementviewInstance.getInitialIndex() );
- }
- }
// Cancelling edit mode or having stopped edit mode
after saving an existing (not
// pending) statement.
@@ -211,11 +183,6 @@
statements = statements.getItemContainer().toArray();
}
- function indexOf( element, array, firstClaimIndex ) {
- var index = $.inArray( element, array );
- return ( index !== -1 ) ? index + firstClaimIndex :
null;
- }
-
this.$listview
.listview( {
listItemAdapter: new
$.wikibase.listview.ListItemAdapter( {
@@ -237,52 +204,12 @@
entityStore: self.option(
'entityStore' ),
valueViewBuilder: self.option(
'valueViewBuilder' ),
entityChangersFactory:
self.option( 'entityChangersFactory' ),
- claimsChanger:
self._claimsChanger,
- index: indexOf( value, (
statements || [] ), self.option( 'firstClaimIndex' ) )
+ claimsChanger:
self._claimsChanger
};
}
} ),
value: statements || null
- } )
- .on( 'listviewitemadded listviewitemremoved', function( event,
value, $li ) {
- self.__updateClaimIndices();
} );
-
- this.__updateClaimIndices();
- },
-
- /**
- * Updates the statement indices.
- *
- * @param {boolean} save
- *
- * @deprecated See bug #56050
- */
- __updateClaimIndices: function( save ) {
- var listview = this.$listview.data( 'listview' ),
- $statementviews = listview.items();
-
- for( var i = 0; i < $statementviews.length; i++ ) {
- var statementview =
listview.listItemAdapter().liInstance( $statementviews.eq( i ) ),
- index = this.options.firstClaimIndex + i;
-
- statementview.option( 'index', index );
-
- if( save ) {
- statementview._initialIndex = index;
- }
- }
- },
-
- /**
- * Returns the initial index of the statementlist's first statement
within the flat list of statements (if
- * in any).
- * @since 0.5
- *
- * @return {number|null}
- */
- getInitialIndex: function() {
- return this._initialIndex;
},
/**
@@ -382,8 +309,6 @@
// currently, the widget lacks a mechanism to update the value.
if( key === 'value' ) {
throw new Error( 'Can not set value after
initialization' );
- } else if( key === 'fistClaimIndex' ) {
- throw new Error( 'firstClaimIndex cannot be set after
initialization' );
}
var response = PARENT.prototype._setOption.apply( this,
arguments );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
index 948566a..298b428 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
@@ -21,12 +21,6 @@
*
* @option referencesChanger {wikibase.entityChangers.ReferencesChanger}
*
- * @option index {number|null} The reference's index within the list of
references (if the reference
- * is contained within such a list).
- * Default: null
- * TODO: This option should be removed and a proper mechanism
independent from referenceview
- * should be implemented to manage and store the indices of references
(bug #56050).
- *
* @option helpMessage {string} End-user message explaining how to use the
referenceview widget. The
* message is most likely to be used inside the tooltip of the toolbar
corresponding to
* the referenceview.
@@ -74,7 +68,6 @@
entityStore: null,
valueViewBuilder: null,
referencesChanger: null,
- index: null,
helpMessage: mw.msg( 'wikibase-claimview-snak-new-tooltip' )
},
@@ -93,14 +86,6 @@
* @type {wb.datamodel.SnakList}
*/
_initialSnakList: null,
-
- /**
- * The reference's initial index within the list of references (if it
is contained within a list
- * of references). The initial index is stored to be able to detect
whether the index has
- * changed and the reference does not feature its initial value.
- * @type {number|null}
- */
- _initialIndex: null,
/**
* Whether the reference is currently in edit mode.
@@ -143,8 +128,6 @@
this._initialSnakList = new wb.datamodel.SnakList();
}
- this._initialIndex = this.option( 'index' );
-
if( !this.options.listItemAdapter ) {
this.options.listItemAdapter = new
$.wikibase.listview.ListItemAdapter( {
listItemWidget: $.wikibase.snaklistview,
@@ -180,31 +163,6 @@
} );
this._updateReferenceHashClass( this.value() );
- },
-
- /**
- * @see jQuery.Widget.option
- *
- * @triggers change
- */
- option: function( key, value ) {
- var val = PARENT.prototype.option.apply( this, arguments );
-
- if( key === 'index' && value !== undefined ) {
- this._trigger( 'change' );
- }
-
- return val;
- },
-
- /**
- * Returns the reference's initial index within the list of references
(if in any).
- * @since 0.5
- *
- * @return {number|null}
- */
- getInitialIndex: function() {
- return this._initialIndex;
},
/**
@@ -502,10 +460,6 @@
* @return {boolean}
*/
isInitialValue: function() {
- if( this.option( 'index' ) !== this._initialIndex ) {
- return false;
- }
-
var $snaklistviews = this._listview.items(),
snakList = new wb.datamodel.SnakList();
@@ -549,11 +503,8 @@
var self = this,
guid = this.option( 'statementGuid' );
- return this.option( 'referencesChanger' ).setReference(
- guid,
- this.value(),
- this.option( 'index' )
- ).done( function( savedReference ) {
+ return this.option( 'referencesChanger' ).setReference( guid,
this.value() )
+ .done( function( savedReference ) {
self._reference = savedReference;
self._updateReferenceHashClass( savedReference );
} );
@@ -563,7 +514,7 @@
* Sets/removes error state from the widget.
* @since 0.4
*
- * @param {wkibase.api.RepoApiError} [error]
+ * @param {wikibase.api.RepoApiError} [error]
*/
setError: function( error ) {
if ( error ) {
@@ -780,192 +731,6 @@
? 'enable'
: 'disable'
]();
- }
- }
- }
-} );
-
-$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
- id: 'referenceview-snakview',
- selector: '.wb-statement-references .wb-referenceview',
- events: {
- 'snakviewstartediting': function( event, toolbarController ) {
- var $snakview = $( event.target ),
- $snaklistview = $snakview.closest(
':wikibase-snaklistview' ),
- $referenceview = $snakview.closest(
':wikibase-referenceview' ),
- referenceview = $referenceview.data(
'referenceview' );
-
- if( !referenceview ) {
- return;
- }
-
- var snakList =
referenceview.options.listItemAdapter.liInstance( $snaklistview ).value();
-
- // Prevent creating the toolbar for pending values.
- if( snakList !== null ) {
- // Since snakviewstartediting is triggered for
every snakview, this creates the
- // toolbar for each snakview widget:
- $snakview.movetoolbar( {
- $container: $( '<div/>' ).appendTo(
$snakview )
- } );
-
- // Disable "move up" button of topmost and
"move down" button of bottommost
- // snakview:
-
- var $topMostSnakview =
referenceview._listview.items().first().data( 'snaklistview' )
- ._listview.items().first();
- var $bottomMostSnakview =
referenceview._listview.items().last().data( 'snaklistview' )
- ._listview.items().last();
-
- if ( $topMostSnakview.get( 0 ) ===
$snakview.get( 0 ) ) {
- $snakview.data( 'movetoolbar'
).getButton( 'up' ).disable();
- }
-
- if( $bottomMostSnakview.get( 0 ) ===
$snakview.get( 0 ) ) {
- $snakview.data( 'movetoolbar'
).getButton( 'down' ).disable();
- }
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'referenceviewafterstopediting',
- function( event, toolbarcontroller ) {
- // Destroy the snakview
toolbars:
- var $referenceview = $(
event.target ),
- referenceview =
$referenceview.data( 'referenceview' );
-
- if( !referenceview ) {
- // Stopped edit mode of
a pending referenceview which does not feature
- // any movetoolbar.
- return;
- }
-
- var referenceviewLia =
referenceview.options.listItemAdapter;
-
- $.each(
referenceview._listview.items(), function( i, snaklistviewNode ) {
- var $snaklistview = $(
snaklistviewNode ),
- snaklistview =
referenceviewLia.liInstance( $snaklistview ),
- snaklistviewLia
= snaklistview._listview.listItemAdapter();
-
- $.each(
snaklistview._listview.items(), function( j, snakviewNode ) {
- var $snakview =
$( snakviewNode ),
-
snakview = snaklistviewLia.liInstance( $snakview );
-
toolbarcontroller.destroyToolbar( snakview.element.data( 'movetoolbar' ) );
- } );
-
- } );
-
- // Remove obsolete event
handlers attached to the node the toolbarcontroller
- // has been initialized on:
- $referenceview.off(
'.movetoolbar' );
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown',
- function( event ) {
- var $snakview = $( event.target
),
- $snaklistview =
$snakview.closest( ':wikibase-snaklistview' ),
- $referenceview =
$snaklistview.closest( ':wikibase-referenceview' );
-
- if( !$referenceview.length ) {
- // Event belongs to
another movetoolbar.
- return;
- }
-
- var referenceview =
$referenceview.data( 'referenceview' ),
- snaklistview =
referenceview.options.listItemAdapter.liInstance( $snaklistview ),
- snakview =
snaklistview._listview.listItemAdapter().liInstance( $snakview ),
- snak = snakview.snak(),
- snakList =
snaklistview.value(),
- action = ( event.type
=== 'movetoolbarup' ) ? 'moveUp' : 'moveDown';
-
- if( action === 'moveUp' &&
snakList.indexOf( snak ) !== 0 ) {
- // Move up snakview
within a snaklistview.
- snaklistview.moveUp(
snak );
- } else if( action ===
'moveDown' && snakList.indexOf( snak ) !== snakList.length - 1 ) {
- // Move down snakview
within a snaklistview.
- snaklistview.moveDown(
snak );
- } else {
- // When issuing "move
up" on a snak on top of a snak list, the whole snaklistview
- // has to be move; Same
for "move down" on a snak at the bottom of a snak list.
-
referenceview.$listview.data( 'listview' )[action]( $snaklistview );
- }
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown
referenceviewitemadded referenceviewitemremoved',
- function( event ) {
- // Dis- and enable movetoolbar
buttons:
-
- var $target = $( event.target );
-
- var referenceview = (
event.type.indexOf( 'referenceview' ) === 0 )
- ? $target.data(
'referenceview' )
- : $target.closest(
':wikibase-referenceview' ).data( 'referenceview' );
-
- if( !referenceview ) {
- // Unrelated "move"
action.
- return;
- }
-
- var referenceviewLia =
referenceview.options.listItemAdapter,
- $snaklistviews =
referenceview._listview.items();
-
- $snaklistviews.each( function(
i, snaklistviewNode ) {
- var snaklistview =
referenceviewLia.liInstance( $( snaklistviewNode ) );
-
- if(
!snaklistview.value() || !snaklistview.isInEditMode() ) {
- // Do not
handle pending values.
- return;
- }
-
-
snaklistview._listview.items().each( function( j, snakviewNode ) {
- var $snakview =
$( snakviewNode ),
-
movetoolbar = $snakview.data( 'movetoolbar' );
-
- if(
!movetoolbar ) {
- //
Continue if the movetoolbar is not present (the snakview is
- //
pending).
- return;
- }
-
- var
isOverallFirst = ( i === 0 && j === 0 ),
-
isLastSnaklistview = ( i === $snaklistviews.length - 1 ),
-
isLastSnakview = ( j === snaklistview._listview.items().length - 1 ),
-
isOverallLast = ( isLastSnaklistview && isLastSnakview ),
-
hasFollowingSnaklistview = ( $snaklistviews.eq( i + 1 ).length > 0 ),
-
isBeforePending = false;
-
- if(
hasFollowingSnaklistview ) {
- var
nextSnakList = referenceviewLia.liInstance(
-
$snaklistviews.eq( i + 1 )
-
).value();
-
isBeforePending = !nextSnakList;
- }
-
-
movetoolbar.getButton( 'up' ).enable();
-
movetoolbar.getButton( 'down' ).enable();
-
- if(
isOverallFirst ) {
-
movetoolbar.getButton( 'up' ).disable();
- }
-
- if(
isOverallLast || isBeforePending ) {
-
movetoolbar.getButton( 'down' ).disable();
- }
- } );
- } );
-
- // Stop repeatedly triggering
the event on the moved DOM node:
-
event.stopImmediatePropagation();
- }
- );
}
}
}
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index 3f1644d..05f431c 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -78,14 +78,6 @@
},
/**
- * The statement's initial index within the list of statements (if it is
contained within a list
- * of statements). The initial index is stored to be able to detect
whether the index has
- * changed and the statement does not feature its initial value.
- * @type {number|null}
- */
- _initialIndex: null,
-
- /**
* Shortcut to the list item adapter in use in the reference view.
* @type {$.wikibase.listview.ListItemAdapter}
*/
@@ -140,7 +132,6 @@
PARENT.prototype._create.call( this );
this._statement = this.options.value;
- this._initialIndex = this.options.index;
this._createRankSelector( this._statement ?
this._statement.getRank() : null );
this._createMainSnak( this._statement
@@ -319,11 +310,6 @@
var self = this,
references = statement.getReferences();
- function indexOf( element, array ) {
- var index = $.inArray( element, array );
- return ( index !== -1 ) ? index : null;
- }
-
var $listview = this.$references.children();
if( !$listview.length ) {
$listview = $( '<div/>' ).prependTo( this.$references );
@@ -333,15 +319,9 @@
listItemAdapter: new
$.wikibase.listview.ListItemAdapter( {
listItemWidget: $.wikibase.referenceview,
newItemOptionsFn: function( value ) {
- var index = indexOf( value,
self.value().getReferences().toArray() );
- if( index === null ) {
- // The empty list view item for
this is already appended to the list view
- index =
self._referencesListview.items().length - 1;
- }
return {
value: value || null,
statementGuid:
self.value().getClaim().getGuid(),
- index: index,
dataTypeStore: self.option(
'dataTypeStore' ),
entityStore: self.option(
'entityStore' ),
valueViewBuilder: self.option(
'valueViewBuilder' ),
@@ -360,18 +340,6 @@
.on( 'listviewitemadded listviewitemremoved', function( event,
value, $li ) {
if( event.target === $listview.get( 0 ) ) {
self.drawReferencesCounter();
- self._updateReferenceIndices();
- }
- } )
- .on( 'referenceviewafterstopediting', function( event,
dropValue ) {
- if( dropValue ) {
- // Re-order claims according to their initial
indices:
- var $referenceviews =
self._referencesListview.items();
-
- for( var i = 0; i < $referenceviews.length; i++
) {
- var referenceview =
self._referenceviewLia.liInstance( $referenceviews.eq( i ) );
- self._referencesListview.move(
$referenceviews.eq( i ), referenceview.getInitialIndex() );
- }
}
} )
.on( 'listviewenternewitem', function( event, $newLi ) {
@@ -417,8 +385,6 @@
this.$refsHeading.html( $toggler );
this.drawReferencesCounter();
}
-
- this._updateReferenceIndices();
},
/**
@@ -487,10 +453,6 @@
* @return {boolean}
*/
isInitialValue: function() {
- if( this.option( 'index' ) !== this._initialIndex ) {
- return false;
- }
-
if( this._statement ) {
if( this._statement.getRank() !==
this._rankSelector.rank() ) {
return false;
@@ -574,19 +536,6 @@
} );
return references;
- },
-
- /**
- * Updates the reference view indices.
- * @since 0.5
- */
- _updateReferenceIndices: function() {
- var $referenceviews = this._referencesListview.items();
-
- for( var i = 0; i < $referenceviews.length; i++ ) {
- var referenceview = this._referenceviewLia.liInstance(
$referenceviews.eq( i ) );
- referenceview.option( 'index', i );
- }
},
/**
@@ -767,10 +716,7 @@
guid = guidGenerator.newGuid( mw.config.get(
'wbEntityId' ) );
}
- return this.option( 'claimsChanger' ).setStatement(
- this._instantiateStatement( guid ),
- this.option( 'index' )
- )
+ return this.option( 'claimsChanger' ).setStatement(
this._instantiateStatement( guid ) )
.done( function( savedStatement ) {
// Update model of represented Statement:
self._statement = savedStatement;
@@ -831,16 +777,6 @@
this.$mainSnak.data( 'snakview' ).startEditing();
}
} ),
-
- /**
- * Returns the statement's initial index within the list of statements
(if in any).
- * @since 0.5
- *
- * @return {number|null}
- */
- getInitialIndex: function() {
- return this._initialIndex;
- },
/**
* Returns whether the statement is editable at the moment.
@@ -908,8 +844,6 @@
if( this._qualifiers ) {
this._qualifiers.option( key, value );
}
- } else if( key === 'index' && value !== undefined ) {
- this._trigger( 'change' );
}
return response;
@@ -1119,194 +1053,6 @@
}
} );
-$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
- id: 'claim-qualifiers-snak',
- selector: '.wikibase-statementview-qualifiers',
- events: {
- 'snakviewstartediting': function( event, toolbarController ) {
- var $snakview = $( event.target ),
- $snaklistview = $snakview.closest(
':wikibase-snaklistview' ),
- snaklistview = $snaklistview.data(
'snaklistview' );
-
- if( !snaklistview ) {
- return;
- }
-
- var $listview = $snaklistview.closest(
':wikibase-listview' );
-
- if( !$listview.parent().hasClass(
'wikibase-statementview-qualifiers' ) ) {
- return;
- }
-
- var listview = $listview.data( 'listview' );
-
- if( $snaklistview.data( 'snaklistview' ).value() !==
null ) {
- // Create toolbar for each snakview widget:
- $snakview.movetoolbar( {
- $container: $( '<div/>' ).appendTo(
$snakview )
- } );
-
- var $topMostSnakview =
listview.items().first().data( 'snaklistview' )
- ._listview.items().first();
- var $bottomMostSnakview =
listview.items().last().data( 'snaklistview' )
- ._listview.items().last();
-
- if ( $topMostSnakview.get( 0 ) ===
$snakview.get( 0 ) ) {
- $snakview.data( 'movetoolbar'
).getButton( 'up' ).disable();
- }
-
- if( $bottomMostSnakview.get( 0 ) ===
$snakview.get( 0 ) ) {
- $snakview.data( 'movetoolbar'
).getButton( 'down' ).disable();
- }
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'snaklistviewafterstopediting',
- function( event, toolbarcontroller ) {
- // Destroy the snakview
toolbars:
- var $snaklistviewNode = $(
event.target ),
- listview =
$snaklistviewNode.data( 'snaklistview' )._listview,
- lia =
listview.listItemAdapter();
-
- $.each( listview.items(),
function( i, item ) {
- var snakview =
lia.liInstance( $( item ) );
-
toolbarcontroller.destroyToolbar( snakview.element.data( 'movetoolbar' ) );
- } );
-
- // Remove obsolete event
handlers attached to the node the
- // toolbarcontroller has been
initialized on:
- $snaklistviewNode
- .closest(
'.wikibase-statementview-qualifiers' )
- .off( '.movetoolbar' );
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown',
- function( event ) {
- var $snakview = $( event.target
),
- $snaklistview =
$snakview.closest( ':wikibase-snaklistview' );
-
- if( !$snaklistview.length ) {
- // Unrelated "move"
action.
- return;
- }
-
- var snaklistview =
$snaklistview.data( 'snaklistview' ),
- snaklistviewListview =
snaklistview.$listview.data( 'listview' ),
- snaklistviewListviewLia
= snaklistviewListview.listItemAdapter(),
- snak =
snaklistviewListviewLia.liInstance( $snakview ).snak(),
- snakList =
snaklistview.value(),
- $listview =
$snaklistview.closest( ':wikibase-listview' ),
- listview =
$listview.data( 'listview' ),
- action = ( event.type
=== 'movetoolbarup' ) ? 'moveUp' : 'moveDown';
-
- if( action === 'moveUp' &&
snakList.indexOf( snak ) !== 0 ) {
- // Snak is not in top
of the snaklistview group the snaks featuring the same
- // property. Therefore,
the snak is to be moved within the snaklistview.
- snaklistview.moveUp(
snak );
- } else if(
- action === 'moveDown'
- && snakList.indexOf(
snak ) !== snakList.length - 1
- ) {
- // Move down snakview
within a snaklistview.
- snaklistview.moveDown(
snak );
- } else {
- // When issuing "move
up" on a snak on top of a snak list, the whole
- // snaklistview has to
be move; Same for "move down" on a snak at the
- // bottom of a snak
list.
- listview[action](
$snaklistview );
- }
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown
listviewitemadded listviewitemremoved',
- function( event ) {
- // Disable "move up" button of
the topmost snakview of the topmost
- // snaklistview and the "move
down" button of the bottommost snakview of the
- // bottommost snaklistview. All
other buttons shall be enabled.
- var $target = $( event.target ),
- $statementview =
$target.closest( ':wikibase-statementview' ),
- statementview =
$statementview.data( 'statementview' ),
- listview;
-
- if( event.type.indexOf(
'listview' ) !== 0 ) {
- var $snaklistview =
$target.closest( ':wikibase-snaklistview' ),
- $listview =
$snaklistview.closest( ':wikibase-listview' );
- listview =
$listview.data( 'listview' );
- } else if(
-
!$target.parent().hasClass( 'wikibase-statementview-qualifiers' )
- ) {
- // Do not react on
snaklistview's listview event.
- return;
- } else {
- listview =
$target.data( 'listview' );
- }
-
- if( !listview ) {
- // Unrelated "move"
action.
- return;
- }
-
- var listviewItems =
listview.items();
-
- listviewItems.each( function(
i, snaklistviewNode ) {
- var snaklistview = $(
snaklistviewNode ).data( 'snaklistview' );
-
- if(
- !snaklistview
- ||
!snaklistview.value()
- ||
!snaklistview.isInEditMode()
- ) {
- // Pending
snaklistview: Remove the preceding "move down" button if
- // it exists:
- return;
- }
-
- var snaklistviewItems =
snaklistview._listview.items();
-
- snaklistviewItems.each(
function( j, snakviewNode ) {
- var $snakview =
$( snakviewNode ),
-
movetoolbar = $snakview.data( 'movetoolbar' );
-
- // Pending
snakviews do not feature a movetoolbar.
- if( movetoolbar
) {
- var
btnUp = movetoolbar.getButton( 'up' ),
-
btnDown = movetoolbar.getButton( 'down' ),
-
isOverallFirst = ( i === 0 && j === 0 ),
-
isLastInSnaklistview = ( j === snaklistviewItems.length - 1 ),
-
isOverallLast = ( i === listviewItems.length - 1 && isLastInSnaklistview ),
-
hasNextListItem = listviewItems.eq( i + 1 ).length > 0,
-
nextSnaklist = ( hasNextListItem )
-
? listviewItems.eq( i + 1 ).data( 'snaklistview' ).value()
-
: null,
-
nextListItemIsPending = hasNextListItem && (
-
nextSnaklist === null
-
|| statementview._initialQualifiers.indexOf( nextSnaklist.toArray()[0]
) === -1
-
),
-
isBeforePending = isLastInSnaklistview && nextListItemIsPending;
-
- btnUp[
( isOverallFirst ) ? 'disable' : 'enable' ]();
-
btnDown[ ( isOverallLast || isBeforePending ) ? 'disable' : 'enable' ]();
- }
- } );
- } );
-
- // Stop repeatedly triggering
the event on the moved DOM node:
-
event.stopImmediatePropagation();
- }
- );
- }
- }
- }
-} );
-
$.wikibase.toolbarcontroller.definition( 'addtoolbar', {
id: 'references',
selector: '.wikibase-statementview-references',
@@ -1450,104 +1196,6 @@
// Destroying the referenceview will destroy the toolbar.
Trying to destroy the toolbar
// in parallel will cause interference.
- }
-} );
-
-$.wikibase.toolbarcontroller.definition( 'movetoolbar', {
- id: 'statementview-referenceview',
- selector: '.wb-referenceview',
- events: {
- 'referenceviewstartediting': function( event, toolbarController
) {
- // Initialize movetoolbar.
-
- var $referenceview = $( event.target ),
- referenceview = $referenceview.data(
'referenceview' ),
- $statementview = $referenceview.closest(
':wikibase-statementview' ),
- statementview = $statementview.data(
'statementview' ),
- $referencesListview =
statementview.$references.children( ':wikibase-listview' ),
- referencesListview = $referencesListview.data(
'listview' );
-
- if( !referenceview.value() ) {
- // Prevent creating the toolbar for pending
values.
- return;
- }
-
- $referenceview.movetoolbar( {
- $container: $( '<div/>' ).appendTo(
$referenceview )
- } );
-
- // Disable "move up" button of topmost and "move down"
button of bottommost
- // referenceview:
- var $topMostReferenceview =
referencesListview.items().first(),
- $bottomMostReferenceview =
referencesListview.items().last();
-
- if ( $topMostReferenceview.get( 0 ) ===
$referenceview.get( 0 ) ) {
- $referenceview.data( 'movetoolbar' ).getButton(
'up' ).disable();
- }
-
- if( $bottomMostReferenceview.get( 0 ) ===
$referenceview.get( 0 ) ) {
- $referenceview.data( 'movetoolbar' ).getButton(
'down' ).disable();
- }
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'referenceviewafterstopediting',
- function( event, toolbarcontroller ) {
- toolbarcontroller.destroyToolbar( $(
event.target ).data( 'movetoolbar' ) );
- }
- );
-
- toolbarController.registerEventHandler(
- event.data.toolbar.type,
- event.data.toolbar.id,
- 'movetoolbarup movetoolbardown',
- function( event ) {
- var $referenceview = $( event.target ),
- referenceview =
$referenceview.data( 'referenceview' );
-
- if( !referenceview ) {
- // Not the event of the
corresponding toolbar but of some other movetoolbar.
- return;
- }
-
- var $statementview =
$referenceview.closest( ':wikibase-statementview' ),
- statementview =
$statementview.data( 'statementview' ),
- $referencesListview =
statementview.$references.children( ':wikibase-listview' ),
- referencesListview =
$referencesListview.data( 'listview' ),
- action = ( event.type ===
'movetoolbarup' ) ? 'moveUp' : 'moveDown',
- referenceviewIndex =
referencesListview.indexOf( $referenceview ),
- isLastListItem = (
referenceviewIndex !== referencesListview.items().length - 1 );
-
- if( action === 'moveUp' &&
referencesListview.indexOf( $referenceview ) !== 0 ) {
- referencesListview.moveUp(
$referenceview );
- } else if( action === 'moveDown' &&
isLastListItem ) {
- referencesListview.moveDown(
$referenceview );
- }
-
- // Disable "move up" button of topmost
and "move down" button of bottommost
- // referenceview:
- var movetoolbar = $referenceview.data(
'movetoolbar' ),
- $topmostReferenceview =
referencesListview.items().first(),
- isTopmost =
$topmostReferenceview.get( 0 ) === $referenceview.get( 0 ),
- $bottommostReferenceview =
referencesListview.items().last(),
- isBottommost =
$bottommostReferenceview.get( 0 ) === $referenceview.get( 0 );
-
- movetoolbar.getButton( 'up' )[(
isTopmost ) ? 'disable' : 'enable' ]();
- movetoolbar.getButton( 'down' )[(
isBottommost ) ? 'disable' : 'enable' ]();
-
- // Update referenceview indices:
- var $referenceviews =
referencesListview.items(),
- referenceListviewLia =
referencesListview.listItemAdapter();
-
- for( var i = 0; i <
$referenceviews.length; i++ ) {
- referenceview =
referenceListviewLia.liInstance( $referenceviews.eq( i ) );
- referenceview.option( 'index',
i );
- }
- }
- );
-
- }
}
} );
diff --git a/repo/resources/entityChangers/ClaimsChanger.js
b/repo/resources/entityChangers/ClaimsChanger.js
index 5602b0e..14050e3 100644
--- a/repo/resources/entityChangers/ClaimsChanger.js
+++ b/repo/resources/entityChangers/ClaimsChanger.js
@@ -93,7 +93,7 @@
/**
* @param {wikibase.datamodel.Claim} claim
- * @param {number} index
+ * @param {number} [index]
* @return {jQuery.Promise}
* Resolved parameters:
* - {wikibase.datamodel.Claim} The saved claim
@@ -129,7 +129,7 @@
/**
* @param {wikibase.datamodel.Statement} statement
- * @param {number} index
+ * @param {number} [index]
* @return {Object} jQuery.Promise
* Resolved parameters:
* - {wikibase.datamodel.Statement} The saved statement
diff --git a/repo/resources/entityChangers/ReferencesChanger.js
b/repo/resources/entityChangers/ReferencesChanger.js
index 2809188..915ecbe 100644
--- a/repo/resources/entityChangers/ReferencesChanger.js
+++ b/repo/resources/entityChangers/ReferencesChanger.js
@@ -90,7 +90,7 @@
/**
* @param {string} statementGuid
* @param {wikibase.datamodel.Reference} reference
- * @param {number} index
+ * @param {number} [index]
* @return {jQuery.Promise}
* Resolved parameters:
* - {wikibase.datamodel.Reference} The saved reference
diff --git a/repo/resources/wikibase.ui.entityViewInit.js
b/repo/resources/wikibase.ui.entityViewInit.js
index fbf55f0..ee810d7 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -53,12 +53,6 @@
'claim-qualifiers-snak',
'referenceview-snakview-remove',
'sitelinkgroupview-sitelinkview'
- ],
- movetoolbar: [
- 'claimlistview-claimview',
- 'claim-qualifiers-snak',
- 'statementview-referenceview',
- 'referenceview-snakview'
]
};
--
To view, visit https://gerrit.wikimedia.org/r/179101
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfe47d0d24b967b8fa94d3fc8e30212da601cadd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits