Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182980

Change subject: Allow the restoration of a deleted parameter in the edit dialog
......................................................................

Allow the restoration of a deleted parameter in the edit dialog

If a user adds a parameter that was previously deleted, allow the
user to restore that parameter data.

Change-Id: Ib739ee09229750f94314636d4290dbe6662b4c0f
---
M TemplateData.php
M i18n/en.json
M i18n/qqq.json
M modules/ext.templateDataGenerator.data.js
M modules/ext.templateDataGenerator.ui.tdDialog.js
5 files changed, 57 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData 
refs/changes/80/182980/1

diff --git a/TemplateData.php b/TemplateData.php
index 649f106..653d30c 100644
--- a/TemplateData.php
+++ b/TemplateData.php
@@ -113,6 +113,7 @@
                'templatedata-modal-button-changelang',
                'templatedata-modal-button-delparam',
                'templatedata-modal-button-importParams',
+               'templatedata-modal-button-restoreparam',
                'templatedata-modal-button-saveparam',
                'templatedata-modal-current-language',
                'templatedata-modal-errormsg',
diff --git a/i18n/en.json b/i18n/en.json
index 461ae6d..5716eea 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -46,6 +46,7 @@
        "templatedata-modal-button-changelang": "Change language",
        "templatedata-modal-button-delparam": "Remove parameter information",
        "templatedata-modal-button-importParams": "Import parameters",
+       "templatedata-modal-button-restoreparam": "Restore parameter",
        "templatedata-modal-button-saveparam": "Save",
        "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\".",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ac9deab..4535ca3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -53,6 +53,7 @@
        "templatedata-modal-button-changelang": "Label for the button to change 
language in the edit dialog.",
        "templatedata-modal-button-delparam": "Button to remove a parameter.",
        "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.",
        "templatedata-modal-current-language": "Label displaying the current 
language in the edit dialog. $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>)",
diff --git a/modules/ext.templateDataGenerator.data.js 
b/modules/ext.templateDataGenerator.data.js
index 349a5c7..6e741f2 100644
--- a/modules/ext.templateDataGenerator.data.js
+++ b/modules/ext.templateDataGenerator.data.js
@@ -739,12 +739,27 @@
         * Don't actually delete the parameter so we can make sure it is removed
         * from the final output.
         * @param {string} paramKey Parameter key
+        * @fires delete-param
         */
        TemplateDataModel.prototype.deleteParam = function ( paramKey ) {
                this.params[paramKey].deleted = true;
                // Remove from paramOrder
                this.removeKeyTemplateParamOrder( paramKey );
                this.emit( 'delete-param', paramKey );
+       };
+
+       /**
+        * Restore parameter by unmarking it as deleted.
+        * @param {string} paramKey Parameter key
+        * @fires add-param
+        */
+       TemplateDataModel.prototype.restoreParam = function ( paramKey ) {
+               if ( this.params[paramKey] ) {
+                       this.params[paramKey].deleted = false;
+                       // Add back to paramOrder
+                       this.addKeyTemplateParamOrder( paramKey );
+                       this.emit( 'add-param', paramKey, this.params[paramKey] 
);
+               }
        };
 
        /**
@@ -778,6 +793,14 @@
                return this.params;
        };
 
+       TemplateDataModel.prototype.isParamDeleted = function ( key ) {
+               return this.params[key].deleted === true;
+       };
+
+       TemplateDataModel.prototype.isParamExists = function ( key ) {
+               return $.inArray( key, Object.keys( this.params ) ) > -1;
+       };
+
        /**
         * Set the original templatedata object
         * @param {Object} templatedataObj TemplateData object
diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js 
b/modules/ext.templateDataGenerator.ui.tdDialog.js
index fb10611..aa28e1a 100644
--- a/modules/ext.templateDataGenerator.ui.tdDialog.js
+++ b/modules/ext.templateDataGenerator.ui.tdDialog.js
@@ -207,6 +207,7 @@
 
                // Events
                this.newLanguageSearchWidget.connect( this, { select: 
'newLanguageSearchWidgetSelect' } );
+               this.newParamInput.connect( this, { change: 
'onAddParamInputChange' } );
                this.addParamButton.connect( this, { click: 
'onAddParamButtonClick' } );
                this.descriptionInput.connect( this, { change: 
'onDescriptionInputChange' } );
                this.paramOrderWidget.connect( this, { reorder: 
'onParamOrderWidgetReorder' } );
@@ -222,6 +223,21 @@
         */
        TemplateDataDialog.prototype.onModelChangeDescription = function ( 
description ) {
                this.descriptionInput.setValue( description );
+       };
+
+       TemplateDataDialog.prototype.onAddParamInputChange = function ( value ) 
{
+               if ( this.model.isParamExists( value ) ) {
+                       if ( this.model.isParamDeleted( value ) ) {
+                               this.addParamButton.setDisabled( false );
+                               this.addParamButton.setLabel( mw.msg( 
'templatedata-modal-button-restoreparam' ) );
+                       } else {
+                               // Disable the add button
+                               this.addParamButton.setDisabled( true );
+                       }
+               } else {
+                       this.addParamButton.setLabel( mw.msg( 
'templatedata-modal-button-addparam' ) );
+                       this.addParamButton.setDisabled( false );
+               }
        };
 
        /**
@@ -343,18 +359,24 @@
                // Validate parameter
                if (
                        !newParamKey.match( allProps.name.restrict ) &&
-                       $.inArray( newParamKey, this.model.getAllParamNames() ) 
=== -1
+                       this.model.isParamExists( newParamKey )
                ) {
-                       // Add to model
-                       if ( this.model.addParam( newParamKey ) ) {
-                               // Add parameter to list
-                               this.addParamToSelectWidget( newParamKey );
-                               // Empty the parameter
-                               this.newParamInput.setValue( '' );
-                               // Go back to list
-                               this.switchPanels( 'listParams' );
+                       if ( this.model.isParamDeleted( newParamKey ) ) {
+                               // Restore
+                               this.model.restoreParam( newParamKey );
+                       } else {
+                               // Add to model
+                               if ( this.model.addParam( newParamKey ) ) {
+                                       // Add parameter to list
+                                       this.addParamToSelectWidget( 
newParamKey );
+                               }
                        }
                }
+               // Reset the input
+               this.newParamInput.setValue( '' );
+
+               // Go back to list
+               this.switchPanels( 'listParams' );
        };
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib739ee09229750f94314636d4290dbe6662b4c0f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to