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

Change subject: Template dialog: Disable 'Apply changes' until a change is made
......................................................................


Template dialog: Disable 'Apply changes' until a change is made

Bug: T76926
Bug: T76927
Change-Id: I5a664f865c11690a19b754fc9877baf37e34edad
---
M modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
M modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
2 files changed, 48 insertions(+), 9 deletions(-)

Approvals:
  Trevor Parscal: Looks good to me, approved
  Esanders: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js 
b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
index dd60447..8e39c63 100644
--- a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
+++ b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
@@ -135,7 +135,7 @@
         * @fires change
         */
        ve.dm.MWTransclusionModel.prototype.process = function ( queue ) {
-               var i, len, item, title, index, remove, existing;
+               var i, len, item, title, index, remove, existing, resolveQueue 
= [];
 
                for ( i = 0, len = queue.length; i < len; i++ ) {
                        remove = 0;
@@ -181,10 +181,17 @@
 
                        // Resolve promises
                        if ( item.deferred ) {
-                               item.deferred.resolve();
+                               resolveQueue.push( item.deferred );
                        }
                }
                this.emit( 'change' );
+
+               // We need to go back and resolve the deferreds after emitting 
change.
+               // Otherwise we get silly situations like a single change event 
being
+               // guaranteed after the transclusion loaded promise gets 
resolved.
+               for ( i = 0; i < resolveQueue.length; i++ ) {
+                       resolveQueue[i].resolve();
+               }
        };
 
        /** */
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
index 8d8e354..05b3dbc 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
@@ -24,6 +24,7 @@
        // Properties
        this.transclusionModel = null;
        this.loaded = false;
+       this.altered = false;
        this.preventReselection = false;
 
        this.confirmOverlay = new ve.ui.Overlay( { classes: 
['ve-ui-overlay-global'] } );
@@ -83,6 +84,16 @@
        this.loaded = true;
        this.$element.addClass( 've-ui-mwTemplateDialog-ready' );
        this.popPending();
+};
+
+/**
+ * Called when the transclusion model changes. E.g. parts changes, parameter 
values changes.
+ */
+ve.ui.MWTemplateDialog.prototype.onTransclusionModelChange = function () {
+       if ( this.loaded ) {
+               this.altered = true;
+               this.setApplicableStatus();
+       }
 };
 
 /**
@@ -155,6 +166,10 @@
                this.setPageByName( reselect.getName() );
        }
 
+       if ( this.loaded && ( added || removed ) ) {
+               this.altered = true;
+       }
+
        this.setApplicableStatus();
 
        this.updateTitle();
@@ -174,8 +189,13 @@
                page = new ve.ui.MWParameterPlaceholderPage( param, 
param.getId(), { $: this.$ } );
        }
        this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( 
param ) );
-       if ( this.loaded && !this.preventReselection ) {
-               this.setPageByName( param.getId() );
+       if ( this.loaded ) {
+               if ( !this.preventReselection ) {
+                       this.setPageByName( param.getId() );
+               }
+
+               this.altered = true;
+               this.setApplicableStatus();
        } else {
                this.onAddParameterBeforeLoad( page );
        }
@@ -214,8 +234,13 @@
                reselect = this.bookletLayout.getClosestPage( page );
 
        this.bookletLayout.removePages( [ page ] );
-       if ( this.loaded && !this.preventReselection ) {
-               this.setPageByName( reselect.getName() );
+       if ( this.loaded ) {
+               if ( !this.preventReselection ) {
+                       this.setPageByName( reselect.getName() );
+               }
+
+               this.altered = true;
+               this.setApplicableStatus();
        }
 };
 
@@ -229,11 +254,14 @@
        var parts = this.transclusionModel && this.transclusionModel.getParts();
 
        if ( this.loading.state() !== 'resolved' ) {
+               // Loading is not resolved
                this.actions.setAbilities( { apply: false, insert: false } );
        } else if ( parts.length && !( parts[0] instanceof 
ve.dm.MWTemplatePlaceholderModel ) ) {
-               this.actions.setAbilities( { apply: true, insert: true } );
+               // Loading is resolved, and we have parts, and first one is not 
placeholder
+               this.actions.setAbilities( { apply: this.altered, insert: true 
} );
        } else {
-               this.actions.setAbilities( { apply: parts.length === 0, insert: 
false } );
+               // Loading is resolved. We have either: 1) no parts, or 2) the 
a placeholder as the first part
+               this.actions.setAbilities( { apply: parts.length === 0 && 
this.altered, insert: false } );
        }
 };
 
@@ -432,10 +460,14 @@
 
                        // Properties
                        this.loaded = false;
+                       this.altered = false;
                        this.transclusionModel = new 
ve.dm.MWTransclusionModel();
 
                        // Events
-                       this.transclusionModel.connect( this, { replace: 
'onReplacePart' } );
+                       this.transclusionModel.connect( this, {
+                               replace: 'onReplacePart',
+                               change: 'onTransclusionModelChange'
+                       } );
 
                        // Initialization
                        if ( !this.selectedNode ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5a664f865c11690a19b754fc9877baf37e34edad
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to