Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/355245 )

Change subject: Initialize StatementGroupListView on Lexeme and on Forms 
separately
......................................................................

Initialize StatementGroupListView on Lexeme and on Forms separately

Change-Id: Ib69f803c492d7e8521523ef876d67d1517e836f6
---
M resources/jquery.wikibase.lexemeformlistview.js
M resources/jquery.wikibase.lexemeformview.js
M resources/jquery.wikibase.lexemeview.js
M resources/view/ControllerViewFactory.js
4 files changed, 50 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/45/355245/1

diff --git a/resources/jquery.wikibase.lexemeformlistview.js 
b/resources/jquery.wikibase.lexemeformlistview.js
index f06d4ed..abaea0e 100644
--- a/resources/jquery.wikibase.lexemeformlistview.js
+++ b/resources/jquery.wikibase.lexemeformlistview.js
@@ -59,7 +59,8 @@
                _createListView: function () {
                        this._listview = new $.wikibase.listview( {
                                listItemAdapter: 
this.options.getListItemAdapter( this._removeItem.bind( this ) ),
-                               listItemNodeName: 'div'
+                               listItemNodeName: 'div',
+                               value: this.options.value
                        }, this.element.find( '.wikibase-lexeme-forms' ) );
 
                },
diff --git a/resources/jquery.wikibase.lexemeformview.js 
b/resources/jquery.wikibase.lexemeformview.js
index 1b10d68..081caa0 100644
--- a/resources/jquery.wikibase.lexemeformview.js
+++ b/resources/jquery.wikibase.lexemeformview.js
@@ -4,6 +4,13 @@
        var PARENT = $.ui.EditableTemplatedWidget;
 
        /**
+        * Initializes StatementGroupListView on given DOM element
+        * @callback buildStatementGroupListView
+        * @param {wikibase.datamodel.LexemeForm}
+        * @param {jQuery} JQuery DOM element
+        */
+
+       /**
         * @class jQuery.wikibase.lexemeformview
         * @extends jQuery.ui.EditableTemplatedWidget
         * @license GPL-2.0+
@@ -35,11 +42,22 @@
                                $grammaticalFeatures: 
'.wikibase-lexeme-form-grammatical-features'
                        },
                        inputNodeName: 'TEXTAREA',
-                       buildGrammaticalFeatureView: null
+                       buildGrammaticalFeatureView: null,
+
+                       /**
+                        * @type {buildStatementGroupListView}
+                        */
+                       buildStatementGroupListView: null
                },
                _inEditMode: false,
 
                _grammaticalFeatureView: null,
+
+               /**
+                * @property {jQuery}
+                * @readonly
+                */
+               $statements: null,
 
                /**
                 * This method acts as a setter if it is given a LexemeForm 
object.
@@ -68,6 +86,15 @@
                },
 
                _create: function () {
+                       this.$statements = $( 
'.wikibase-statementgrouplistview', this.element );
+                       if ( this.$statements.length === 0 ) {
+                               this.$statements = $( '<div/>' );
+                       } else {
+                               this.options.buildStatementGroupListView(
+                                       this.value(),
+                                       this.$statements
+                               );
+                       }
                        PARENT.prototype._create.call( this );
                        this._grammaticalFeatureView = 
this._buildGrammaticalFeatureView();
 
diff --git a/resources/jquery.wikibase.lexemeview.js 
b/resources/jquery.wikibase.lexemeview.js
index a2648ce..a84467f 100644
--- a/resources/jquery.wikibase.lexemeview.js
+++ b/resources/jquery.wikibase.lexemeview.js
@@ -41,7 +41,7 @@
                _create: function () {
                        this._createEntityview();
 
-                       this.$statements = $( 
'.wikibase-statementgrouplistview', this.element );
+                       this.$statements = $( '.wikibase-entityview-main > 
.wikibase-statementgrouplistview', this.element );
                        if ( this.$statements.length === 0 ) {
                                this.$statements = $( '<div/>' ).appendTo( 
this.$main );
                        }
diff --git a/resources/view/ControllerViewFactory.js 
b/resources/view/ControllerViewFactory.js
index 2c8f108..5e9de3a 100644
--- a/resources/view/ControllerViewFactory.js
+++ b/resources/view/ControllerViewFactory.js
@@ -56,44 +56,53 @@
                                buildEntityTermsView: 
this.getEntityTermsView.bind( this, startEditingCallback ),
                                buildSitelinkGroupListView: 
this.getSitelinkGroupListView.bind( this, startEditingCallback ),
                                buildStatementGroupListView: 
this.getStatementGroupListView.bind( this, startEditingCallback ),
-                               buildLexemeFormListView: 
this.getLexemeFormListView.bind( this, startEditingCallback ),
+                               buildLexemeFormListView: 
this.getLexemeFormListView.bind( this, entity, startEditingCallback ),
                                value: entity
                        }
                );
        };
 
-       SELF.prototype.getLexemeFormListView = function ( startEditingCallback 
) {
+       SELF.prototype.getLexemeFormListView = function ( lexeme, 
startEditingCallback ) {
 
                return this._getView(
                        'lexemeformlistview',
                        $( '.wikibase-lexeme-forms-section' ),
                        {
                                getListItemAdapter: 
this.getListItemAdapterForLexemeFormListView.bind( this, startEditingCallback ),
-                               getAdder: this._getAdderWithStartEditing( 
startEditingCallback )
+                               getAdder: this._getAdderWithStartEditing( 
startEditingCallback ),
+                               value: lexeme.forms
                        }
                );
        };
 
-       SELF.prototype.getLexemeFormView = function ( value, 
labelFormattingService, $dom, startEditingCallback, removeCallback ) {
+       SELF.prototype.getLexemeFormView = function ( form, 
labelFormattingService, $dom, startEditingCallback, removeCallback ) {
                var self = this;
 
                var lexemeFormView = this._getView(
-                       'lexemeformview',
-                       $dom,
-                       { value: value, labelFormattingService: 
labelFormattingService, api: self._api }
+                               'lexemeformview',
+                               $dom,
+                               {
+                                       value: form,
+                                       labelFormattingService: 
labelFormattingService,
+                                       api: self._api,
+                                       buildStatementGroupListView: 
this.getStatementGroupListView.bind(
+                                               this,
+                                               startEditingCallback
+                                       )
+                               }
                        ),
                        controller = this._getController(
                                this._toolbarFactory.getToolbarContainer( 
lexemeFormView.element ),
                                lexemeFormView,
                                fakeModel,
                                removeCallback,
-                               value,
+                               form,
                                startEditingCallback
                        );
 
                // Empty formviews (added with the "add" button) should start 
in edit mode
-               if ( !value ) {
-                       controller.startEditing().done( $.proxy( 
lexemeFormView, 'focus' ) );
+               if ( !form ) {
+                       controller.startEditing().done( 
lexemeFormView.focus.bind(lexemeFormView)  );
                }
 
                return lexemeFormView;
@@ -157,14 +166,6 @@
                        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(),
-                                               
self._getExistingGrammaticalFeatures( $element )
-                                       );
-                               }
 
                                view = self.getLexemeFormView(
                                        value || null, // FIXME: if this is 
undefined instead of null, things break

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib69f803c492d7e8521523ef876d67d1517e836f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>

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

Reply via email to