jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348756 )

Change subject: Enable editing of forms in the form list view.
......................................................................


Enable editing of forms in the form list view.

This adds a new ControllerViewFactory in order to wire together the
lexemeview, lexemeformlistview and lexemeformview including the toolbar
and ToolbarViewController for lexemeformview which are needed for
editing.

It also adds an intial LexemeForm model for the datamodel frontend
which at the moment does not inherit from Entity. It is only needed to
provide the equals-method for the ToolbarControllerView.

Persistence is not implemented yet. It uses a fake model instead of an
EntityChanger that always resolves the "save" promise.

Bug: T162339
Bug: T162340
Bug: T162341
Change-Id: Ie36d5e5dbd80706f26f91d57abe742decfad3c3d
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M phpcs.xml
A resources/datamodel/LexemeForm.js
A resources/jquery.wikibase.lexemeformlistview.js
D resources/jquery.wikibase.lexemeformsectionview.js
M resources/jquery.wikibase.lexemeformview.js
M resources/jquery.wikibase.lexemeview.js
M resources/lexeme.css
M resources/templates.php
A resources/view/ControllerViewFactory.js
A resources/view/__namespace.js
M src/Rdf/LexemeRdfBuilder.php
M src/View/LexemeFormsView.php
M tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
16 files changed, 401 insertions(+), 137 deletions(-)

Approvals:
  WMDE-leszek: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 3029636..7888c1b 100644
--- a/extension.json
+++ b/extension.json
@@ -46,8 +46,9 @@
                "jquery.wikibase.lexemeview": {
                        "scripts": "jquery.wikibase.lexemeview.js",
                        "dependencies": [
+                               "wikibase.lexeme.view.ControllerViewFactory",
                                "jquery.wikibase.entityview",
-                               "jquery.wikibase.lexemeformsectionview"
+                               "jquery.wikibase.lexemeformlistview"
                        ]
                },
                "wikibase.lexeme": {
@@ -60,8 +61,8 @@
                                "wikibase.lexeme.getDeserializer"
                        ]
                },
-               "jquery.wikibase.lexemeformsectionview": {
-                       "scripts": "jquery.wikibase.lexemeformsectionview.js",
+               "jquery.wikibase.lexemeformlistview": {
+                       "scripts": "jquery.wikibase.lexemeformlistview.js",
                        "dependencies": [
                                "jquery.wikibase.lexemeformview",
                                "jquery.ui.widget"
@@ -72,6 +73,10 @@
                        "dependencies": [
                                "wikibase.templates.lexeme",
                                "jquery.ui.EditableTemplatedWidget"
+                       ],
+                       "messages": [
+                               "wikibase-lexeme-empty-form-representation",
+                               "wikibase-lexeme-enter-form-representation"
                        ]
                },
                "wikibase.templates.lexeme": {
@@ -91,6 +96,16 @@
                                "wikibase.datamodel.Fingerprint",
                                "wikibase.datamodel.StatementGroupSet",
                                "wikibase.datamodel.TermMap",
+                               "wikibase.lexeme"
+                       ]
+               },
+               "wikibase.lexeme.datamodel.LexemeForm": {
+                       "scripts": [
+                               "datamodel/__namespace.js",
+                               "datamodel/LexemeForm.js"
+                       ],
+                       "dependencies": [
+                               "util.inherit",
                                "wikibase.lexeme"
                        ]
                },
@@ -173,6 +188,18 @@
                                
"wikibase.lexeme.special.formHelpers.LexemeLanguageFieldObserver"
                        ]
                },
+               "wikibase.lexeme.view.ControllerViewFactory": {
+                       "scripts": [
+                               "view/__namespace.js",
+                               "view/ControllerViewFactory.js"
+                       ],
+                       "dependencies": [
+                               "util.inherit",
+                               "wikibase.view.ControllerViewFactory",
+                               "wikibase.lexeme.datamodel.LexemeForm",
+                               "wikibase.lexeme"
+                       ]
+               },
                "wikibase.lexeme.config.LexemeLanguageCodePropertyIdConfig": {
                        "class": 
"Wikibase\\Lexeme\\Config\\LexemeLanguageCodePropertyIdConfig"
                },
diff --git a/i18n/en.json b/i18n/en.json
index ff7e857..3a42f9f 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -12,6 +12,8 @@
        "wikibase-newlexeme-language": "Language of lexeme",
        "wikibase-lexeme-view-language-lexical-category": "$1 in $2",
        "wikibase-lexeme-view-forms": "Forms",
+       "wikibase-lexeme-enter-form-representation": "Enter new form 
representation",
+       "wikibase-lexeme-empty-form-representation": "No form representation 
defined",
        "wikibase-lexeme-view-senses": "Senses",
        "wikibase-lexeme-summary-wbeditentity-update": "Changed a lexeme"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 5a3b02c..62a8270 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -17,6 +17,8 @@
        "wikibase-newlexeme-language": "Label for field in the lexeme creation 
form.",
        "wikibase-lexeme-view-language-lexical-category": "Description when 
both lexical category and language are present\n{{Identical|In}}",
        "wikibase-lexeme-view-forms": "Subheading for the forms section on a 
lexeme page.\n{{Identical|Form}}",
+       "wikibase-lexeme-enter-form-representation": "Placeholder for the 
lexeme form representation input field.",
+       "wikibase-lexeme-empty-form-representation": "Placeholder message 
displayed instead of the lexeme form representation in case no representation 
has been specified yet.",
        "wikibase-lexeme-view-senses": "Subheading for the senses section on a 
lexeme page.\n{{Identical|Sense}}",
        "wikibase-lexeme-summary-wbeditentity-update": "Auto-generated edit 
summary when editing a lexeme"
 }
diff --git a/phpcs.xml b/phpcs.xml
index 9df75b3..7f79f05 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -8,6 +8,9 @@
        <rule ref="Generic.CodeAnalysis.UnconditionalIfStatement" />
        <rule ref="Generic.ControlStructures" />
        <rule ref="Generic.Files.InlineHTML" />
+       <rule ref="Generic.Files.LineLength">
+               <exclude-pattern>resources/templates\.php</exclude-pattern>
+       </rule>
        <rule ref="Generic.Files.OneInterfacePerFile" />
        <rule ref="Generic.Files.OneTraitPerFile" />
        <rule ref="Generic.Metrics.CyclomaticComplexity" />
diff --git a/resources/datamodel/LexemeForm.js 
b/resources/datamodel/LexemeForm.js
new file mode 100644
index 0000000..9416534
--- /dev/null
+++ b/resources/datamodel/LexemeForm.js
@@ -0,0 +1,53 @@
+( function ( wb, util ) {
+       'use strict';
+
+       /**
+        * @param {string} id
+        * @param {string} representation
+        */
+       var LexemeForm = util.inherit(
+               'LexemeForm',
+               function ( id, representation ) {
+                       this._id = id;
+                       this._representation = representation;
+               },
+               {
+
+                       /**
+                        * @type {string}
+                        */
+                       _id: null,
+
+                       /**
+                        * @type {string}
+                        */
+                       _representation: null,
+
+                       /**
+                        * @return {string}
+                        */
+                       getId: function () {
+                               return this._id;
+                       },
+
+                       /**
+                        * @return {string}
+                        */
+                       getRepresentation: function () {
+                               return this._representation;
+                       },
+
+                       /**
+                        * @param {LexemeForm} form
+                        * @return {boolean}
+                        */
+                       equals: function ( form ) {
+                               return form instanceof LexemeForm
+                                       && this.getId() === form.getId()
+                                       && this.getRepresentation() === 
form.getRepresentation()
+                       }
+               } );
+
+       wb.lexeme.datamodel.LexemeForm = LexemeForm;
+
+}( wikibase, util ) );
diff --git a/resources/jquery.wikibase.lexemeformlistview.js 
b/resources/jquery.wikibase.lexemeformlistview.js
new file mode 100644
index 0000000..6c2390f
--- /dev/null
+++ b/resources/jquery.wikibase.lexemeformlistview.js
@@ -0,0 +1,88 @@
+( function ( $ ) {
+       'use strict';
+
+       var PARENT = $.Widget;
+
+       /**
+        * @class jQuery.wikibase.lexemeformlistview
+        * @extends jQuery.ui.Widget
+        * @license GPL-2.0+
+        *
+        * @constructor
+        *
+        * @param {Object} options
+        * @param {jquery.wikibase.listview.ListItemAdapter} 
options.getListItemAdapter
+        * @param {jQuery.wikibase.addtoolbar} options.getAdder
+        * @param {wikibase.lexeme.datamodel.LexemeForm} options.value
+        */
+       $.widget( 'wikibase.lexemeformlistview', PARENT, {
+               /**
+                * @inheritdoc
+                * @protected
+                */
+               options: {
+                       getListItemAdapter: null,
+                       getAdder: null,
+                       value: null
+               },
+
+               /**
+                * @type {jQuery.wikibase.listview}
+                * @private
+                */
+               _listview: null,
+
+               /**
+                * @inheritdoc
+                */
+               _create: function () {
+                       PARENT.prototype._create.call( this );
+
+                       this._createListView();
+                       this.options.getAdder( this.enterNewItem.bind( this ), 
this.element );
+               },
+
+               /**
+                * @inheritdoc
+                * @protected
+                */
+               destroy: function() {
+                       this._listview.destroy();
+                       PARENT.prototype.destroy.call( this );
+               },
+
+               /**
+                * Creates the `listview` widget managing the `lexemeformview` 
widgets.
+                *
+                * @private
+                */
+               _createListView: function() {
+                       this._listview = new $.wikibase.listview( {
+                               listItemAdapter: 
this.options.getListItemAdapter( this._removeItem.bind( this ) ),
+                               listItemNodeName: 'div'
+                       }, this.element.find( '.wikibase-lexeme-forms' ) );
+
+               },
+
+               /**
+                * Adds a new, pending `lexemeformview` to the 
`lexemeformlistview`.
+                *
+                * @see jQuery.wikibase.listview.enterNewItem
+                * @return {jQuery.Promise}
+                */
+               enterNewItem: function() {
+                       return this._listview.enterNewItem();
+               },
+
+               /**
+                * Removes a `lexemeformview` widget.
+                *
+                * @param {jQuery.wikibase.lexemeformview} lexemeformview
+                */
+               _removeItem: function( lexemeformview ) {
+                       this._listview.removeItem( lexemeformview.element );
+                       this._trigger( 'afterremove' );
+               },
+
+       } );
+}( jQuery ) );
diff --git a/resources/jquery.wikibase.lexemeformsectionview.js 
b/resources/jquery.wikibase.lexemeformsectionview.js
deleted file mode 100644
index b2695d8..0000000
--- a/resources/jquery.wikibase.lexemeformsectionview.js
+++ /dev/null
@@ -1,66 +0,0 @@
-( function ( $ ) {
-       'use strict';
-
-       var PARENT = $.Widget;
-
-       /**
-        * @class jQuery.wikibase.lexemeformsectionview
-        * @extends jQuery.ui.Widget
-        * @license GPL-2.0+
-        *
-        * @constructor
-        *
-        * @param {Object} options
-        * @param {wikibase.datamodel.Forms} options.value
-        */
-       $.widget( 'wikibase.lexemeformsectionview', PARENT, {
-               /**
-                * @inheritdoc
-                * @protected
-                */
-               options: {
-                       value: null //list of forms?
-               },
-
-               /**
-                * @inheritdoc
-                */
-               _create: function () {
-                       this._attachEventHandlers();
-
-                       var listItemAdapter = new 
$.wikibase.listview.ListItemAdapter({
-                               listItemWidget: $.wikibase.lexemeformview,
-                               getNewItem: function ( arg1, element ) {
-                                       return $.wikibase.lexemeformview( {}, 
$( element ) )
-                               }
-                       });
-                       var listview = new $.wikibase.listview(
-                               {
-                                       listItemAdapter: listItemAdapter,
-                                       listItemNodeName: 'h3'
-                               },
-                               $( '.wikibase-lexeme-forms' )
-                       );
-
-                       var $toolbarContainer = $( '<div 
class="wikibase-addtoolbar-container wikibase-toolbar-container"></div>' );
-                       this.element.append( $toolbarContainer );
-
-                       new $.wikibase.addtoolbar( {
-                               add: function () {
-                                       listview.enterNewItem();
-                               }
-                       }, $toolbarContainer )
-               },
-
-               /**
-                * @protected
-                */
-               _attachEventHandlers: function () {
-                       var element = this.element;
-                       element.on( 'click.' + this.widgetName, 
'.wb-section-heading', function () {
-                               element.find( '.wikibase-lexeme-forms' 
).toggle();
-                       } );
-               }
-
-       } );
-}( jQuery ) );
diff --git a/resources/jquery.wikibase.lexemeformview.js 
b/resources/jquery.wikibase.lexemeformview.js
index 6f3b781..2a55ef8 100644
--- a/resources/jquery.wikibase.lexemeformview.js
+++ b/resources/jquery.wikibase.lexemeformview.js
@@ -4,8 +4,8 @@
        var PARENT = $.ui.EditableTemplatedWidget;
 
        /**
-        * @class jQuery.wikibase.lexemeformsectionview
-        * @extends jQuery.ui.Widget
+        * @class jQuery.wikibase.lexemeformview
+        * @extends jQuery.ui.EditableTemplatedWidget
         * @license GPL-2.0+
         *
         * @constructor
@@ -23,30 +23,55 @@
                                '',
                                function () {
                                        return '';
-                               }
+                               },
+                               ''
                        ],
+                       templateShortCuts: {
+                               $text: '.wikibase-lexeme-form-text',
+                               $id: '.wikibase-lexeme-form-id'
+                       },
                        inputNodeName: 'TEXTAREA'
                },
                _inEditMode: false,
 
-               value: function () {
-                       return this.element.text().trim();
+               /**
+                * This method acts as a setter if it is given a LexemeForm 
object.
+                * Otherwise it returns its value if it is not in edit mode and 
returns a new LexemeForm from its
+                * input value otherwise.
+                *
+                * @param {wikibase.lexeme.datamodel.LexemeForm} value
+                * @returns {wikibase.lexeme.datamodel.LexemeForm|undefined}
+                */
+               value: function ( value ) {
+                       if ( value instanceof wb.lexeme.datamodel.LexemeForm ) {
+                               this.option( 'value', value );
+                               return;
+                       }
+
+                       if ( !this.isInEditMode() ) {
+                               return this.options.value;
+                       }
+
+                       return new wb.lexeme.datamodel.LexemeForm(
+                               Math.round( Math.random() * 100 ), // TODO: 
should be a unique numeric ID per form
+                               $.trim( this.$text.children( this.inputNodeName 
).val() )
+                       );
                },
                _create: function () {
                        PARENT.prototype._create.call( this );
-                       if (this.value() === '') {
+                       if ( !this.value() ) {
                                this.startEditing();
                        }
                },
-               _startEditing: function() {
+               _startEditing: function () {
                        // FIXME: This could be much faster
                        this._inEditMode = true;
                        return this.draw();
                },
-               _stopEditing: function( dropValue ) {
+               _stopEditing: function ( dropValue ) {
                        this._inEditMode = false;
-                       if ( dropValue && this.options.value() === '' ) {
-                               this.$text.children( '.' + this.widgetFullName 
+ '-input' ).val( '' );
+                       if ( dropValue && 
this.options.value.getRepresentation() === '' ) {
+                               this.$text.children( this.inputNodeName ).val( 
'' );
                        }
 
                        return this.draw();
@@ -57,19 +82,17 @@
                /**
                 * @inheritdoc
                 */
-               draw: function() {
-                       var self = this,
-                               deferred = $.Deferred(),
-                               value = this.value();
-
-                       if ( value === '' ) {
+               draw: function () {
+                       var deferred = $.Deferred(),
+                               value = this.options.value;
+                       if ( !value || value.getRepresentation() === '' ) {
                                value = null;
                        }
 
                        this.element.toggleClass( 'wb-empty', !value );
 
                        if ( !this.isInEditMode() && !value ) {
-                               this.$text.text( mw.msg( 'wikibase-label-empty' 
) );
+                               this.$text.text( mw.msg( 
'wikibase-lexeme-empty-form-representation' ) );
                                // Apply lang and dir of UI language
                                // instead language of that row
                                var userLanguage = mw.config.get( 
'wgUserLanguage' );
@@ -79,37 +102,27 @@
                                return deferred.resolve().promise();
                        }
 
-
                        if ( !this.isInEditMode() ) {
-                               this.$text.text( value );
+                               this.$text.text( value.getRepresentation() );
+                               this.$id.text( ' (F' + value.getId() + ')' ); 
// TODO: whitespace and brackets (?) should be i18nable
+
                                return deferred.resolve().promise();
                        }
 
-                       var $input = $( document.createElement( 
this.options.inputNodeName ) );
-
-                       $input
-                               .addClass( this.widgetFullName + '-input' )
-                               .on( 'keydown.' + this.widgetName, function( 
event ) {
-                                       if ( event.keyCode === 
$.ui.keyCode.ENTER ) {
-                                               event.preventDefault();
-                                       }
-                               } )
-                               .on( 'eachchange.' + this.widgetName, function( 
event ) {
-                                       self._trigger( 'change' );
-                               } );
+                       var $input = $( document.createElement( 
this.options.inputNodeName ) )
+                               .attr( 'placeholder', mw.msg( 
'wikibase-lexeme-enter-form-representation' ) );
 
                        if ( value ) {
-                               $input.val( value );
+                               $input.val( value.getRepresentation() );
                        }
 
                        if ( $.fn.inputautoexpand ) {
                                $input.inputautoexpand( {
-                                       expandHeight: true,
                                        suppressNewLine: true
                                } );
                        }
 
-                       this.element.empty().append( $input );
+                       this.$text.empty().append( $input );
 
                        return deferred.resolve().promise();
                }
diff --git a/resources/jquery.wikibase.lexemeview.js 
b/resources/jquery.wikibase.lexemeview.js
index d3e7a83..92c1b4b 100644
--- a/resources/jquery.wikibase.lexemeview.js
+++ b/resources/jquery.wikibase.lexemeview.js
@@ -23,7 +23,8 @@
                 * @protected
                 */
                options: {
-                       buildStatementGroupListView: null
+                       buildStatementGroupListView: null,
+                       buildLexemeFormListView: null
                },
 
                /**
@@ -44,10 +45,7 @@
                                this.$statements = $( '<div/>' ).appendTo( 
this.$main );
                        }
 
-                       new $.wikibase.lexemeformsectionview(
-                               {},
-                               $( '.wikibase-lexeme-forms-section' )
-                       );
+                       this.options.buildLexemeFormListView();
                },
 
                /**
@@ -55,7 +53,7 @@
                 * @protected
                 */
                _init: function() {
-                       if ( !this.options.buildStatementGroupListView ) {
+                       if ( !this.options.buildStatementGroupListView || 
!this.options.buildLexemeFormListView ) {
                                throw new Error( 'Required option(s) missing' );
                        }
 
diff --git a/resources/lexeme.css b/resources/lexeme.css
index 9a50d86..8e7bdf6 100644
--- a/resources/lexeme.css
+++ b/resources/lexeme.css
@@ -13,9 +13,37 @@
        width: 60%;
 }
 
-.wikibase-lexeme-form-representation {
+.wikibase-lexeme-forms .wikibase-lexeme-form {
+       position: relative;
+       clear: left;
+}
+
+.wikibase-lexeme-forms .wikibase-lexeme-form-representation {
        clear: left;
        margin-left: 10px; /* same as .wb-section-heading */
+       position: relative;
+       border-bottom: 1px solid #a2a9b1;
+       font-weight: normal;
+}
+
+.wikibase-lexeme-form-representation .wikibase-toolbar-container {
+       font-size: 0.833em; /* reset from h3 size to 100% for toolbar alignment 
*/
+}
+
+.wikibase-lexeme-forms .wikibase-lexeme-form-representation textarea {
+       display: inline-block;
+       font-size: 0.9em;
+       height: 1.5em;
+       vertical-align: middle;
+}
+
+.wikibase-lexeme-form-representation .wikibase-lexeme-form-id {
+       color: #72777d;
+}
+
+.wikibase-lexeme-forms-section > .wikibase-toolbar-container {
+       position: static;
+       float: left;
 }
 
 .wikibase-lexeme-form-grammatical-features {
diff --git a/resources/templates.php b/resources/templates.php
index 5df52ea..ec34183 100644
--- a/resources/templates.php
+++ b/resources/templates.php
@@ -16,17 +16,15 @@
 
        $templates['wikibase-lexeme-form'] = <<<'HTML'
 <div class="wikibase-lexeme-form">
-       <h3 class="wikibase-lexeme-form-representation" lang="$1">$2 $3</h3>
+       <h3 class="wikibase-lexeme-form-representation" lang="$1">
+               <span class="wikibase-lexeme-form-text">$2</span>
+               <span class="wikibase-lexeme-form-id wikibase-title-id"> 
$3</span>
+       </h3>
        <div class="wikibase-lexeme-form-grammatical-features">
                <div 
class="wikibase-lexeme-form-grammatical-features-header">Grammatical 
features</div>
                <div 
class="wikibase-lexeme-form-grammatical-features-values">$4</div>
        </div>
 </div>
-HTML;
-
-       //TODO Join these templates
-       $templates['wikibase-lexeme-form-id'] = <<<'HTML'
-<span class="wikibase-lexeme-form-id wikibase-title-id">$1</span>
 HTML;
 
        return $templates;
diff --git a/resources/view/ControllerViewFactory.js 
b/resources/view/ControllerViewFactory.js
new file mode 100644
index 0000000..b788ba7
--- /dev/null
+++ b/resources/view/ControllerViewFactory.js
@@ -0,0 +1,136 @@
+( function ( mw, wb, $ ) {
+       'use strict';
+
+       var PARENT = wb.view.ControllerViewFactory;
+
+       var SELF = util.inherit(
+               PARENT,
+               function (
+                       toolbarFactory,
+                       entityChangersFactory,
+                       structureEditorFactory,
+                       contentLanguages,
+                       dataTypeStore,
+                       entityIdHtmlFormatter,
+                       entityIdPlainFormatter,
+                       entityStore,
+                       expertStore,
+                       formatterFactory,
+                       messageProvider,
+                       parserStore,
+                       userLanguages,
+                       vocabularyLookupApiUrl,
+                       commonsApiUrl
+               ) {
+                       PARENT.apply( this, [
+                               toolbarFactory,
+                               entityChangersFactory,
+                               structureEditorFactory,
+                               contentLanguages,
+                               dataTypeStore,
+                               entityIdHtmlFormatter,
+                               entityIdPlainFormatter,
+                               entityStore,
+                               expertStore,
+                               formatterFactory,
+                               messageProvider,
+                               parserStore,
+                               userLanguages,
+                               vocabularyLookupApiUrl,
+                               commonsApiUrl
+                       ] );
+               }
+       );
+
+       SELF.prototype.getEntityView = function ( startEditingCallback, entity, 
$entityview ) {
+               return this._getView(
+                       entity.getType() + 'view',
+                       $entityview,
+                       {
+                               buildEntityTermsView: 
this.getEntityTermsView.bind( this, startEditingCallback ),
+                               buildSitelinkGroupListView: 
this.getSitelinkGroupListView.bind( this, startEditingCallback ),
+                               buildStatementGroupListView: 
this.getStatementGroupListView.bind( this, startEditingCallback ),
+                               buildLexemeFormListView: 
this.getLexemeFormListView.bind( this, startEditingCallback ),
+                               value: entity
+                       }
+               );
+       };
+
+       SELF.prototype.getLexemeFormListView = function ( startEditingCallback 
) {
+
+               return this._getView(
+                       'lexemeformlistview',
+                       $( '.wikibase-lexeme-forms-section' ),
+                       {
+                               getListItemAdapter: 
this.getListItemAdapterForLexemeFormListView.bind( this, startEditingCallback ),
+                               getAdder: this._getAdderWithStartEditing( 
startEditingCallback )
+                       }
+               );
+       };
+
+       var fakeModel = { // FIXME: replace with EntityChanger
+               save: function ( value ) {
+                       var deferred = $.Deferred();
+                       deferred.resolve( value );
+                       return deferred.promise();
+               }
+       };
+
+       SELF.prototype.getLexemeFormView = function ( value, $dom, 
startEditingCallback, removeCallback ) {
+               var lexemeFormView = this._getView(
+                       'lexemeformview',
+                       $dom,
+                       { value: value }
+                       ),
+                       controller = this._getController(
+                               this._toolbarFactory.getToolbarContainer( 
lexemeFormView.element ),
+                               lexemeFormView,
+                               fakeModel,
+                               removeCallback,
+                               value,
+                               startEditingCallback
+                       );
+
+               // Empty formviews (added with the "add" button) should start 
in edit mode
+               if ( !value ) {
+                       controller.startEditing()
+                               .done( $.proxy( lexemeFormView, 'focus' ) );
+               }
+
+               return lexemeFormView;
+       };
+
+       SELF.prototype.getListItemAdapterForLexemeFormListView = function ( 
startEditingCallback, removeCallback ) {
+               var self = this,
+                       view,
+                       doRemove = function() {
+                               return removeCallback( view );
+                       };
+
+               return new $.wikibase.listview.ListItemAdapter( {
+                       listItemWidget: $.wikibase.lexemeformview,
+                       getNewItem: function ( value, element ) {
+                               var $element = $( element );
+
+                               if ( $element.text() !== '' ) { // FIXME: 
values should come from lexeme object
+                                       value = new 
wb.lexeme.datamodel.LexemeForm(
+                                               $element.find( 
'.wikibase-lexeme-form-id' ).text().match( /\d+/ )[0],
+                                               $element.find( 
'.wikibase-lexeme-form-text' ).text()
+                                       );
+                               }
+
+                               view = self.getLexemeFormView(
+                                       value || null, // FIXME: if this is 
undefined instead of null, things break
+                                       $element,
+                                       startEditingCallback,
+                                       doRemove // FIXME: This is not doing 
the right thing
+                               );
+
+                               return view;
+                       }
+               } );
+       };
+
+       wb.lexeme.view.ControllerViewFactory = SELF;
+
+}( mediaWiki, wikibase, jQuery ) );
diff --git a/resources/view/__namespace.js b/resources/view/__namespace.js
new file mode 100644
index 0000000..d66dbe9
--- /dev/null
+++ b/resources/view/__namespace.js
@@ -0,0 +1 @@
+wikibase.lexeme.view = wikibase.lexeme.view || {};
diff --git a/src/Rdf/LexemeRdfBuilder.php b/src/Rdf/LexemeRdfBuilder.php
index 0b48afe..476268e 100755
--- a/src/Rdf/LexemeRdfBuilder.php
+++ b/src/Rdf/LexemeRdfBuilder.php
@@ -47,7 +47,6 @@
         */
        public function addLemmas( $entityLName, TermList $lemmas ) {
                foreach ( $lemmas->toTextArray() as $lemmaCode => $lemmaText ) {
-
                        $this->writer->about( RdfVocabulary::NS_ENTITY, 
$entityLName )
                                ->say( 'rdfs', 'label' )
                                ->text( $lemmaText, $lemmaCode )
diff --git a/src/View/LexemeFormsView.php b/src/View/LexemeFormsView.php
index cf20666..55121b6 100644
--- a/src/View/LexemeFormsView.php
+++ b/src/View/LexemeFormsView.php
@@ -74,7 +74,8 @@
                return $this->templateFactory->render( 'wikibase-lexeme-form', [
                        'some language',
                        htmlspecialchars( $representation ),
-                       $this->getFormIdHtml( $form->getId() ),
+                       wfMessage( 'parentheses' )->rawParams( 
htmlspecialchars( $form->getId()->getSerialization() ) )
+                               ->text(),
                        implode(
                                $this->textProvider->get( 'comma-separator' ),
                                array_map(
@@ -93,24 +94,6 @@
         */
        private function getGrammaticalFeatureHtml( ItemId $id ) {
                return $this->entityIdHtmlFormatter->formatEntityId( $id );
-       }
-
-       /**
-        * @param LexemeFormId|null $id
-        *
-        * @return string HTML
-        */
-       private function getFormIdHtml( LexemeFormId $id = null ) {
-               if ( $id === null ) {
-                       return '';
-               }
-
-               // TODO: Use an existing message instead of the hard coded space
-               return $this->templateFactory->render(
-                       'wikibase-lexeme-form-id',
-                       wfMessage( 'parentheses' )->rawParams( 
htmlspecialchars( $id->getSerialization() ) )
-                               ->text()
-               );
        }
 
 }
diff --git a/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php 
b/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
index 709952e..096a1a6 100644
--- a/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
+++ b/tests/phpunit/mediawiki/View/LexemeFormsViewTest.php
@@ -89,7 +89,6 @@
                        new DummyLocalizedTextProvider(),
                        new LexemeTemplateFactory( [
                                'wikibase-lexeme-form' => '<h3 lang="$1">$2 $3 
$4</h3>',
-                               'wikibase-lexeme-form-id' => '$1',
                        ] ),
                        new EntityIdHtmlLinkFormatter(
                                $this->getMock( LabelDescriptionLookup::class ),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie36d5e5dbd80706f26f91d57abe742decfad3c3d
Gerrit-PatchSet: 20
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Jakob <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Jakob <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to