From db4d034fd7465153a66e13286774108b744d1857 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Tue, 2 Dec 2014 01:25:19 +0000 Subject: [PATCH] Disable Apply Changes in reference dialog until changes have been made Bug: T57976 Change-Id: Ib5229bdc480ec437436c5d8d351b06417d4ffd9b --- .../ui/dialogs/ve.ui.MWReferenceDialog.js | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js index 1b0432b06d..054cf47b12 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js @@ -137,13 +137,20 @@ ve.ui.MWReferenceDialog.static.getImportRules = function () { /* Methods */ +/** + * Determine whether the reference document we're editing has any content. + * @return {boolean} Document has content + */ +ve.ui.MWReferenceDialog.prototype.documentHasContent = function () { + // TODO: Check for other types of empty, e.g. only whitespace? + return this.referenceModel.getDocument().data.countNonInternalElements() > 2; +}; + /** * Handle reference surface change events */ ve.ui.MWReferenceDialog.prototype.onDocumentTransact = function () { - var data = this.referenceModel.getDocument().data, - // TODO: Check for other types of empty, e.g. only whitespace? - hasContent = data.countNonInternalElements() > 2; + var hasContent = this.documentHasContent(); this.actions.setAbilities( { apply: hasContent, @@ -152,6 +159,15 @@ ve.ui.MWReferenceDialog.prototype.onDocumentTransact = function () { } ); }; +/** + * Handle reference group input change events + */ +ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () { + this.actions.setAbilities( { + apply: this.documentHasContent() + } ); +}; + /** * Handle search select events. * @@ -277,6 +293,7 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () { $overlay: this.$overlay, emptyGroupName: ve.msg( 'visualeditor-dialog-reference-options-group-placeholder' ) } ); + this.referenceGroupInput.input.connect( this, { change: 'onReferenceGroupInputChange' } ); this.referenceGroupField = new OO.ui.FieldLayout( this.referenceGroupInput, { $: this.$, align: 'top', @@ -375,7 +392,8 @@ ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) { // If not, set disabled based on whether or not there are any existing ones. this.actions.setAbilities( { select: !( this.selectedNode instanceof ve.dm.MWReferenceNode ) && - !this.search.isIndexEmpty() + !this.search.isIndexEmpty(), + apply: false } ); this.referenceGroupInput.populateMenu( this.getFragment().getDocument().getInternalList() );