mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-09-24 18:59:30 +00:00
Merge "Prompt user to confirm closing modified TemplateData edit dialog"
This commit is contained in:
commit
4f081392f2
|
@ -107,6 +107,7 @@
|
|||
"templatedata-modal-button-importParams",
|
||||
"templatedata-modal-button-restoreparam",
|
||||
"templatedata-modal-button-saveparam",
|
||||
"templatedata-modal-confirmcancel",
|
||||
"templatedata-modal-current-language",
|
||||
"templatedata-modal-errormsg",
|
||||
"templatedata-modal-errormsg-import-noparams",
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
"templatedata-modal-button-importParams": "Import parameters",
|
||||
"templatedata-modal-button-restoreparam": "Restore parameter",
|
||||
"templatedata-modal-button-saveparam": "Save",
|
||||
"templatedata-modal-confirmcancel": "Are you sure you want to cancel? Any changes will be lost.",
|
||||
"templatedata-modal-current-language": "Current language: $1",
|
||||
"templatedata-modal-errormsg": "Errors found. Please make sure there are no empty or duplicate parameter names, and that the parameter name does not include \"$1\", \"$2\" or \"$3\".",
|
||||
"templatedata-modal-errormsg-import-noparams": "No new parameters found during import.",
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
"templatedata-modal-button-importParams": "Label of the import button",
|
||||
"templatedata-modal-button-restoreparam": "Label for the button to restore a previously deleted parameter in the edit dialog.",
|
||||
"templatedata-modal-button-saveparam": "Label for the button to save parameter details in the templatedata edit dialog.\n{{Identical|Save}}",
|
||||
"templatedata-modal-confirmcancel": "Prompt shown to the user when they attempt to cancel the templatedata edit dialog after making changes.",
|
||||
"templatedata-modal-current-language": "Label displaying the current language in the edit dialog. Parameters:\n* $1 - currently showing language\n{{Identical|Current language}}",
|
||||
"templatedata-modal-errormsg": "Error message that appears in the TemplateData generator GUI in case there are empty, duplicate or invalid parameter names.\n\nInvalid characters are supplied as parameters to avoid parsing errors in translation strings.\n\nParameters:\n* $1 - pipe (<code>|</code>)\n* $2 - equal sign (<code>=</code>)\n* $3 - double curly brackets (<code><nowiki>}}</nowiki></code>)",
|
||||
"templatedata-modal-errormsg-import-noparams": "Error message that appears in the TemplateData generator GUI in case no template parameters were found during the import attempt.",
|
||||
|
|
|
@ -54,6 +54,10 @@ OO.mixinClass( mw.TemplateData.Model, OO.EventEmitter );
|
|||
* @param {...Mixed} value Property value
|
||||
*/
|
||||
|
||||
/**
|
||||
* @event change
|
||||
*/
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
/**
|
||||
|
@ -385,6 +389,8 @@ mw.TemplateData.Model.prototype.getExistingLanguageCodes = function () {
|
|||
* @param {string} key Parameter key
|
||||
* @param {Object} [paramData] Parameter data
|
||||
* @return {boolean} Parameter was added successfully
|
||||
* @fires add-param
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
|
||||
var prop, name, lang, propToSet,
|
||||
|
@ -465,6 +471,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
|
|||
|
||||
// Trigger the add parameter event
|
||||
this.emit( 'add-param', key, this.params[ key ] );
|
||||
this.emit( 'change' );
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -491,6 +498,7 @@ mw.TemplateData.Model.prototype.getAllParamNames = function () {
|
|||
* @param {Object} [language] Description language, if supplied. If not given,
|
||||
* will default to the wiki language.
|
||||
* @fires change-description
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, language ) {
|
||||
language = language || this.getDefaultLanguage();
|
||||
|
@ -503,6 +511,7 @@ mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, langua
|
|||
this.description[ language ] = desc;
|
||||
this.emit( 'change-description', desc, language );
|
||||
}
|
||||
this.emit( 'change' );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -549,6 +558,7 @@ mw.TemplateData.Model.prototype.getDefaultLanguage = function () {
|
|||
*
|
||||
* @param {string[]} orderArray Parameter key array in order
|
||||
* @fires change-paramOrder
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray ) {
|
||||
orderArray = orderArray || [];
|
||||
|
@ -556,6 +566,7 @@ mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray )
|
|||
// Copy the array
|
||||
this.paramOrder = orderArray.slice();
|
||||
this.emit( 'change-paramOrder', orderArray );
|
||||
this.emit( 'change' );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -563,12 +574,14 @@ mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray )
|
|||
*
|
||||
* @param {string} [format='inline'] Preferred format
|
||||
* @fires change-format
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) {
|
||||
format = format || 'inline';
|
||||
if ( this.format !== format ) {
|
||||
this.format = format;
|
||||
this.emit( 'change-format', format );
|
||||
this.emit( 'change' );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -577,14 +590,22 @@ mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) {
|
|||
*
|
||||
* @param {string} key New key the add into the paramOrder
|
||||
* @fires add-paramOrder
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.addKeyTemplateParamOrder = function ( key ) {
|
||||
if ( $.inArray( key, this.paramOrder ) === -1 ) {
|
||||
this.paramOrder.push( key );
|
||||
this.emit( 'add-paramOrder', key );
|
||||
this.emit( 'change' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: document
|
||||
*
|
||||
* @fires change-paramOrder
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex ) {
|
||||
var keyIndex = this.paramOrder.indexOf( key );
|
||||
// Move the parameter
|
||||
|
@ -598,18 +619,22 @@ mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex
|
|||
|
||||
// Emit event
|
||||
this.emit( 'change-paramOrder', this.paramOrder );
|
||||
this.emit( 'change' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a key to the end of the paramOrder
|
||||
*
|
||||
* @param {string} key New key the add into the paramOrder
|
||||
* @fires change-paramOrder
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.removeKeyTemplateParamOrder = function ( key ) {
|
||||
var keyPos = $.inArray( key, this.paramOrder );
|
||||
if ( keyPos > -1 ) {
|
||||
this.paramOrder.splice( keyPos, 1 );
|
||||
this.emit( 'change-paramOrder', this.paramOrder );
|
||||
this.emit( 'change' );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -640,6 +665,7 @@ mw.TemplateData.Model.prototype.getTemplateFormat = function () {
|
|||
* @param {string} [language] Value language
|
||||
* @return {boolean} Operation was successful
|
||||
* @fires change-property
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, value, language ) {
|
||||
var propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage(),
|
||||
|
@ -668,6 +694,7 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
|
|||
if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ][ language ], value ) ) {
|
||||
this.params[ paramKey ][ prop ][ language ] = value;
|
||||
this.emit( 'change-property', paramKey, prop, value, language );
|
||||
this.emit( 'change' );
|
||||
status = true;
|
||||
}
|
||||
} else {
|
||||
|
@ -675,6 +702,7 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
|
|||
if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ], value ) ) {
|
||||
this.params[ paramKey ][ prop ] = value;
|
||||
this.emit( 'change-property', paramKey, prop, value, language );
|
||||
this.emit( 'change' );
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
|
@ -694,12 +722,14 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
|
|||
*
|
||||
* @param {string} paramKey Parameter key
|
||||
* @fires delete-param
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.deleteParam = function ( paramKey ) {
|
||||
this.params[ paramKey ].deleted = true;
|
||||
// Remove from paramOrder
|
||||
this.removeKeyTemplateParamOrder( paramKey );
|
||||
this.emit( 'delete-param', paramKey );
|
||||
this.emit( 'change' );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -707,6 +737,7 @@ mw.TemplateData.Model.prototype.deleteParam = function ( paramKey ) {
|
|||
*
|
||||
* @param {string} paramKey Parameter key
|
||||
* @fires add-param
|
||||
* @fires change
|
||||
*/
|
||||
mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) {
|
||||
if ( this.params[ paramKey ] ) {
|
||||
|
@ -714,6 +745,7 @@ mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) {
|
|||
// Add back to paramOrder
|
||||
this.addKeyTemplateParamOrder( paramKey );
|
||||
this.emit( 'add-param', paramKey, this.params[ paramKey ] );
|
||||
this.emit( 'change' );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ mw.TemplateData.Dialog = function mwTemplateDataDialog( config ) {
|
|||
mw.TemplateData.Dialog.super.call( this, config );
|
||||
|
||||
this.model = null;
|
||||
this.modified = false;
|
||||
this.language = null;
|
||||
this.availableLanguages = [];
|
||||
this.selectedParamKey = '';
|
||||
|
@ -307,6 +308,13 @@ mw.TemplateData.Dialog.prototype.onModelAddKeyParamOrder = function ( key ) {
|
|||
this.paramOrderWidget.addItems( [ dragItem ] );
|
||||
};
|
||||
|
||||
/**
|
||||
* Respond to a change in the model
|
||||
*/
|
||||
mw.TemplateData.Dialog.prototype.onModelChange = function () {
|
||||
this.modified = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Respond to param order widget reorder event
|
||||
*
|
||||
|
@ -810,6 +818,7 @@ mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) {
|
|||
|
||||
// The dialog must be supplied with a reference to a model
|
||||
this.model = data.model;
|
||||
this.modified = false;
|
||||
|
||||
// Hide the panels and display a spinner
|
||||
this.$spinner.show();
|
||||
|
@ -824,7 +833,8 @@ mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) {
|
|||
this.model.connect( this, {
|
||||
'change-description': 'onModelChangeDescription',
|
||||
'change-paramOrder': 'onModelChangeParamOrder',
|
||||
'add-paramOrder': 'onModelAddKeyParamOrder'
|
||||
'add-paramOrder': 'onModelAddKeyParamOrder',
|
||||
change: 'onModelChange'
|
||||
} );
|
||||
|
||||
// Setup the dialog
|
||||
|
@ -982,6 +992,19 @@ mw.TemplateData.Dialog.prototype.getActionProcess = function ( action ) {
|
|||
this.close( { action: action } );
|
||||
}, this );
|
||||
}
|
||||
if ( !action && this.modified ) {
|
||||
return new OO.ui.Process( function () {
|
||||
var dialog = this;
|
||||
return OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) )
|
||||
.then( function ( result ) {
|
||||
if ( result ) {
|
||||
dialog.close();
|
||||
} else {
|
||||
return $.Deferred().resolve().promise();
|
||||
}
|
||||
} );
|
||||
}, this );
|
||||
}
|
||||
// Fallback to parent handler
|
||||
return mw.TemplateData.Dialog.super.prototype.getActionProcess.call( this, action );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue