Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/176896
Change subject: Save the draft translations automatically ...................................................................... Save the draft translations automatically * Removed the "Save as draft" button. Only publish button exist now * Save the drafts in every progress calculation change. Looks like that trigger will work. * Autosave in every 5 minutes timeout too Bug: T76182 Change-Id: I9173128b80928040caea6f810be1e6094db1c815 --- M Resources.php M i18n/en.json M i18n/qqq.json M modules/draft/ext.cx.draft.js M modules/header/ext.cx.header.js M modules/header/styles/ext.cx.header.less 6 files changed, 53 insertions(+), 51 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/96/176896/1 diff --git a/Resources.php b/Resources.php index 368cc5e..95fcba9 100644 --- a/Resources.php +++ b/Resources.php @@ -100,7 +100,6 @@ 'cx-error-page-not-found', 'cx-header-new-translation', 'cx-publish-button', - 'cx-save-draft-button', 'cx-special-login-error', 'cx-translation-target-page-exists', 'login', @@ -420,6 +419,8 @@ ), 'messages' => array( 'cx-save-draft-saving', + 'cx-save-draft-save-success', + 'cx-save-draft-tooltip', ), ) + $resourcePaths; diff --git a/i18n/en.json b/i18n/en.json index 144b466..5f846cd 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -114,6 +114,7 @@ "apihelp-query+contenttranslation-param-translationid": "Translation id.", "apihelp-query+contenttranslation-example-1": "Get translations started by Santhosh.", "apihelp-query+contenttranslation-example-2": "Get translations draft by id.", - "cx-save-draft-button": "Save as draft", - "cx-save-draft-saving": "Saving..." + "cx-save-draft-save-success": "Saved $1 {{plural:$1|minute|minutes}} ago", + "cx-save-draft-saving": "Saving...", + "cx-save-draft-tooltip": "Translation drafts are saved automatically" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 2fcfe39..580aa5c 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -118,6 +118,6 @@ "apihelp-query+contenttranslation-param-translationid": "{{doc-apihelp-param|query+contenttranslation}}", "apihelp-query+contenttranslation-example-1": "Don't translate \"Santhosh\". It is a username and must remain exactly as in the example.\n{{doc-apihelp-example|query+contenttranslation}}", "apihelp-query+contenttranslation-example-2": "{{doc-apihelp-example|query+contenttranslation}}", - "cx-save-draft-button": "Label of button to save the translation as draft.", - "cx-save-draft-saving": "Label of button to save the translation as draft while saving is in progress\n{{Identical|Saving}}" + "cx-save-draft-saving": "Label of button to save the translation as draft while saving is in progress\n{{Identical|Saving}}", + "cx-save-draft-tooltip": "Tooltip text shown for the save status indicator text in the header of [[Special:ContentTranslation]]" } diff --git a/modules/draft/ext.cx.draft.js b/modules/draft/ext.cx.draft.js index 2e4e945..ee734af 100644 --- a/modules/draft/ext.cx.draft.js +++ b/modules/draft/ext.cx.draft.js @@ -9,13 +9,13 @@ ( function ( $, mw ) { 'use strict'; + var timer; /** * @class * @param {number} draftId Draft id */ function ContentTranslationDraft( draftId ) { this.draftId = draftId; - this.$draftButton = $( '.cx-header__draft-button' ); this.listen(); } @@ -27,10 +27,7 @@ mw.hook( 'mw.cx.save' ).add( function () { self.save(); } ); - mw.hook( 'mw.cx.translation.published' ).add( function () { - self.$draftButton.prop( 'disabled', true ).show(); - } ); - // Publish when CTRL+S is pressed. + // Save when CTRL+S is pressed. $( document ).on( 'keydown', function ( e ) { if ( e.ctrlKey && e.which === 83 ) { e.preventDefault(); @@ -86,16 +83,12 @@ * Save the translation */ ContentTranslationDraft.prototype.save = function () { - var self = this, - draftContent, targetTitle, params, apiParams, + var draftContent, targetTitle, params, apiParams, api = new mw.Api(); targetTitle = $( '.cx-column--translation > h2' ).text(); draftContent = $( '.cx-column--translation .cx-column__content' ).clone(); - - this.$draftButton - .prop( 'disabled', true ) - .text( mw.msg( 'cx-save-draft-saving' ) ); + clearInterval( timer ); params = { from: mw.cx.sourceLanguage, to: mw.cx.targetLanguage, @@ -114,13 +107,11 @@ timeout: 100 * 1000 // in milliseconds } ).done( function () { mw.hook( 'mw.cx.translation.saved' ).fire(); + timer = setInterval( function () { + mw.hook( 'mw.cx.save' ).fire(); + }, 5 * 60 * 1000 ); } ).fail( function () { mw.hook( 'mw.cx.error' ).fire( mw.msg( 'cx-publish-page-error' ) ); - } ).always( function () { - self.$draftButton - .prop( 'disabled', false ) - .text( mw.msg( 'cx-save-draft-button' ) ) - .hide(); } ); }; diff --git a/modules/header/ext.cx.header.js b/modules/header/ext.cx.header.js index d22576f..0c37558 100644 --- a/modules/header/ext.cx.header.js +++ b/modules/header/ext.cx.header.js @@ -11,6 +11,7 @@ ( function ( $, mw ) { 'use strict'; + var timer; /** * Handlers the top part of the three column interface. * @@ -21,9 +22,8 @@ function ContentTranslationHeader( element, siteMapper ) { this.$container = $( element ); this.siteMapper = siteMapper; - + this.$saveStatus = null; this.$publishButton = null; - this.$draftButton = null; this.$infoBar = null; this.init(); @@ -39,14 +39,11 @@ * @param {object} weights */ ContentTranslationHeader.prototype.setPublishButtonState = function ( weights ) { - if ( mw.config.get( 'wgContentTranslationDatabase' ) !== null ) { - this.$draftButton.show().prop( 'disabled', weights.any === 0 ); - this.$publishButton.hide(); - } else { - this.$publishButton.show().prop( 'disabled', weights.any === 0 ); + this.$publishButton.show().prop( 'disabled', weights.any === 0 ); + if ( weights.any > 0 ) { + // Start saving the translaton + mw.hook( 'mw.cx.save' ).fire(); } - - }; /** @@ -140,10 +137,6 @@ this.$publishButton.on( 'click', function () { mw.hook( 'mw.cx.publish' ).fire(); } ); - this.$draftButton.on( 'click', function () { - mw.hook( 'mw.cx.save' ).fire(); - } ); - // Click handler for remove icon in info bar. this.$infoBar.on( 'click', '.remove', function () { $( this ).parent().hide(); @@ -154,8 +147,26 @@ mw.hook( 'mw.cx.success' ).add( $.proxy( this.showSuccess, this ) ); mw.hook( 'mw.cx.error.anonuser' ).add( $.proxy( this.showLoginMessage, this ) ); mw.hook( 'mw.cx.translation.ready' ).add( $.proxy( this.checkTargetTitle, this ) ); + mw.hook( 'mw.cx.save' ).add( $.proxy( this.updateSaveStatus, this, 'progress' ) ); + mw.hook( 'mw.cx.translation.saved' ).add( $.proxy( this.updateSaveStatus, this, 'success' ) ); }; + ContentTranslationHeader.prototype.updateSaveStatus = function ( status ) { + var self = this, + minutes = 0; + + this.$saveStatus.attr('title', mw.msg( 'cx-save-draft-tooltip' ) ); + if ( status === 'progress' ) { + this.$saveStatus.text( mw.msg( 'cx-save-draft-saving' ) ); + clearTimeout( timer ); + } else { + this.$saveStatus.text( mw.msg( 'cx-save-draft-save-success', 0 ) ); + timer = setInterval( function () { + minutes++; + self.$saveStatus.text( mw.msg( 'cx-save-draft-save-success', minutes ) ); + }, 60 * 1000 ); + } + }; /** * Render the header */ @@ -175,13 +186,15 @@ .append( $logo, $titleText ); $translationCenterLink = $( '<a>' ) - // TODO update the text when the dashboard is ready - .text( mw.msg( 'cx-header-new-translation' ) ) + .text( mw.msg( 'cx-header-new-translation' ) ) .attr( 'href', mw.util.getUrl( 'Special:ContentTranslation' ) ); $translationCenter = $( '<div>' ) .addClass( 'cx-header__translation-center' ) .append( $translationCenterLink ); + + this.$saveStatus = $( '<div>' ) + .addClass( 'cx-header__save-status' ); this.$publishButton = $( '<button>' ) .addClass( 'cx-header__publish-button mw-ui-button mw-ui-constructive' ) @@ -189,24 +202,13 @@ .text( mw.msg( 'cx-publish-button' ) ) .hide(); - if ( mw.config.get( 'wgContentTranslationDatabase' ) !== null ) { - this.$draftButton = $( '<button>' ) - .addClass( 'cx-header__draft-button mw-ui-button mw-ui-constructive' ) - .prop( 'disabled', true ) - .text( mw.msg( 'cx-save-draft-button' ) ) - .hide(); - this.$publishButton.prop( 'disabled', false ); - } else { - this.$draftButton = $(); - } - $publishArea = $( '<div>' ) .addClass( 'cx-header__publish' ) .append( this.$draftButton, this.$publishButton ); $headerBar = $( '<div>' ) .addClass( 'cx-header__bar' ) - .append( $translationCenter, $publishArea ); + .append( $translationCenter, this.$saveStatus, $publishArea ); this.$infoBar = $( '<div>' ) .addClass( 'cx-header__infobar' ) diff --git a/modules/header/styles/ext.cx.header.less b/modules/header/styles/ext.cx.header.less index 6e93f3b..0e692ae 100644 --- a/modules/header/styles/ext.cx.header.less +++ b/modules/header/styles/ext.cx.header.less @@ -44,7 +44,7 @@ .cx-header__translation-center { .mw-ui-item; - .mw-ui-two-thirds; + .mw-ui-one-third; a { color: #565656; @@ -57,6 +57,13 @@ margin: 0 8px 0 0; } } +} + +.cx-header__save-status { + .mw-ui-item; + .mw-ui-one-third; + color: #555555; + font-size: normal; } .cx-header__infobar { @@ -95,6 +102,7 @@ .cx-header__publish { .mw-ui-item; .mw-ui-one-third; + float: right; } .cx-header.sticky { @@ -114,8 +122,7 @@ padding-top: 5px; } - .cx-header__publish-button, - .cx-header__draft-button { + .cx-header__publish-button{ float: right; } -- To view, visit https://gerrit.wikimedia.org/r/176896 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9173128b80928040caea6f810be1e6094db1c815 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits