Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/203499

Change subject: Allow citoid inspector to work within the basic reference dialog
......................................................................

Allow citoid inspector to work within the basic reference dialog

Avoid staging and insertion of <ref> if we are already in the
basic reference dialog.

Bug: T94621
Change-Id: I510ad0425c682c19897c39896770bb5216fab042
---
M Citoid.php
M modules/ve.ui.CiteFromIdInspector.js
M modules/ve.ui.CiteFromIdInspectorTool.js
A modules/ve.ui.CitoidAction.js
4 files changed, 88 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Citoid 
refs/changes/99/203499/1

diff --git a/Citoid.php b/Citoid.php
index 3defac4..384f928 100644
--- a/Citoid.php
+++ b/Citoid.php
@@ -38,7 +38,8 @@
                'modules/ve.ui.CiteFromIdInspectorTool.js',
                'modules/ve.ui.CiteFromIdGroupWidget.js',
                'modules/ve.ui.CiteFromIdReferenceWidget.js',
-               'modules/ve.ui.CiteFromIdInspector.js'
+               'modules/ve.ui.CiteFromIdInspector.js',
+               'modules/ve.ui.CitoidAction.js'
        ),
        'styles' => array(
                'modules/ve.ui.CiteFromIdInspector.css'
diff --git a/modules/ve.ui.CiteFromIdInspector.js 
b/modules/ve.ui.CiteFromIdInspector.js
index 601c8d9..9ed1018 100644
--- a/modules/ve.ui.CiteFromIdInspector.js
+++ b/modules/ve.ui.CiteFromIdInspector.js
@@ -20,6 +20,7 @@
        this.templateTypeMap = null;
        this.lookupPromise = null;
        this.service = null;
+       this.inDialog = '';
 
        this.$element
                .addClass( 've-ui-citeFromIdInspector' );
@@ -263,7 +264,7 @@
  * Respond to preview select widget choose event
  */
 ve.ui.CiteFromIdInspector.prototype.onPreviewSelectWidgetChoose = function ( 
item ) {
-       var fragment,
+       var fragment = this.fragment,
                surfaceModel = this.getFragment().getSurface(),
                doc = surfaceModel.getDocument(),
                internalList = doc.getInternalList(),
@@ -274,23 +275,27 @@
                this.getFragment().getSurface().applyStaging();
 
                // Gets back contents of <ref> tag
-               item = this.referenceModel.findInternalItem( surfaceModel );
-               fragment = this.getFragment().clone(
-                       new ve.dm.LinearSelection( doc, item.getChildren()[ 0 
].getRange() )
-               );
+               if ( this.inDialog !== 'reference' ) {
+                       item = this.referenceModel.findInternalItem( 
surfaceModel );
+                       fragment = this.getFragment().clone(
+                               new ve.dm.LinearSelection( doc, 
item.getChildren()[ 0 ].getRange() )
+                       );
+               }
 
                this.results[ index ].transclusionModel.insertTransclusionNode( 
fragment );
-               // HACK: Scorch the earth - this is only needed because without 
it,
-               // the reference list won't re-render properly, and can be 
removed
-               // once someone fixes that
-               this.referenceModel.setDocument(
-                       doc.cloneFromRange(
-                               internalList.getItemNode( 
this.referenceModel.getListIndex() ).getRange()
-                       )
-               );
-               this.referenceModel.updateInternalItem( surfaceModel );
-               this.doneStaging = true;
 
+               if ( this.inDialog !== 'reference' ) {
+                       // HACK: Scorch the earth - this is only needed because 
without it,
+                       // the reference list won't re-render properly, and can 
be removed
+                       // once someone fixes that
+                       this.referenceModel.setDocument(
+                               doc.cloneFromRange(
+                                       internalList.getItemNode( 
this.referenceModel.getListIndex() ).getRange()
+                               )
+                       );
+                       this.referenceModel.updateInternalItem( surfaceModel );
+                       this.doneStaging = true;
+               }
                // Close the inspector
                this.close();
        }
@@ -322,14 +327,14 @@
 ve.ui.CiteFromIdInspector.prototype.getSetupProcess = function ( data ) {
        return ve.ui.CiteFromIdInspector.super.prototype.getSetupProcess.call( 
this, data )
                .next( function () {
+
                        // Reset
                        this.lookupPromise = null;
                        this.doneStaging = false;
                        this.results = [];
                        this.lookupButton.setDisabled( true );
+                       this.inDialog = data.inDialog || '';
 
-                       // Stage an empty reference
-                       this.getFragment().getSurface().pushStaging();
 
                        // Collapse returns a new fragment, so update 
this.fragment
                        this.fragment = this.getFragment().collapseToEnd();
@@ -337,9 +342,14 @@
                        // Create model
                        this.referenceModel = new ve.dm.MWReferenceModel();
 
-                       // Insert an empty reference
-                       this.referenceModel.insertInternalItem( 
this.getFragment().getSurface() );
-                       this.referenceModel.insertReferenceNode( 
this.getFragment() );
+                       if ( this.inDialog !== 'reference' ) {
+                               // Stage an empty reference
+                               this.getFragment().getSurface().pushStaging();
+
+                               // Insert an empty reference
+                               this.referenceModel.insertInternalItem( 
this.getFragment().getSurface() );
+                               this.referenceModel.insertReferenceNode( 
this.getFragment() );
+                       }
 
                        this.switchPanels( 'lookup' );
                }, this );
@@ -362,7 +372,7 @@
 ve.ui.CiteFromIdInspector.prototype.getTeardownProcess = function ( data ) {
        return 
ve.ui.CiteFromIdInspector.super.prototype.getTeardownProcess.call( this, data )
                .first( function () {
-                       if ( !this.doneStaging ) {
+                       if ( !this.doneStaging && this.inDialog !== 'reference' 
) {
                                this.fragment.getSurface().popStaging();
                        }
 
diff --git a/modules/ve.ui.CiteFromIdInspectorTool.js 
b/modules/ve.ui.CiteFromIdInspectorTool.js
index 8014450..49310a8 100644
--- a/modules/ve.ui.CiteFromIdInspectorTool.js
+++ b/modules/ve.ui.CiteFromIdInspectorTool.js
@@ -81,8 +81,7 @@
 
        ve.ui.commandRegistry.register(
                new ve.ui.Command(
-                       'citefromid', 'window', 'open',
-                       { args: [ 'citefromid' ], supportedSelections: [ 
'linear' ] }
+                       'citefromid', 'citoid', 'open', { args: [ 'citefromid' 
], supportedSelections: [ 'linear' ] }
                )
        );
 
diff --git a/modules/ve.ui.CitoidAction.js b/modules/ve.ui.CitoidAction.js
new file mode 100644
index 0000000..8d36a4b
--- /dev/null
+++ b/modules/ve.ui.CitoidAction.js
@@ -0,0 +1,54 @@
+/*!
+ * VisualEditor UserInterface CitoidAction class.
+ *
+ * @copyright 2011-2015 VisualEditor Team and others; see 
http://ve.mit-license.org
+ */
+
+/**
+ * Link action.
+ *
+ * Opens either MWLinkAnnotationInspector or MWLinkNodeInspector depending on 
what is selected.
+ *
+ * @class
+ * @extends ve.ui.Action
+ * @constructor
+ * @param {ve.ui.Surface} surface Surface to act on
+ */
+ve.ui.CitoidAction = function VeUiCitoidAction( surface ) {
+       // Parent constructor
+       ve.ui.Action.call( this, surface );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.CitoidAction, ve.ui.Action );
+
+/* Static Properties */
+
+ve.ui.CitoidAction.static.name = 'citoid';
+
+/**
+ * @inheritdoc
+ */
+ve.ui.CitoidAction.static.methods = [ 'open' ];
+
+/* Methods */
+
+/**
+ * When opening citoid inspector, send the inspector a property of the surface
+ * dialog name.
+ *
+ * @method
+ * @return {boolean} Action was executed
+ */
+ve.ui.CitoidAction.prototype.open = function () {
+debugger;
+       this.surface.execute( 'window', 'open', 'citefromid', {
+               inDialog: this.surface.getInDialog()
+       } );
+       return true;
+};
+
+/* Registration */
+
+ve.ui.actionFactory.register( ve.ui.CitoidAction );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I510ad0425c682c19897c39896770bb5216fab042
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Citoid
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to