jenkins-bot has submitted this change and it was merged.

Change subject: Make the cancel and apply button applicable for all modules
......................................................................


Make the cancel and apply button applicable for all modules

If a user does changes in module A, does not save or cancel,
goes to module B, does some changes, moves to other modules,
and finally presses Apply, all changes should get saved.

Similarly, if a user cancels, all changes should get cancelled.

This required moving the cancel and apply button outside of modules
and managed by the language settings framework.

Modules get mw.uls.settings.apply or mw.uls.settings.cancel triggers
to do whatever they want to do on apply or save.

Includes some refactoring related to this.

Bug: 53256
Change-Id: I7d773d33a980a78604b36e39bf96a5686870124e
---
M resources/css/ext.uls.languagesettings.css
M resources/js/ext.uls.displaysettings.js
M resources/js/ext.uls.inputsettings.js
M resources/js/ext.uls.languagesettings.js
M tests/browser/features/step_definitions/panel_steps.rb
M tests/browser/features/step_definitions/uls_cog_sidebar_user_steps.rb
M tests/browser/features/support/modules/interlanguage_module.rb
M tests/browser/features/support/pages/panel_page.rb
M tests/browser/features/uls_triggers.feature
9 files changed, 51 insertions(+), 80 deletions(-)

Approvals:
  Amire80: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/css/ext.uls.languagesettings.css 
b/resources/css/ext.uls.languagesettings.css
index 7c5e61f..b7a1b94 100644
--- a/resources/css/ext.uls.languagesettings.css
+++ b/resources/css/ext.uls.languagesettings.css
@@ -92,7 +92,7 @@
        background-color: #F5F5F5;
 }
 
-#languagesettings-settings-panel .language-settings-buttons {
+.language-settings-buttons {
        border-top: 1px solid #F0F0F0;
        margin-top: 25px;
        padding: 15px;
diff --git a/resources/js/ext.uls.displaysettings.js 
b/resources/js/ext.uls.displaysettings.js
index 3b7e658..cfcbe45 100644
--- a/resources/js/ext.uls.displaysettings.js
+++ b/resources/js/ext.uls.displaysettings.js
@@ -78,19 +78,9 @@
 
                + '</div>' // End font selectors
 
-               + '</div>' // End font settings section
+               + '</div>'; // End font settings section
 
-               // Separator
-               + '<div class="row"></div>'
 
-               // Apply and Cancel buttons
-               + '<div class="row language-settings-buttons">'
-               + '<div class="eleven columns">'
-               + '<button class="button uls-display-settings-cancel" 
data-i18n="ext-uls-language-settings-cancel"></button>'
-               + '<button class="button active blue" 
id="uls-displaysettings-apply" data-i18n="ext-uls-language-settings-apply" 
disabled></button>'
-               + '</div>'
-               + '</div>'
-               + '</div>';
 
        function DisplaySettings( $parent ) {
                this.name = $.i18n( 'ext-uls-display-settings-title-short' );
@@ -452,8 +442,7 @@
                 * i18n this settings panel
                 */
                i18n: function () {
-                       this.$template.i18n();
-
+                       this.$parent.i18n();
                        this.$template.find( '#ui-font-selector-label strong' )
                                .text( $.i18n( 'ext-uls-webfonts-select-for', 
$.uls.data.getAutonym( this.uiLanguage ) ) );
                        this.$template.find( '#content-font-selector-label 
strong' )
@@ -485,11 +474,11 @@
                 */
                markDirty: function () {
                        this.dirty = true;
-                       this.$template.find( '#uls-displaysettings-apply' 
).removeAttr( 'disabled' );
+                       this.$parent.$window.find( 'button.uls-settings-apply' 
).removeAttr( 'disabled' );
                },
 
                disableApplyButton: function () {
-                       this.$template.find( '#uls-displaysettings-apply' 
).prop( 'disabled', true );
+                       this.$parent.$window.find( 'button.uls-settings-apply' 
).prop( 'disabled', true );
                },
 
                /**
@@ -502,15 +491,6 @@
                                $tabButtons = displaySettings.$template.find( 
'.uls-display-settings-tab-switcher button' );
 
                        // TODO all these repeated selectors can be placed in 
object constructor.
-
-                       displaySettings.$template.find( 
'#uls-displaysettings-apply' ).on( 'click', function () {
-                               displaySettings.apply();
-                       } );
-
-                       displaySettings.$template.find( 
'button.uls-display-settings-cancel' ).on( 'click', function () {
-                               displaySettings.cancel();
-                               displaySettings.close();
-                       } );
 
                        $uiFontSelector.on( 'change', function () {
                                displaySettings.markDirty();
@@ -551,7 +531,6 @@
 
                        } );
 
-                       mw.hook( 'mw.uls.settings.cancel' ).add( $.proxy( 
this.cancel, this ) );
                },
 
                /**
@@ -624,6 +603,7 @@
                 */
                cancel: function () {
                        if ( !this.dirty ) {
+                               this.close();
                                return;
                        }
                        // Reload preferences
@@ -637,6 +617,7 @@
                        // Restore content and UI language
                        this.uiLanguage = this.getUILanguage();
                        this.contentLanguage = this.getContentLanguage();
+                       this.close();
                }
        };
 
diff --git a/resources/js/ext.uls.inputsettings.js 
b/resources/js/ext.uls.inputsettings.js
index 81bafbc..c5f8808 100644
--- a/resources/js/ext.uls.inputsettings.js
+++ b/resources/js/ext.uls.inputsettings.js
@@ -53,18 +53,6 @@
                + '<div class="six columns button uls-input-settings-toggle">'
                + '<button class="active green button 
uls-input-toggle-button"></button>'
                + '</div>'
-               + '</div>'
-
-               // Separator
-               + '<div class="row"></div>'
-
-               // Apply and Cancel buttons
-               + '<div class="row language-settings-buttons">'
-               + '<div class="eleven columns">'
-               + '<button class="button uls-input-settings-cancel" 
data-i18n="ext-uls-language-settings-cancel"></button>'
-               + '<button class="active blue button uls-input-settings-apply" 
data-i18n="ext-uls-language-settings-apply" disabled></button>'
-               + '</div>'
-               + '</div>'
                + '</div>';
 
        function InputSettings( $parent ) {
@@ -76,6 +64,8 @@
                this.$imes = null;
                this.$parent = $parent;
                this.savedRegistry = $.extend( true, {}, 
$.ime.preferences.registry );
+               // ime system is lazy loaded, make sure it is initialized
+               mw.ime.init();
        }
 
        InputSettings.prototype = {
@@ -92,8 +82,6 @@
                        this.$imes = $( 'body' ).data( 'ime' );
                        this.$parent.$settingsPanel.append( this.$template );
                        $enabledOnly = this.$template.find( '.enabled-only' );
-                       // ime system is lazy loaded, make sure it is 
initialized
-                       mw.ime.init();
                        if ( $.ime.preferences.isEnabled() ) {
                                $enabledOnly.removeClass( 'hide' );
                        } else {
@@ -103,8 +91,7 @@
 
                        this.prepareLanguages();
                        this.prepareToggleButton();
-                       this.$template.i18n();
-                       this.disableApplyButton();
+                       this.$parent.i18n();
                        $( 'body' ).data( 'webfonts' ).refresh();
                        this.listen();
                },
@@ -115,11 +102,11 @@
                 */
                markDirty: function () {
                        this.dirty = true;
-                       this.$template.find( 'button.uls-input-settings-apply' 
).prop( 'disabled', false );
+                       this.$parent.$window.find( 'button.uls-settings-apply' 
).prop( 'disabled', false );
                },
 
                disableApplyButton: function () {
-                       this.$template.find( 'button.uls-input-settings-apply' 
).prop( 'disabled', true );
+                       this.$parent.$window.find( 'button.uls-settings-apply' 
).prop( 'disabled', true );
                },
 
                prepareInputmethods: function ( language ) {
@@ -446,16 +433,6 @@
 
                        $imeListContainer = this.$template.find( 
'.uls-input-settings-inputmethods-list' );
 
-                       // Apply and close buttons
-                       inputSettings.$template.find( 
'button.uls-input-settings-apply' ).on( 'click', function () {
-                               inputSettings.apply();
-                       } );
-
-                       inputSettings.$template.find( 
'button.uls-input-settings-cancel' ).on( 'click', function () {
-                               inputSettings.cancel();
-                               inputSettings.close();
-                       } );
-
                        $imeListContainer.on( 'change', 
'input:radio[name=ime]:checked', function () {
                                inputSettings.markDirty();
                                $.ime.preferences.setIM( $( this ).val() );
@@ -472,7 +449,6 @@
                                        }
                                } );
 
-                       mw.hook( 'mw.uls.settings.cancel' ).add( $.proxy( 
this.cancel, this ) );
                },
 
                /**
@@ -564,6 +540,7 @@
                 */
                cancel: function () {
                        if ( !this.dirty ) {
+                               this.close();
                                return;
                        }
                        // Reload preferences
@@ -576,6 +553,7 @@
                        } else {
                                mw.ime.disable();
                        }
+                       this.close();
                }
        };
 
diff --git a/resources/js/ext.uls.languagesettings.js 
b/resources/js/ext.uls.languagesettings.js
index 02bfafb..6e40815 100644
--- a/resources/js/ext.uls.languagesettings.js
+++ b/resources/js/ext.uls.languagesettings.js
@@ -20,7 +20,7 @@
 ( function ( $, mw ) {
        'use strict';
 
-       var closeRow, settingsMenu, settingsPanel, windowTemplate, panelsRow;
+       var closeRow, settingsMenu, settingsPanel, windowTemplate, panelsRow, 
buttonsRow;
 
        closeRow = '<div class="row">' +
                '<div class="uls-language-settings-close-block eight columns 
offset-by-four"><span id="languagesettings-close" 
class="icon-close"></span></div>' +
@@ -32,9 +32,19 @@
                '</div>';
        settingsPanel = '<div id="languagesettings-settings-panel" class="eight 
columns">' +
                '</div>';
+       buttonsRow = '<div class="row"></div>' +
+               // Apply and Cancel buttons
+               '<div class="row language-settings-buttons">' +
+               '<div class="eleven columns">' +
+               '<button class="button uls-settings-cancel" 
data-i18n="ext-uls-language-settings-cancel"></button>' +
+               '<button class="button active blue uls-settings-apply" 
data-i18n="ext-uls-language-settings-apply" disabled></button>' +
+               '</div>' +
+               '</div>' +
+               '</div>';
        panelsRow = '<div class="row" id="languagesettings-panels">' +
                settingsMenu +
                settingsPanel +
+               buttonsRow +
                '</div>';
        windowTemplate = '<div style="display: block;" 
id="language-settings-dialog" class="grid uls-menu uls-wide">' +
                closeRow +
@@ -66,9 +76,11 @@
                // Register all event listeners to the ULS language settings 
here.
                listen: function () {
                        this.$element.on( 'click', $.proxy( this.click, this ) 
);
-                       this.$window.find( '#languagesettings-close' )
-                               .on( 'click', $.proxy( this.close, this ) );
 
+                       this.$window.find( '#languagesettings-close, 
button.uls-settings-cancel' )
+                               .on( 'click', $.proxy( mw.hook( 
'mw.uls.settings.cancel' ).fire, this ) );
+                       this.$window.find( 'button.uls-settings-apply' )
+                               .on( 'click', $.proxy( mw.hook( 
'mw.uls.settings.apply' ).fire, this ) );
                        // Hide the window when clicked outside
                        $( 'html' ).click( $.proxy( this.hide, this ) );
 
@@ -95,17 +107,18 @@
                                        }
 
                                        // Call render function on the current 
setting module.
-                                       languageSettings.renderModule( 
moduleName, defaultModule === moduleName );
+                                       languageSettings.initModule( 
moduleName, defaultModule === moduleName );
                                }
                        } );
                },
 
                /**
+                * Initialize the module.
                 * Render the link and settings area for a language setting 
module.
-                * @param moduleName String Name of the setting module
-                * @param active boolean Make this module active and show by 
default
+                * @param {string} moduleName Name of the setting module
+                * @param {boolean} active boolean Make this module active and 
show by default
                 */
-               renderModule: function ( moduleName, active ) {
+               initModule: function ( moduleName, active ) {
                        var $settingsTitle, $settingsText, $settingsLink,
                                languageSettings = this,
                                module = new 
$.fn.languagesettings.modules[moduleName]( languageSettings ),
@@ -132,7 +145,7 @@
                                var $this = $( this );
 
                                $this.data( 'module' ).render();
-                               // re-position the window and scroll in to view 
if required.
+                               // Re-position the window and scroll in to view 
if required.
                                languageSettings.position();
                                $settingsMenuItems.find( '.menu-section' 
).removeClass( 'active' );
                                $this.addClass( 'active' );
@@ -143,6 +156,10 @@
                                $settingsLink.addClass( 'active' );
                        }
                        this.modules[moduleName] = module;
+
+                       // Register cancel and apply hooks
+                       mw.hook( 'mw.uls.settings.cancel' ).add( $.proxy( 
module.cancel, module ) );
+                       mw.hook( 'mw.uls.settings.apply' ).add( $.proxy( 
module.apply, module ) );
                },
 
                position: function () {
@@ -160,6 +177,10 @@
                        this.$window.scrollIntoView();
                },
 
+               i18n: function () {
+                       this.$window.i18n();
+               },
+
                show: function () {
                        if ( !this.initialized ) {
                                this.render();
@@ -167,7 +188,7 @@
                        }
                        // close model windows close, if they hide on page click
                        $( 'html' ).click();
-                       this.$window.i18n();
+                       this.i18n();
                        this.shown = true;
                        this.$window.show();
 
@@ -217,7 +238,6 @@
                                this.options.onClose();
                        }
 
-                       mw.hook( 'mw.uls.settings.cancel' ).fire();
                },
 
                click: function ( e ) {
diff --git a/tests/browser/features/step_definitions/panel_steps.rb 
b/tests/browser/features/step_definitions/panel_steps.rb
index 3caf222..6737682 100644
--- a/tests/browser/features/step_definitions/panel_steps.rb
+++ b/tests/browser/features/step_definitions/panel_steps.rb
@@ -68,10 +68,10 @@
 end
 
 When(/^I apply the changes$/) do
-       on(ULSPage).panel_button_display_apply_element.click
-       wait = Selenium::WebDriver::Wait.new(:timeout => 3)
-       panel = @browser.driver.find_element(:id => 'language-settings-dialog')
-  wait.until { !panel.displayed? }
+       on(ULSPage).panel_button_apply_element.click
+       # Leave a little time for the settings to be saved. The settings window 
closes
+       # immediately, so it is not enough to wait for it to disappear.
+       sleep 2
 end
 
 Then(/^the (.*) font must be changed to the "(.*?)" font$/) do |type, font|
diff --git 
a/tests/browser/features/step_definitions/uls_cog_sidebar_user_steps.rb 
b/tests/browser/features/step_definitions/uls_cog_sidebar_user_steps.rb
index 5b6d360..77d525d 100644
--- a/tests/browser/features/step_definitions/uls_cog_sidebar_user_steps.rb
+++ b/tests/browser/features/step_definitions/uls_cog_sidebar_user_steps.rb
@@ -27,12 +27,8 @@
   step 'I see the logged in language settings panel'
 end
 
-When(/^I click Apply Settings$/) do
-  on(InterlanguagePage).apply_settings_element.click
-end
-
 When(/^I click Cancel$/) do
-  on(InterlanguagePage).cancel_element.click
+  on(ULSPage).panel_button_cancel_element.click
 end
 
 When(/^I click on the link to select Malayalam$/) do
diff --git a/tests/browser/features/support/modules/interlanguage_module.rb 
b/tests/browser/features/support/modules/interlanguage_module.rb
index cd9dc4e..275f03c 100644
--- a/tests/browser/features/support/modules/interlanguage_module.rb
+++ b/tests/browser/features/support/modules/interlanguage_module.rb
@@ -4,10 +4,8 @@
   include PageObject
 
   a(:add_links, id: 'wbc-linkToItem-link')
-  span(:apply_settings, class: 'uls-settings-trigger')
   a(:back_to_display, text: 'Back to display settings')
   a(:back_to_input, text: 'Back to input settings')
-  button(:cancel, class: 'button uls-display-settings-cancel')
   span(:cog, class: 'uls-settings-trigger')
   button(:ellipsis_button, class: 'uls-more-languages button')
   a(:english_link, text: 'English')
diff --git a/tests/browser/features/support/pages/panel_page.rb 
b/tests/browser/features/support/pages/panel_page.rb
index fb159a4..d937b32 100644
--- a/tests/browser/features/support/pages/panel_page.rb
+++ b/tests/browser/features/support/pages/panel_page.rb
@@ -10,7 +10,8 @@
        button(:panel_language, id: 'uls-display-settings-language-tab')
 
        span(:panel_button_close, id: 'languagesettings-close')
-       button(:panel_button_display_apply, id: 'uls-displaysettings-apply')
+       button(:panel_button_apply, class: 'uls-settings-apply')
+       button(:panel_button_cancel, class: 'uls-settings-cancel')
 
        button(:panel_disable_input_methods, class: 'uls-input-toggle-button')
        button(:panel_enable_input_methods, class: 'uls-input-toggle-button')
diff --git a/tests/browser/features/uls_triggers.feature 
b/tests/browser/features/uls_triggers.feature
index 9dbb241..319c803 100644
--- a/tests/browser/features/uls_triggers.feature
+++ b/tests/browser/features/uls_triggers.feature
@@ -35,6 +35,3 @@
     | user status | close method           |
     | logged in   | I click X              |
     | logged out  | I click Cancel         |
-    # It is weird that this works, since the button is disabled until changes
-    # have been made
-    | logged out  | I click Apply Settings |

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7d773d33a980a78604b36e39bf96a5686870124e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Pginer <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to