jenkins-bot has submitted this change and it was merged.

Change subject: References dialog cleanup
......................................................................


References dialog cleanup

Objectives:

* Remove the whole toolbar subset thing, it's up to the creator of the
  subsurface to know what is and is now allowed, and the commands were
  still passing through unfiltered
* Correctly separate initialization from opening - fix issue where opening
  the reference dialog multiple times will keep adding more and more
  controls

Changes:

ve.init.Target.js
* Remove getToolbarSubset method

ve.ui.MWReferenceDialog.js
* Add toolbar tools and surface commands configs to reference dialog,
  including the things that are safe to use in references
* Move creation of field sets and reused controls to initialize method
  to prevent re-creation each time the dialog is opened
* Move static initialization stuff to the top near the other static stuff

Change-Id: I1c8577d17c506bac76e61b2b036655c59ef5a218
---
M modules/ve/init/ve.init.Target.js
M modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
2 files changed, 48 insertions(+), 54 deletions(-)

Approvals:
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/init/ve.init.Target.js 
b/modules/ve/init/ve.init.Target.js
index 6227ae5..166dab0 100644
--- a/modules/ve/init/ve.init.Target.js
+++ b/modules/ve/init/ve.init.Target.js
@@ -39,24 +39,3 @@
 ve.init.Target.static.surfaceCommands = [
        'bold', 'italic', 'link', 'undo', 'redo', 'indent', 'outdent'
 ];
-
-/* Static Methods */
-
-/**
- * Get a subset of toolbarTools excluding certain tools.
- *
- * @param {string[]} exclude List of tools to exclude
- * @returns {Object} Toolbar tools object
- */
-ve.init.Target.static.getToolbarSubset = function ( exclude ) {
-       var i, iLen, items, group, toolbarSubset = [];
-       for ( i = 0, iLen = this.toolbarTools.length; i < iLen; i++ ) {
-               items = ve.simpleArrayDifference( this.toolbarTools[i].items, 
exclude );
-               if ( items.length ) {
-                       group = ve.copyObject( this.toolbarTools[i] );
-                       group.items = items;
-                       toolbarSubset.push( group );
-               }
-       }
-       return toolbarSubset;
-};
diff --git a/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js 
b/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
index 56c8919..e09073e 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
@@ -35,6 +35,27 @@
 
 ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
 
+ve.ui.MWReferenceDialog.static.toolbarTools = [
+       { 'items': ['undo', 'redo'] },
+       { 'items': ['mwFormat'] },
+       { 'items': ['bold', 'italic', 'mwLink', 'clear', 'mwMediaInsert'] }
+];
+
+ve.ui.MWReferenceDialog.static.surfaceCommands = [
+       'bold', 'italic', 'mwLink', 'undo', 'redo'
+];
+
+/* Static Initialization */
+
+ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
+       've.ce.Node.css',
+       've.ce.Surface.css',
+       've.ui.Surface.css',
+       've.ui.Context.css',
+       've.ui.Tool.css',
+       've.ui.Toolbar.css'
+] );
+
 /* Methods */
 
 /**
@@ -46,8 +67,27 @@
        // Call parent method
        ve.ui.Dialog.prototype.initialize.call( this );
 
+       // Properties
+       this.contentFieldset = new ve.ui.FieldsetLayout( {
+               // TODO: use message string
+               '$$': this.frame.$$, 'label': 'Content', 'icon': 'parameter'
+       } );
+       this.nameFieldset = new ve.ui.FieldsetLayout( {
+               // TODO: use message string
+               '$$': this.frame.$$, 'label': 'Name', 'icon': 'parameter'
+       } );
+       this.nameInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$ } );
+       this.nameLabel = new ve.ui.InputLabelWidget( {
+               '$$': this.frame.$$,
+               'input': this.nameInput,
+               // TODO: use message string
+               'label': 'Reuse this reference by this name'
+       } );
+
        // Initialization
        this.$body.addClass( 've-ui-mwReferenceDialog-body' );
+       this.$body.append( this.contentFieldset.$, this.nameFieldset.$ );
+       this.nameFieldset.$.append( this.nameLabel.$, this.nameInput.$ );
 };
 
 /**
@@ -56,32 +96,20 @@
  * @method
  */
 ve.ui.MWReferenceDialog.prototype.onOpen = function () {
-       var focusedNode, doc, data,
-       // Remove mwReference tool as you can't have nested references
-               toolbarSubset = 
ve.init.mw.ViewPageTarget.static.getToolbarSubset( [
-                       // Can't have nested references
-                       'mwReference',
-                       // Lists not properly supported by PHP parser
-                       'number', 'bullet', 'outdent', 'indent'
-               ] );
+       var focusedNode, data,
+               doc = this.surface.getModel().getDocument();
 
        // Parent method
        ve.ui.Dialog.prototype.onOpen.call( this );
 
-       // Get data from selection
+       // Get reference content
        focusedNode = this.surface.getView().getFocusedNode();
-       doc = this.surface.getModel().getDocument();
        if ( focusedNode instanceof ve.ce.MWReferenceNode ) {
                this.internalItem = focusedNode.getModel().getInternalItem();
                data = doc.getData( this.internalItem.getRange(), true );
        } else {
                data = [
-                       {
-                               'type': 'paragraph',
-                               'internal': {
-                                       'generated': 'wrapper'
-                               }
-                       },
+                       { 'type': 'paragraph', 'internal': { 'generated': 
'wrapper' } },
                        { 'type': '/paragraph' }
                ];
        }
@@ -94,9 +122,9 @@
 
        // Initialization
        this.referenceToolbar.$.addClass( 've-ui-mwReferenceDialog-toolbar' );
-       this.$body.append( this.referenceToolbar.$, this.referenceSurface.$ );
-       this.referenceToolbar.addTools( toolbarSubset );
-       this.referenceSurface.addCommands( 
ve.init.mw.ViewPageTarget.static.surfaceCommands );
+       this.contentFieldset.$.append( this.referenceToolbar.$, 
this.referenceSurface.$ );
+       this.referenceToolbar.addTools( this.constructor.static.toolbarTools );
+       this.referenceSurface.addCommands( 
this.constructor.static.surfaceCommands );
        this.referenceSurface.initialize();
        this.referenceSurface.view.documentView.documentNode.$.focus();
 };
@@ -138,9 +166,7 @@
                                {
                                        'type': 'mwReference',
                                        'attributes': {
-                                               'mw': {
-                                                       'name': 'ref'
-                                               },
+                                               'mw': { 'name': 'ref' },
                                                'listIndex': newItem.index,
                                                'listGroup': 'mwReference/' + 
groupName,
                                                'listKey': key,
@@ -157,17 +183,6 @@
        this.referenceSurface.destroy();
        this.referenceToolbar.destroy();
 };
-
-/* Initialization */
-
-ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
-       've.ce.Node.css',
-       've.ce.Surface.css',
-       've.ui.Surface.css',
-       've.ui.Context.css',
-       've.ui.Tool.css',
-       've.ui.Toolbar.css'
-] );
 
 /* Registration */
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1c8577d17c506bac76e61b2b036655c59ef5a218
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to