mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-09-25 03:08:59 +00:00
Merge "ve.ui.MWReferencesListDialog: Disable 'Apply' button until changes are made"
This commit is contained in:
commit
fd956ab507
|
@ -95,13 +95,46 @@ ve.ui.MWReferencesListDialog.prototype.initialize = function () {
|
|||
this.$body.append( this.panels.$element );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle change event.
|
||||
*/
|
||||
ve.ui.MWReferencesListDialog.prototype.onChange = function () {
|
||||
this.updateActions();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the 'apply' action according to whether there are changes
|
||||
*/
|
||||
ve.ui.MWReferencesListDialog.prototype.updateActions = function () {
|
||||
this.actions.setAbilities( { apply: this.isModified() } );
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
ve.ui.MWReferencesListDialog.prototype.isModified = function () {
|
||||
var refGroup, listGroup, oldListGroup, isResponsive, oldResponsive;
|
||||
if ( !this.selectedNode ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
refGroup = this.groupInput.getValue();
|
||||
listGroup = 'mwReference/' + refGroup;
|
||||
isResponsive = this.responsiveCheckbox.isSelected();
|
||||
|
||||
oldListGroup = this.selectedNode.getAttribute( 'listGroup' );
|
||||
oldResponsive = this.selectedNode.getAttribute( 'isResponsive' );
|
||||
|
||||
return listGroup !== oldListGroup || isResponsive !== oldResponsive;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferencesListDialog.prototype.getActionProcess = function ( action ) {
|
||||
if ( action === 'apply' ) {
|
||||
return new OO.ui.Process( function () {
|
||||
var refGroup, listGroup, oldListGroup, isResponsive, oldResponsive, mwData, attrChanges, doc,
|
||||
var refGroup, listGroup, isResponsive, mwData, attrChanges, doc,
|
||||
surfaceModel = this.getFragment().getSurface();
|
||||
|
||||
// Save changes
|
||||
|
@ -112,10 +145,8 @@ ve.ui.MWReferencesListDialog.prototype.getActionProcess = function ( action ) {
|
|||
if ( this.selectedNode ) {
|
||||
// Edit existing model
|
||||
doc = surfaceModel.getDocument();
|
||||
oldListGroup = this.selectedNode.getAttribute( 'listGroup' );
|
||||
oldResponsive = this.selectedNode.getAttribute( 'isResponsive' );
|
||||
|
||||
if ( listGroup !== oldListGroup || isResponsive !== oldResponsive ) {
|
||||
if ( this.isModified() ) {
|
||||
// newFromAttributeChanges doesn't do the smart-replacing
|
||||
// for nested attributes, so make a copy of the mw
|
||||
// attribute so we can disable autoGenerated now we've
|
||||
|
@ -160,6 +191,22 @@ ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) {
|
|||
this.groupInput.populateMenu( this.getFragment().getDocument().getInternalList() );
|
||||
|
||||
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) );
|
||||
|
||||
this.groupInput.connect( this, { change: 'onChange' } );
|
||||
this.responsiveCheckbox.connect( this, { change: 'onChange' } );
|
||||
|
||||
this.updateActions();
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferencesListDialog.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWReferencesListDialog.super.prototype.getTeardownProcess.call( this, data )
|
||||
.next( function () {
|
||||
this.groupInput.disconnect( this );
|
||||
this.responsiveCheckbox.disconnect( this );
|
||||
}, this );
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue