Merge "Prompt user to confirm closing modified TemplateData edit dialog"

This commit is contained in:
jenkins-bot 2016-01-12 23:48:31 +00:00 committed by Gerrit Code Review
commit 4f081392f2
5 changed files with 59 additions and 1 deletions

View file

@ -107,6 +107,7 @@
"templatedata-modal-button-importParams", "templatedata-modal-button-importParams",
"templatedata-modal-button-restoreparam", "templatedata-modal-button-restoreparam",
"templatedata-modal-button-saveparam", "templatedata-modal-button-saveparam",
"templatedata-modal-confirmcancel",
"templatedata-modal-current-language", "templatedata-modal-current-language",
"templatedata-modal-errormsg", "templatedata-modal-errormsg",
"templatedata-modal-errormsg-import-noparams", "templatedata-modal-errormsg-import-noparams",

View file

@ -58,6 +58,7 @@
"templatedata-modal-button-importParams": "Import parameters", "templatedata-modal-button-importParams": "Import parameters",
"templatedata-modal-button-restoreparam": "Restore parameter", "templatedata-modal-button-restoreparam": "Restore parameter",
"templatedata-modal-button-saveparam": "Save", "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-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": "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.", "templatedata-modal-errormsg-import-noparams": "No new parameters found during import.",

View file

@ -68,6 +68,7 @@
"templatedata-modal-button-importParams": "Label of the import button", "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-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-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-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": "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.", "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.",

View file

@ -54,6 +54,10 @@ OO.mixinClass( mw.TemplateData.Model, OO.EventEmitter );
* @param {...Mixed} value Property value * @param {...Mixed} value Property value
*/ */
/**
* @event change
*/
/* Static Methods */ /* Static Methods */
/** /**
@ -385,6 +389,8 @@ mw.TemplateData.Model.prototype.getExistingLanguageCodes = function () {
* @param {string} key Parameter key * @param {string} key Parameter key
* @param {Object} [paramData] Parameter data * @param {Object} [paramData] Parameter data
* @return {boolean} Parameter was added successfully * @return {boolean} Parameter was added successfully
* @fires add-param
* @fires change
*/ */
mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) { mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
var prop, name, lang, propToSet, var prop, name, lang, propToSet,
@ -465,6 +471,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
// Trigger the add parameter event // Trigger the add parameter event
this.emit( 'add-param', key, this.params[ key ] ); this.emit( 'add-param', key, this.params[ key ] );
this.emit( 'change' );
return true; return true;
}; };
@ -491,6 +498,7 @@ mw.TemplateData.Model.prototype.getAllParamNames = function () {
* @param {Object} [language] Description language, if supplied. If not given, * @param {Object} [language] Description language, if supplied. If not given,
* will default to the wiki language. * will default to the wiki language.
* @fires change-description * @fires change-description
* @fires change
*/ */
mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, language ) { mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, language ) {
language = language || this.getDefaultLanguage(); language = language || this.getDefaultLanguage();
@ -503,6 +511,7 @@ mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, langua
this.description[ language ] = desc; this.description[ language ] = desc;
this.emit( 'change-description', desc, language ); 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 * @param {string[]} orderArray Parameter key array in order
* @fires change-paramOrder * @fires change-paramOrder
* @fires change
*/ */
mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray ) { mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray ) {
orderArray = orderArray || []; orderArray = orderArray || [];
@ -556,6 +566,7 @@ mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray )
// Copy the array // Copy the array
this.paramOrder = orderArray.slice(); this.paramOrder = orderArray.slice();
this.emit( 'change-paramOrder', orderArray ); 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 * @param {string} [format='inline'] Preferred format
* @fires change-format * @fires change-format
* @fires change
*/ */
mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) { mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) {
format = format || 'inline'; format = format || 'inline';
if ( this.format !== format ) { if ( this.format !== format ) {
this.format = format; this.format = format;
this.emit( 'change-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 * @param {string} key New key the add into the paramOrder
* @fires add-paramOrder * @fires add-paramOrder
* @fires change
*/ */
mw.TemplateData.Model.prototype.addKeyTemplateParamOrder = function ( key ) { mw.TemplateData.Model.prototype.addKeyTemplateParamOrder = function ( key ) {
if ( $.inArray( key, this.paramOrder ) === -1 ) { if ( $.inArray( key, this.paramOrder ) === -1 ) {
this.paramOrder.push( key ); this.paramOrder.push( key );
this.emit( 'add-paramOrder', key ); this.emit( 'add-paramOrder', key );
this.emit( 'change' );
} }
}; };
/**
* TODO: document
*
* @fires change-paramOrder
* @fires change
*/
mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex ) { mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex ) {
var keyIndex = this.paramOrder.indexOf( key ); var keyIndex = this.paramOrder.indexOf( key );
// Move the parameter // Move the parameter
@ -598,18 +619,22 @@ mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex
// Emit event // Emit event
this.emit( 'change-paramOrder', this.paramOrder ); this.emit( 'change-paramOrder', this.paramOrder );
this.emit( 'change' );
}; };
/** /**
* Add a key to the end of the paramOrder * Add a key to the end of the paramOrder
* *
* @param {string} key New key the add into the paramOrder * @param {string} key New key the add into the paramOrder
* @fires change-paramOrder
* @fires change
*/ */
mw.TemplateData.Model.prototype.removeKeyTemplateParamOrder = function ( key ) { mw.TemplateData.Model.prototype.removeKeyTemplateParamOrder = function ( key ) {
var keyPos = $.inArray( key, this.paramOrder ); var keyPos = $.inArray( key, this.paramOrder );
if ( keyPos > -1 ) { if ( keyPos > -1 ) {
this.paramOrder.splice( keyPos, 1 ); this.paramOrder.splice( keyPos, 1 );
this.emit( 'change-paramOrder', this.paramOrder ); this.emit( 'change-paramOrder', this.paramOrder );
this.emit( 'change' );
} }
}; };
@ -640,6 +665,7 @@ mw.TemplateData.Model.prototype.getTemplateFormat = function () {
* @param {string} [language] Value language * @param {string} [language] Value language
* @return {boolean} Operation was successful * @return {boolean} Operation was successful
* @fires change-property * @fires change-property
* @fires change
*/ */
mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, value, language ) { mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, value, language ) {
var propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage(), 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 ) ) { if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ][ language ], value ) ) {
this.params[ paramKey ][ prop ][ language ] = value; this.params[ paramKey ][ prop ][ language ] = value;
this.emit( 'change-property', paramKey, prop, value, language ); this.emit( 'change-property', paramKey, prop, value, language );
this.emit( 'change' );
status = true; status = true;
} }
} else { } else {
@ -675,6 +702,7 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ], value ) ) { if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ], value ) ) {
this.params[ paramKey ][ prop ] = value; this.params[ paramKey ][ prop ] = value;
this.emit( 'change-property', paramKey, prop, value, language ); this.emit( 'change-property', paramKey, prop, value, language );
this.emit( 'change' );
status = true; status = true;
} }
} }
@ -694,12 +722,14 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
* *
* @param {string} paramKey Parameter key * @param {string} paramKey Parameter key
* @fires delete-param * @fires delete-param
* @fires change
*/ */
mw.TemplateData.Model.prototype.deleteParam = function ( paramKey ) { mw.TemplateData.Model.prototype.deleteParam = function ( paramKey ) {
this.params[ paramKey ].deleted = true; this.params[ paramKey ].deleted = true;
// Remove from paramOrder // Remove from paramOrder
this.removeKeyTemplateParamOrder( paramKey ); this.removeKeyTemplateParamOrder( paramKey );
this.emit( 'delete-param', 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 * @param {string} paramKey Parameter key
* @fires add-param * @fires add-param
* @fires change
*/ */
mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) { mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) {
if ( this.params[ paramKey ] ) { if ( this.params[ paramKey ] ) {
@ -714,6 +745,7 @@ mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) {
// Add back to paramOrder // Add back to paramOrder
this.addKeyTemplateParamOrder( paramKey ); this.addKeyTemplateParamOrder( paramKey );
this.emit( 'add-param', paramKey, this.params[ paramKey ] ); this.emit( 'add-param', paramKey, this.params[ paramKey ] );
this.emit( 'change' );
} }
}; };

View file

@ -12,6 +12,7 @@ mw.TemplateData.Dialog = function mwTemplateDataDialog( config ) {
mw.TemplateData.Dialog.super.call( this, config ); mw.TemplateData.Dialog.super.call( this, config );
this.model = null; this.model = null;
this.modified = false;
this.language = null; this.language = null;
this.availableLanguages = []; this.availableLanguages = [];
this.selectedParamKey = ''; this.selectedParamKey = '';
@ -307,6 +308,13 @@ mw.TemplateData.Dialog.prototype.onModelAddKeyParamOrder = function ( key ) {
this.paramOrderWidget.addItems( [ dragItem ] ); 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 * 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 // The dialog must be supplied with a reference to a model
this.model = data.model; this.model = data.model;
this.modified = false;
// Hide the panels and display a spinner // Hide the panels and display a spinner
this.$spinner.show(); this.$spinner.show();
@ -824,7 +833,8 @@ mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) {
this.model.connect( this, { this.model.connect( this, {
'change-description': 'onModelChangeDescription', 'change-description': 'onModelChangeDescription',
'change-paramOrder': 'onModelChangeParamOrder', 'change-paramOrder': 'onModelChangeParamOrder',
'add-paramOrder': 'onModelAddKeyParamOrder' 'add-paramOrder': 'onModelAddKeyParamOrder',
change: 'onModelChange'
} ); } );
// Setup the dialog // Setup the dialog
@ -982,6 +992,19 @@ mw.TemplateData.Dialog.prototype.getActionProcess = function ( action ) {
this.close( { action: action } ); this.close( { action: action } );
}, this ); }, 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 // Fallback to parent handler
return mw.TemplateData.Dialog.super.prototype.getActionProcess.call( this, action ); return mw.TemplateData.Dialog.super.prototype.getActionProcess.call( this, action );
}; };