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

Change subject: Keep label and disabled state of transclusion dialog apply 
button in sync
......................................................................


Keep label and disabled state of transclusion dialog apply button in sync

* Use "Insert template" when adding a single template
* Use "Insert transclusion" when adding a multi-part template
* Use "Apply changes" when working with an existing tranclusion
* Use "Loading..." and disable while waiting for template data
* Disable when the transclusion has only a template placeholder

Bug: 50998
Change-Id: Ib2fb3d8711ed6d3ef41cc0db55740c95394dd3f9
---
M VisualEditor.php
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js
4 files changed, 66 insertions(+), 17 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  Siebrand: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/VisualEditor.php b/VisualEditor.php
index 3735bd0..b249c9f 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -918,6 +918,9 @@
                        'visualeditor-dialog-transclusion-add-param',
                        'visualeditor-dialog-transclusion-add-template',
                        'visualeditor-dialog-transclusion-content',
+                       'visualeditor-dialog-transclusion-insert-template',
+                       'visualeditor-dialog-transclusion-insert-transclusion',
+                       'visualeditor-dialog-transclusion-loading',
                        'visualeditor-dialog-transclusion-multiple-mode',
                        'visualeditor-dialog-transclusion-options',
                        'visualeditor-dialog-transclusion-placeholder',
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index 7103467..8dc3963 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -115,6 +115,9 @@
     "visualeditor-dialog-transclusion-add-param": "Add parameter",
     "visualeditor-dialog-transclusion-add-template": "Add template",
     "visualeditor-dialog-transclusion-content": "Content",
+    "visualeditor-dialog-transclusion-insert-template": "Insert template",
+    "visualeditor-dialog-transclusion-insert-transclusion": "Insert 
transclusion",
+    "visualeditor-dialog-transclusion-loading": "Loading...",
     "visualeditor-dialog-transclusion-multiple-mode": "Show options",
     "visualeditor-dialog-transclusion-options": "Options",
     "visualeditor-dialog-transclusion-placeholder": "New template",
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index 2dd3649..677b6f9 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -120,6 +120,9 @@
     "visualeditor-dialog-transclusion-add-param": "Label for button that adds 
parameter a parameter to a template.\n{{Identical|Add parameter}}",
     "visualeditor-dialog-transclusion-add-template": "Label for button that 
adds parameter a template to a transclusion.\n{{Identical|Add template}}",
     "visualeditor-dialog-transclusion-content": "Label for editor of content 
between transclusion parts.\n{{Identical|Content}}",
+    "visualeditor-dialog-transclusion-insert-template": "Label for button in 
the transclusion dialog while in single mode that closes the dialog inserts a 
template",
+    "visualeditor-dialog-transclusion-insert-transclusion": "Label for button 
in the transclusion dialog while in multiple mode that closes the dialog 
inserts a transclusion",
+    "visualeditor-dialog-transclusion-loading": "Label for the apply button in 
the transclusion dialog while it is disabled and loading",
     "visualeditor-dialog-transclusion-multiple-mode": "Label for button that 
shows advanced options in transclusion dialog",
     "visualeditor-dialog-transclusion-options": "Label for section with 
options for templates, content or parameters.\n{{Identical|Options}}",
     "visualeditor-dialog-transclusion-placeholder": "Label for section with 
options for adding a new template to a multi part transclusion",
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js
index 31fd68c..5f82af1 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js
@@ -25,6 +25,7 @@
        this.loaded = false;
        this.preventReselection = false;
        this.mode = null;
+       this.inserting = false;
 };
 
 /* Inheritance */
@@ -150,7 +151,7 @@
  * @param {ve.dm.MWTransclusionPartModel} added Added part
  */
 ve.ui.MWTransclusionDialog.prototype.onReplacePart = function ( removed, added 
) {
-       var i, len, page, name, names, params, partPage, reselect,
+       var i, len, page, name, names, params, partPage, reselect, single,
                removePages = [];
 
        if ( removed ) {
@@ -216,7 +217,19 @@
        } else if ( reselect ) {
                this.setPageByName( reselect.getName() );
        }
-       this.modeButton.setDisabled( !this.isSingleTemplateTransclusion( 
this.transclusion ) );
+       // Update widgets related to a transclusion being a single template or 
not
+       single = this.isSingleTemplateTransclusion();
+       this.modeButton.setDisabled( !single );
+       this.applyButton
+               .setLabel( ve.msg(
+                       !this.inserting ? 'visualeditor-dialog-action-apply' : (
+                               single ?
+                                       
'visualeditor-dialog-transclusion-insert-template' :
+                                       
'visualeditor-dialog-transclusion-insert-transclusion'
+                       )
+               ) )
+               .setDisabled( !this.isInsertable() );
+       this.updateTitle();
 };
 
 /**
@@ -256,10 +269,10 @@
 /**
  * Checks if transclusion only contains a single template or template 
placeholder.
  *
- * @returns {boolean} Transclusion only contains a single template or template 
placeholder.
+ * @returns {boolean} Transclusion only contains a single template or template 
placeholder
  */
-ve.ui.MWTransclusionDialog.prototype.isSingleTemplateTransclusion = function ( 
transclusion ) {
-       var parts = transclusion && transclusion.getParts();
+ve.ui.MWTransclusionDialog.prototype.isSingleTemplateTransclusion = function 
() {
+       var parts = this.transclusion && this.transclusion.getParts();
 
        return parts && parts.length === 1 && (
                parts[0] instanceof ve.dm.MWTemplateModel ||
@@ -268,10 +281,25 @@
 };
 
 /**
+ * Checks if transclusion is in a valid state for inserting into the document
+ *
+ * If the transclusion is empty or only contains a placeholder it will not be 
insertable.
+ *
+ * @returns {boolean} Transclusion can be inserted
+ */
+ve.ui.MWTransclusionDialog.prototype.isInsertable = function () {
+       var parts = this.transclusion && this.transclusion.getParts();
+
+       return !this.loading &&
+               parts.length &&
+               ( parts.length > 1 || !( parts[0] instanceof 
ve.dm.MWTemplatePlaceholderModel ) );
+};
+
+/**
  * Get the label of a template or template placeholder.
  *
  * @param {ve.dm.MWTemplateModel|ve.dm.MWTemplatePlaceholderModel} part Part 
to check
- * @returns {string} Label of template or template placeholder.
+ * @returns {string} Label of template or template placeholder
  */
 ve.ui.MWTransclusionDialog.prototype.getTemplatePartLabel = function ( part ) {
        return part instanceof ve.dm.MWTemplateModel ?
@@ -310,7 +338,7 @@
                parts = this.transclusion.getParts();
                part = parts.length && parts[0];
                if ( mode === 'auto' ) {
-                       mode = this.isSingleTemplateTransclusion( 
this.transclusion ) ? 'single' : 'multiple';
+                       mode = this.isSingleTemplateTransclusion() ? 'single' : 
'multiple';
                }
        }
        if ( !modeCssClasses[mode] ) {
@@ -325,16 +353,25 @@
        }
        this.setSize( single ? 'medium' : 'large' );
        this.bookletLayout.toggleOutline( !single );
-       this.setTitle(
-               single && part ?
-                       this.getTemplatePartLabel( part ) :
-                       this.constructor.static.title
-       );
        this.modeButton.setLabel( ve.msg(
                single ?
                        'visualeditor-dialog-transclusion-multiple-mode' :
                        'visualeditor-dialog-transclusion-single-mode'
        ) );
+       this.updateTitle();
+};
+
+/**
+ * Update the dialog title.
+ */
+ve.ui.MWTransclusionDialog.prototype.updateTitle = function () {
+       var parts = this.transclusion && this.transclusion.getParts();
+
+       this.setTitle(
+               this.mode === 'single' && parts && parts.length && parts[0] ?
+                       this.getTemplatePartLabel( parts[0] ) :
+                       this.constructor.static.title
+       );
 };
 
 /**
@@ -370,7 +407,6 @@
        // Properties
        this.applyButton = new OO.ui.ButtonWidget( {
                '$': this.$,
-               'label': ve.msg( 'visualeditor-dialog-action-apply' ),
                'flags': ['primary']
        } );
        this.modeButton = new OO.ui.ButtonWidget( { '$': this.$ } );
@@ -434,17 +470,21 @@
        this.node = this.surface.getView().getFocusedNode();
        this.transclusion = new ve.dm.MWTransclusionModel();
        this.loaded = false;
+       this.inserting = !( this.node instanceof ve.ce.MWTransclusionNode );
 
        // Events
        this.transclusion.connect( this, { 'replace': 'onReplacePart' } );
 
        // Initialization
-       if ( this.node instanceof ve.ce.MWTransclusionNode ) {
-               promise = this.transclusion
-                       .load( ve.copy( this.node.getModel().getAttribute( 'mw' 
) ) );
-       } else {
+       this.applyButton
+               .setDisabled( true )
+               .setLabel( ve.msg( 'visualeditor-dialog-transclusion-loading' ) 
);
+       if ( this.inserting ) {
                promise = this.transclusion
                        .addPart( new ve.dm.MWTemplatePlaceholderModel( 
this.transclusion ) );
+       } else {
+               promise = this.transclusion
+                       .load( ve.copy( this.node.getModel().getAttribute( 'mw' 
) ) );
        }
        promise.always( ve.bind( function () {
                this.loaded = true;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2fb3d8711ed6d3ef41cc0db55740c95394dd3f9
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <tpars...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to