Santhosh has uploaded a new change for review.

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

Change subject: Show a confirmation dialoge when translator tries to delete 
translation
......................................................................

Show a confirmation dialoge when translator tries to delete translation

Bug: T85991
Change-Id: I34d589a7b418acdd3999519160d69681531c271c
---
M Resources.php
M i18n/en.json
M i18n/qqq.json
M modules/dashboard/ext.cx.translationlist.js
M modules/dashboard/styles/ext.cx.translationlist.less
5 files changed, 119 insertions(+), 9 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/89/189689/1

diff --git a/Resources.php b/Resources.php
index c5acf68..5a95cf4 100644
--- a/Resources.php
+++ b/Resources.php
@@ -584,6 +584,9 @@
                'cx-translation-status-draft',
                'cx-translation-status-deleted',
                'cx-translation-status-published',
+               'cx-draft-discard-confirmaton-message',
+               'cx-draft-cancel-button-label',
+               'cx-draft-discard-button-label',
        ),
 ) + $resourcePaths;
 
diff --git a/i18n/en.json b/i18n/en.json
index 21829c4..df91012 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -142,5 +142,8 @@
        "cx-stats-table-target-total": "Total (Target)",
        "cx-stats-published-translations-title": "Published translations",
        "cx-stats-draft-translations-title": "In progress translations",
-       "cx-stats-published-translators-title": "Number of translators"
+       "cx-stats-published-translators-title": "Number of translators",
+       "cx-draft-discard-confirmaton-message": "Are you sure you want to 
permanently delete this translation?",
+       "cx-draft-cancel-button-label": "Cancel",
+       "cx-draft-discard-button-label": "Delete translation"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 3534aca..14e1fc1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -147,5 +147,9 @@
        "cx-stats-table-target-total": "Header text to indicate total 
translations to target language",
        "cx-stats-published-translations-title": "Section title for published 
translation stats",
        "cx-stats-draft-translations-title": "Section title for translations in 
draft(in progress) state stats",
-       "cx-stats-published-translators-title": "Section title for stats about 
number of translators who published articles across languages"
+       "cx-stats-published-translators-title": "Section title for stats about 
number of translators who published articles across languages",
+       "cx-stats-published-translators-title": "Number of translators",
+       "cx-draft-discard-confirmaton-message": "Confirmation message when user 
attempt to delete a translation",
+       "cx-draft-cancel-button-label": "Canel button label",
+       "cx-draft-discard-button-label": "Label for delete button"
 }
diff --git a/modules/dashboard/ext.cx.translationlist.js 
b/modules/dashboard/ext.cx.translationlist.js
index 78cf3e3..0eaa5f7 100644
--- a/modules/dashboard/ext.cx.translationlist.js
+++ b/modules/dashboard/ext.cx.translationlist.js
@@ -28,7 +28,8 @@
                this.$sourceLanguageFilter = null;
                this.$targetLanguageFilter = null;
                this.$translationFilterContainer = null;
-
+               this.$confirmatonDialog = null;
+               this.$overlay = null;
                this.init();
                this.render();
                this.listen();
@@ -297,16 +298,77 @@
                this.$container.on( 'click', '.cx-discard-translation', 
function () {
                        var translation = $( this ).data( 'translation' );
 
-                       translationList.discardTranslation( $( this ).data( 
'translation' ) )
-                               .then( function ( response ) {
-                                       if ( response.cxdelete.result === 
'success' ) {
-                                               
translationList.markTranslationAsDeleted( translation );
-                                       }
-                               } );
+                       translationList.showDiscardConfirmation( translation 
).then( function ( answer ) {
+                               if ( !answer ) {
+                                       return;
+                               }
+                               translationList.discardTranslation( translation 
)
+                                       .then( function ( response ) {
+                                               if ( response.cxdelete.result 
=== 'success' ) {
+                                                       
translationList.markTranslationAsDeleted( translation );
+                                               }
+                                       } );
+                       } );
                } );
        };
 
        /**
+        * Show the confirmaton dialoge for discarding a translaton
+        * @param {Object} translation
+        * @return {jQuery.Promise}
+        */
+       CXTranslationList.prototype.showDiscardConfirmation = function () {
+               var deferred, $actions, $cancelButton, $discardButton, $message,
+                       translationList = this;
+
+               deferred = $.Deferred();
+
+               if ( !this.$overlay ) {
+                       this.$overlay = $( '<div>' )
+                               .addClass( 'cx-draft-discard-dialoge__overlay' 
);
+                       $( 'body' ).append( this.$overlay );
+               }
+
+               if ( !this.$confirmatonDialog ) {
+                       this.$confirmatonDialog = $( '<div>' )
+                               .addClass( 'cx-draft-discard-dialoge' );
+                       $cancelButton = $( '<button>' )
+                               .addClass( 'mw-ui-button mw-ui-quiet 
cx-draft-discard-dialoge__cancel' )
+                               .text( mw.msg( 'cx-draft-cancel-button-label' ) 
);
+                       $discardButton = $( '<button>' )
+                               .addClass( 'mw-ui-button mw-ui-destructive 
cx-draft-discard-dialoge__discard' )
+                               .text( mw.msg( 'cx-draft-discard-button-label' 
) );
+                       $actions = $( '<div>' )
+                               .addClass( 'cx-draft-discard-dialoge__actions' )
+                               .append( $discardButton, $cancelButton );
+                       $message = $( '<div>' )
+                               .addClass( 'cx-draft-discard-dialoge__message' )
+                               .text( mw.msg( 
'cx-draft-discard-confirmaton-message' ) );
+                       $( 'body' ).append( this.$confirmatonDialog.append( 
$message, $actions ) );
+               } else {
+                       $cancelButton = this.$confirmatonDialog.find( 
'.cx-draft-discard-dialoge__cancel' );
+                       $discardButton = this.$confirmatonDialog.find( 
'.cx-draft-discard-dialoge__discard' );
+               }
+
+               $cancelButton.on( 'click', function () {
+                       deferred.resolve( false );
+                       translationList.$confirmatonDialog.hide();
+                       translationList.$overlay.hide();
+               } );
+
+               $discardButton.on( 'click', function () {
+                       deferred.resolve( true );
+                       translationList.$confirmatonDialog.hide();
+                       translationList.$overlay.hide();
+               } );
+
+               this.$overlay.show();
+               this.$confirmatonDialog.show();
+
+               return deferred.promise();
+       };
+
+       /**
         * Mark the translation item in the translation list as deleted
         * @param {Object} translation
         */
diff --git a/modules/dashboard/styles/ext.cx.translationlist.less 
b/modules/dashboard/styles/ext.cx.translationlist.less
index 6dd6af6..4721786 100644
--- a/modules/dashboard/styles/ext.cx.translationlist.less
+++ b/modules/dashboard/styles/ext.cx.translationlist.less
@@ -167,3 +167,41 @@
                }
        }
 }
+
+.cx-draft-discard-dialoge {
+       .mw-ui-item;
+       color: #333;
+       position: fixed;
+       min-width: 500px;
+       max-width: 600px;
+       background: white;
+       border: 1px solid #ddd;
+       border-bottom-width: 3px;
+       border-radius: 3px;
+       padding: 0;
+       top: 30%;
+       left: 30%;
+       box-shadow: 0 5px 10px rgba(0,0,0,0.2);
+       &__message {
+               padding: 25px;
+               font-size: large;
+       }
+       &__actions {
+               .mw-ui-one-whole;
+               padding: 20px;
+               button {
+                       float: right;
+                       padding-right: 20px;
+               }
+       }
+}
+
+.cx-draft-discard-dialoge__overlay {
+       position: fixed;
+       top: 0;
+       left: 0;
+       height: 100%;
+       width: 100%;
+       background-color: #FFF;
+       opacity: 0.5;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34d589a7b418acdd3999519160d69681531c271c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to